From 1586c763677834ada6c5e725db6188805f76d9b9 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Tue, 18 Feb 2020 13:27:21 -0500 Subject: [PATCH] fix regression with xpack.remote_clusters.ui.enabled setting --- .../plugins/remote_clusters/public/index.ts | 4 +- .../plugins/remote_clusters/public/plugin.ts | 72 +++++++++++-------- .../plugins/remote_clusters/public/types.ts | 6 ++ .../plugins/remote_clusters/server/config.ts | 5 +- 4 files changed, 56 insertions(+), 31 deletions(-) diff --git a/x-pack/plugins/remote_clusters/public/index.ts b/x-pack/plugins/remote_clusters/public/index.ts index dbe22b71b48df..6ba021b157c3e 100644 --- a/x-pack/plugins/remote_clusters/public/index.ts +++ b/x-pack/plugins/remote_clusters/public/index.ts @@ -3,6 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { PluginInitializerContext } from 'kibana/public'; import { RemoteClustersUIPlugin } from './plugin'; -export const plugin = () => new RemoteClustersUIPlugin(); +export const plugin = (initializerContext: PluginInitializerContext) => + new RemoteClustersUIPlugin(initializerContext); diff --git a/x-pack/plugins/remote_clusters/public/plugin.ts b/x-pack/plugins/remote_clusters/public/plugin.ts index 5b84fa1fde369..0fc70cdb60f95 100644 --- a/x-pack/plugins/remote_clusters/public/plugin.ts +++ b/x-pack/plugins/remote_clusters/public/plugin.ts @@ -5,50 +5,64 @@ */ import { i18n } from '@kbn/i18n'; -import { CoreSetup, Plugin, CoreStart } from 'kibana/public'; +import { CoreSetup, Plugin, CoreStart, PluginInitializerContext } from 'kibana/public'; import { init as initBreadcrumbs } from './application/services/breadcrumb'; import { init as initDocumentation } from './application/services/documentation'; import { init as initHttp } from './application/services/http'; import { init as initUiMetric } from './application/services/ui_metric'; import { init as initNotification } from './application/services/notification'; import { init as initRedirect } from './application/services/redirect'; -import { Dependencies } from './types'; +import { Dependencies, ClientConfigType } from './types'; export class RemoteClustersUIPlugin implements Plugin { + constructor(private readonly initializerContext: PluginInitializerContext) {} + setup( { notifications: { toasts }, http, getStartServices }: CoreSetup, { management, usageCollection }: Dependencies ) { - const esSection = management.sections.getSection('elasticsearch'); - - esSection!.registerApp({ - id: 'remote_clusters', - title: i18n.translate('xpack.remoteClusters.appTitle', { - defaultMessage: 'Remote Clusters', - }), - mount: async ({ element, setBreadcrumbs }) => { - const [core] = await getStartServices(); - const { - i18n: { Context: i18nContext }, - docLinks, - fatalErrors, - } = core; - - // Initialize services - initBreadcrumbs(setBreadcrumbs); - initDocumentation(docLinks); - initUiMetric(usageCollection); - initNotification(toasts, fatalErrors); - initHttp(http); - - const { renderApp } = await import('./application'); - return renderApp(element, i18nContext); - }, - }); + const { + ui: { enabled: isRemoteClustersUiEnabled }, + } = this.initializerContext.config.get(); + + if (isRemoteClustersUiEnabled) { + const esSection = management.sections.getSection('elasticsearch'); + + esSection!.registerApp({ + id: 'remote_clusters', + title: i18n.translate('xpack.remoteClusters.appTitle', { + defaultMessage: 'Remote Clusters', + }), + mount: async ({ element, setBreadcrumbs }) => { + const [core] = await getStartServices(); + const { + i18n: { Context: i18nContext }, + docLinks, + fatalErrors, + } = core; + + // Initialize services + initBreadcrumbs(setBreadcrumbs); + initDocumentation(docLinks); + initUiMetric(usageCollection); + initNotification(toasts, fatalErrors); + initHttp(http); + + const { renderApp } = await import('./application'); + return renderApp(element, i18nContext); + }, + }); + } } start({ application }: CoreStart) { - initRedirect(application.navigateToApp); + const { + ui: { enabled: isRemoteClustersUiEnabled }, + } = this.initializerContext.config.get(); + + if (isRemoteClustersUiEnabled) { + initRedirect(application.navigateToApp); + } } stop() {} diff --git a/x-pack/plugins/remote_clusters/public/types.ts b/x-pack/plugins/remote_clusters/public/types.ts index 45ae90f91587a..cee65f40c44ee 100644 --- a/x-pack/plugins/remote_clusters/public/types.ts +++ b/x-pack/plugins/remote_clusters/public/types.ts @@ -14,6 +14,12 @@ export interface Dependencies { usageCollection: UsageCollectionSetup; } +export interface ClientConfigType { + ui: { + enabled: boolean; + }; +} + export { RegisterManagementAppArgs }; export { I18nStart }; diff --git a/x-pack/plugins/remote_clusters/server/config.ts b/x-pack/plugins/remote_clusters/server/config.ts index 9525fe1e2a0db..e329789cb6b60 100644 --- a/x-pack/plugins/remote_clusters/server/config.ts +++ b/x-pack/plugins/remote_clusters/server/config.ts @@ -9,6 +9,9 @@ import { PluginConfigDescriptor } from 'kibana/server'; export const configSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), + ui: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }), }); export type ConfigType = TypeOf; @@ -16,6 +19,6 @@ export type ConfigType = TypeOf; export const config: PluginConfigDescriptor = { schema: configSchema, exposeToBrowser: { - enabled: true, + ui: true, }, };