Skip to content

Commit

Permalink
[ML] Refactor register helper files
Browse files Browse the repository at this point in the history
  • Loading branch information
peteharverson committed Jan 21, 2021
1 parent befab0c commit 911527a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
29 changes: 11 additions & 18 deletions x-pack/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ import { ML_APP_URL_GENERATOR } from '../common/constants/ml_url_generator';
import { isFullLicense, isMlEnabled } from '../common/license';

import { setDependencyCache } from './application/util/dependency_cache';
import { registerFeature } from './register_feature';
import { registerFeature } from './register_helper';
// Not importing from `ml_url_generator/index` here to avoid importing unnecessary code
import { getSearchDeepLinks } from './ml_url_generator/search_deep_links';
import { registerUrlGenerator } from './ml_url_generator/ml_url_generator';

export interface MlStartDependencies {
Expand All @@ -71,7 +70,7 @@ export interface MlSetupDependencies {
export type MlCoreSetup = CoreSetup<MlStartDependencies, MlPluginStart>;

export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
private appUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private appUpdater$ = new BehaviorSubject<AppUpdater>(() => ({}));
private urlGenerator: undefined | UrlGeneratorContract<typeof ML_APP_URL_GENERATOR>;

constructor(private initializerContext: PluginInitializerContext) {}
Expand All @@ -86,7 +85,7 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
euiIconType: PLUGIN_ICON_SOLUTION,
appRoute: '/app/ml',
category: DEFAULT_APP_CATEGORIES.kibana,
updater$: this.appUpdater,
updater$: this.appUpdater$,
mount: async (params: AppMountParameters) => {
const [coreStart, pluginsStart] = await core.getStartServices();
const kibanaVersion = this.initializerContext.env.packageInfo.version;
Expand Down Expand Up @@ -134,29 +133,23 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
});
} else {
// if ml is disabled in elasticsearch, disable ML in kibana
this.appUpdater.next(() => ({
this.appUpdater$.next(() => ({
status: AppStatus.inaccessible,
}));
}

// register various ML plugin features which require a full license
const { registerEmbeddables, registerManagementSection, registerMlUiActions } = await import(
'./register_helper'
);
const {
registerEmbeddables,
registerManagementSection,
registerMlUiActions,
registerSearchLinks,
} = await import('./register_helper');

const mlEnabled = isMlEnabled(license);
const fullLicense = isFullLicense(license);
if (mlEnabled) {
this.appUpdater.next(() => ({
meta: {
keywords: [
i18n.translate('xpack.ml.keyword.ml', {
defaultMessage: 'ML',
}),
],
searchDeepLinks: getSearchDeepLinks(fullLicense),
},
}));
registerSearchLinks(this.appUpdater$, fullLicense);

if (fullLicense) {
const canManageMLJobs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { registerEmbeddables } from './embeddables';
export { registerEmbeddables } from '../embeddables';
export { registerFeature } from './register_feature';
export { registerManagementSection } from './application/management';
export { registerMlUiActions } from './ui_actions';
export { registerManagementSection } from '../application/management';
export { registerMlUiActions } from '../ui_actions';
export { registerSearchLinks } from './register_search_links';
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { i18n } from '@kbn/i18n';
import {
FeatureCatalogueCategory,
HomePublicPluginSetup,
} from '../../../../src/plugins/home/public';
import { PLUGIN_ID } from '../common/constants/app';
} from '../../../../../src/plugins/home/public';
import { PLUGIN_ID } from '../../common/constants/app';

export const registerFeature = (home: HomePublicPluginSetup) => {
// register ML for the kibana home screen.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { registerSearchLinks } from './register_search_links';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import { BehaviorSubject } from 'rxjs';

import { AppUpdater } from 'src/core/public';
import { getSearchDeepLinks } from './search_deep_links';

export function registerSearchLinks(
appUpdater: BehaviorSubject<AppUpdater>,
isFullLicense: boolean
) {
appUpdater.next(() => ({
meta: {
keywords: [
i18n.translate('xpack.ml.keyword.ml', {
defaultMessage: 'ML',
}),
],
searchDeepLinks: getSearchDeepLinks(isFullLicense),
},
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';

import { AppSearchDeepLink } from 'src/core/public';
import { ML_PAGES } from '../../common/constants/ml_url_generator';
import { ML_PAGES } from '../../../common/constants/ml_url_generator';

const OVERVIEW_LINK_SEARCH_DEEP_LINK: AppSearchDeepLink = {
id: 'mlOverviewSearchDeepLink',
Expand Down

0 comments on commit 911527a

Please sign in to comment.