Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve consistency for display of management items #92694

Merged
merged 4 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions x-pack/plugins/beats_management/public/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ import { BeatsManagementConfigType } from '../common';
import { MANAGEMENT_SECTION } from '../common/constants';

async function startApp(libs: FrontendLibs, core: CoreSetup<StartDeps>) {
const [startServices] = await Promise.all([
core.getStartServices(),
libs.framework.waitUntilFrameworkReady(),
]);
const startServices = await core.getStartServices();

if (startServices[0].http.anonymousPaths.isAnonymous(window.location.pathname)) {
return;
}
// Can't run until the `start` lifecycle, so we wait for start services to resolve above before calling this.
await libs.framework.waitUntilFrameworkReady();
Comment on lines +21 to +27
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this isn't strictly related to the resolved issues, but I noticed that Beats was making requests which required authentication on the login page (and other unauthenticated pages). This change prevents Beats from completing its initialization if we are on one such page. Moving from an unauthenticated page to an authenticated page requires a full page reload, so there is no risk to the actual stack management application.


const capabilities = startServices[0].application.capabilities;
const hasBeatsCapability = capabilities.management.ingest?.[MANAGEMENT_SECTION] ?? false;
Expand Down
16 changes: 10 additions & 6 deletions x-pack/plugins/cross_cluster_replication/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,21 @@ export class CrossClusterReplicationPlugin implements Plugin {

// NOTE: We enable the plugin by default instead of disabling it by default because this
// creates a race condition that causes functional tests to fail on CI (see #66781).
licensing.license$
.pipe(first())
.toPromise()
.then((license) => {
Promise.all([licensing.license$.pipe(first()).toPromise(), getStartServices()]).then(
([license, startServices]) => {
const licenseStatus = license.check(PLUGIN.ID, PLUGIN.minimumLicenseType);
const isLicenseOk = licenseStatus.state === 'valid';
const config = this.initializerContext.config.get<ClientConfigType>();

const capabilities = startServices[0].application.capabilities;

// remoteClusters.isUiEnabled is driven by the xpack.remote_clusters.ui.enabled setting.
// The CCR UI depends upon the Remote Clusters UI (e.g. by cross-linking to it), so if
// the Remote Clusters UI is disabled we can't show the CCR UI.
const isCcrUiEnabled = config.ui.enabled && remoteClusters.isUiEnabled;
const isCcrUiEnabled =
capabilities.management.data?.[MANAGEMENT_ID] &&
config.ui.enabled &&
remoteClusters.isUiEnabled;

if (isLicenseOk && isCcrUiEnabled) {
if (indexManagement) {
Expand All @@ -106,7 +109,8 @@ export class CrossClusterReplicationPlugin implements Plugin {
} else {
ccrApp.disable();
}
});
}
);
}

public start() {}
Expand Down
16 changes: 12 additions & 4 deletions x-pack/plugins/watcher/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/

import { i18n } from '@kbn/i18n';
import { CoreSetup, Plugin, CoreStart } from 'kibana/public';
import { CoreSetup, Plugin, CoreStart, Capabilities } from 'kibana/public';
import { first, map, skip } from 'rxjs/operators';

import { Subject, combineLatest } from 'rxjs';
import { FeatureCatalogueCategory } from '../../../../src/plugins/home/public';

import { LicenseStatus } from '../common/types/license_status';
Expand All @@ -26,6 +27,8 @@ const licenseToLicenseStatus = (license: ILicense): LicenseStatus => {
};

export class WatcherUIPlugin implements Plugin<void, void, Dependencies, any> {
private capabilities$: Subject<Capabilities> = new Subject();

setup(
{ notifications, http, uiSettings, getStartServices }: CoreSetup,
{ licensing, management, data, home, charts }: Dependencies
Expand Down Expand Up @@ -99,21 +102,26 @@ export class WatcherUIPlugin implements Plugin<void, void, Dependencies, any> {

home.featureCatalogue.register(watcherHome);

licensing.license$.pipe(first(), map(licenseToLicenseStatus)).subscribe(({ valid }) => {
combineLatest([
licensing.license$.pipe(first(), map(licenseToLicenseStatus)),
this.capabilities$,
]).subscribe(([{ valid }, capabilities]) => {
// NOTE: We enable the plugin by default instead of disabling it by default because this
// creates a race condition that can cause the app nav item to not render in the side nav.
// The race condition still exists, but it will result in the item rendering when it shouldn't
// (e.g. on a license it's not available for), instead of *not* rendering when it *should*,
// which is a less frustrating UX.
if (valid) {
if (valid && capabilities.management.insightsAndAlerting?.watcher === true) {
watcherESApp.enable();
} else {
watcherESApp.disable();
}
});
}

start(core: CoreStart) {}
start(core: CoreStart) {
this.capabilities$.next(core.application.capabilities);
}

stop() {}
}