Skip to content

Commit

Permalink
Improve consistency for display of management items (#92694) (#93237)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Larry Gregory <larry.gregory@elastic.co>
  • Loading branch information
kibanamachine and legrego authored Mar 2, 2021
1 parent 88f661b commit 7b9b093
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
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();

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() {}
}

0 comments on commit 7b9b093

Please sign in to comment.