Skip to content

Commit

Permalink
[ML] Disabling start trial option when license management ui is disab…
Browse files Browse the repository at this point in the history
…led (elastic#60987) (elastic#61309)

* [ML] Disabling start trial option when license management ui is disabled

* tiny refactor

* changes based on review
  • Loading branch information
jgowdyelastic authored Mar 25, 2020
1 parent 27bd06e commit b1fd4d5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/license_management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
20 changes: 16 additions & 4 deletions x-pack/plugins/license_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@ interface PluginsDependencies {
telemetry?: TelemetryPluginSetup;
}

export class LicenseManagementUIPlugin implements Plugin<void, void, any, any> {
export interface LicenseManagementUIPluginSetup {
enabled: boolean;
}
export type LicenseManagementUIPluginStart = void;

export class LicenseManagementUIPlugin
implements Plugin<LicenseManagementUIPluginSetup, LicenseManagementUIPluginStart, any, any> {
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<ClientConfigType>();

if (!config.ui.enabled) {
// No need to go any further
return;
return {
enabled: false,
};
}

const { getStartServices } = coreSetup;
Expand Down Expand Up @@ -76,8 +84,12 @@ export class LicenseManagementUIPlugin implements Plugin<void, void, any, any> {
return renderApp(element, appDependencies);
},
});

return {
enabled: true,
};
}

start() {}
start(): LicenseManagementUIPluginStart {}
stop() {}
}
3 changes: 2 additions & 1 deletion x-pack/plugins/ml/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"optionalPlugins": [
"security",
"spaces",
"management"
"management",
"licenseManagement"
],
"server": true,
"ui": true
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const App: FC<AppProps> = ({ coreStart, deps }) => {
appName: 'ML',
data: deps.data,
security: deps.security,
licenseManagement: deps.licenseManagement,
storage: localStorage,
...coreStart,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 (
<Fragment>
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -26,6 +27,7 @@ export interface MlSetupDependencies {
licensing: LicensingPluginSetup;
management: ManagementSetup;
usageCollection: UsageCollectionSetup;
licenseManagement?: LicenseManagementUIPluginSetup;
}

export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
Expand All @@ -50,6 +52,7 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
licensing: pluginsSetup.licensing,
management: pluginsSetup.management,
usageCollection: pluginsSetup.usageCollection,
licenseManagement: pluginsSetup.licenseManagement,
},
{
element: params.element,
Expand Down

0 comments on commit b1fd4d5

Please sign in to comment.