From b1fd4d5b3f835f6381159d43778bbe8d8824396c Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Wed, 25 Mar 2020 19:06:14 +0000 Subject: [PATCH] [ML] Disabling start trial option when license management ui is disabled (#60987) (#61309) * [ML] Disabling start trial option when license management ui is disabled * tiny refactor * changes based on review --- .../license_management/public/index.ts | 2 +- .../license_management/public/plugin.ts | 20 +++++++++++++++---- x-pack/plugins/ml/kibana.json | 3 ++- x-pack/plugins/ml/public/application/app.tsx | 1 + .../contexts/kibana/kibana_context.ts | 2 ++ .../datavisualizer_selector.tsx | 10 ++++++++-- x-pack/plugins/ml/public/plugin.ts | 3 +++ 7 files changed, 33 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/license_management/public/index.ts b/x-pack/plugins/license_management/public/index.ts index 3c76549ebdc161..99f715f9718f6b 100644 --- a/x-pack/plugins/license_management/public/index.ts +++ b/x-pack/plugins/license_management/public/index.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ import { PluginInitializerContext } from 'src/core/public'; - import { LicenseManagementUIPlugin } from './plugin'; import './application/index.scss'; +export { LicenseManagementUIPluginSetup, LicenseManagementUIPluginStart } from './plugin'; export const plugin = (ctx: PluginInitializerContext) => new LicenseManagementUIPlugin(ctx); diff --git a/x-pack/plugins/license_management/public/plugin.ts b/x-pack/plugins/license_management/public/plugin.ts index 00d353bc97e040..1d309f229cb8be 100644 --- a/x-pack/plugins/license_management/public/plugin.ts +++ b/x-pack/plugins/license_management/public/plugin.ts @@ -20,17 +20,25 @@ interface PluginsDependencies { telemetry?: TelemetryPluginSetup; } -export class LicenseManagementUIPlugin implements Plugin { +export interface LicenseManagementUIPluginSetup { + enabled: boolean; +} +export type LicenseManagementUIPluginStart = void; + +export class LicenseManagementUIPlugin + implements Plugin { private breadcrumbService = new BreadcrumbService(); constructor(private readonly initializerContext: PluginInitializerContext) {} - setup(coreSetup: CoreSetup, plugins: PluginsDependencies) { + setup(coreSetup: CoreSetup, plugins: PluginsDependencies): LicenseManagementUIPluginSetup { const config = this.initializerContext.config.get(); if (!config.ui.enabled) { // No need to go any further - return; + return { + enabled: false, + }; } const { getStartServices } = coreSetup; @@ -76,8 +84,12 @@ export class LicenseManagementUIPlugin implements Plugin { return renderApp(element, appDependencies); }, }); + + return { + enabled: true, + }; } - start() {} + start(): LicenseManagementUIPluginStart {} stop() {} } diff --git a/x-pack/plugins/ml/kibana.json b/x-pack/plugins/ml/kibana.json index b6db289f4be6d5..038f61b3a33b7b 100644 --- a/x-pack/plugins/ml/kibana.json +++ b/x-pack/plugins/ml/kibana.json @@ -18,7 +18,8 @@ "optionalPlugins": [ "security", "spaces", - "management" + "management", + "licenseManagement" ], "server": true, "ui": true diff --git a/x-pack/plugins/ml/public/application/app.tsx b/x-pack/plugins/ml/public/application/app.tsx index 8c3e0c066f4118..e9796fcbb0fe44 100644 --- a/x-pack/plugins/ml/public/application/app.tsx +++ b/x-pack/plugins/ml/public/application/app.tsx @@ -37,6 +37,7 @@ const App: FC = ({ coreStart, deps }) => { appName: 'ML', data: deps.data, security: deps.security, + licenseManagement: deps.licenseManagement, storage: localStorage, ...coreStart, }; diff --git a/x-pack/plugins/ml/public/application/contexts/kibana/kibana_context.ts b/x-pack/plugins/ml/public/application/contexts/kibana/kibana_context.ts index d2615e8174dd18..475e44af3669c0 100644 --- a/x-pack/plugins/ml/public/application/contexts/kibana/kibana_context.ts +++ b/x-pack/plugins/ml/public/application/contexts/kibana/kibana_context.ts @@ -11,10 +11,12 @@ import { KibanaReactContextValue, } from '../../../../../../../src/plugins/kibana_react/public'; import { SecurityPluginSetup } from '../../../../../security/public'; +import { LicenseManagementUIPluginSetup } from '../../../../../license_management/public'; interface StartPlugins { data: DataPublicPluginStart; security: SecurityPluginSetup; + licenseManagement?: LicenseManagementUIPluginSetup; } export type StartServices = CoreStart & StartPlugins; // eslint-disable-next-line react-hooks/rules-of-hooks diff --git a/x-pack/plugins/ml/public/application/datavisualizer/datavisualizer_selector.tsx b/x-pack/plugins/ml/public/application/datavisualizer/datavisualizer_selector.tsx index 254788c52a7a81..a8bb5a0a8fe102 100644 --- a/x-pack/plugins/ml/public/application/datavisualizer/datavisualizer_selector.tsx +++ b/x-pack/plugins/ml/public/application/datavisualizer/datavisualizer_selector.tsx @@ -23,7 +23,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { isFullLicense } from '../license'; -import { useTimefilter } from '../contexts/kibana'; +import { useTimefilter, useMlKibana } from '../contexts/kibana'; import { NavigationMenu } from '../components/navigation_menu'; @@ -50,8 +50,14 @@ function startTrialDescription() { export const DatavisualizerSelector: FC = () => { useTimefilter({ timeRangeSelector: false, autoRefreshSelector: false }); + const { + services: { licenseManagement }, + } = useMlKibana(); - const startTrialVisible = isFullLicense() === false; + const startTrialVisible = + licenseManagement !== undefined && + licenseManagement.enabled === true && + isFullLicense() === false; return ( diff --git a/x-pack/plugins/ml/public/plugin.ts b/x-pack/plugins/ml/public/plugin.ts index 30b7133f4147e5..d4bec3d617a048 100644 --- a/x-pack/plugins/ml/public/plugin.ts +++ b/x-pack/plugins/ml/public/plugin.ts @@ -14,6 +14,7 @@ import { DataPublicPluginStart } from 'src/plugins/data/public'; import { SecurityPluginSetup } from '../../security/public'; import { LicensingPluginSetup } from '../../licensing/public'; import { initManagementSection } from './application/management'; +import { LicenseManagementUIPluginSetup } from '../../license_management/public'; import { setDependencyCache } from './application/util/dependency_cache'; import { PLUGIN_ID, PLUGIN_ICON } from '../common/constants/app'; @@ -26,6 +27,7 @@ export interface MlSetupDependencies { licensing: LicensingPluginSetup; management: ManagementSetup; usageCollection: UsageCollectionSetup; + licenseManagement?: LicenseManagementUIPluginSetup; } export class MlPlugin implements Plugin { @@ -50,6 +52,7 @@ export class MlPlugin implements Plugin { licensing: pluginsSetup.licensing, management: pluginsSetup.management, usageCollection: pluginsSetup.usageCollection, + licenseManagement: pluginsSetup.licenseManagement, }, { element: params.element,