Skip to content

Commit 4bc5f01

Browse files
[ML] Add ML deep links to navigational search (#88958)
* [ML] Add ML deep links to navigational search * [ML] Refactor register helper files * [ML] Edit import in search_deep_links * [ML] Move register_feature out of register_helper * [ML] Add comment about registerFeature Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 6391ef9 commit 4bc5f01

File tree

5 files changed

+172
-17
lines changed

5 files changed

+172
-17
lines changed

x-pack/plugins/ml/public/plugin.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export interface MlSetupDependencies {
7070
export type MlCoreSetup = CoreSetup<MlStartDependencies, MlPluginStart>;
7171

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

7676
constructor(private initializerContext: PluginInitializerContext) {}
@@ -85,7 +85,7 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
8585
euiIconType: PLUGIN_ICON_SOLUTION,
8686
appRoute: '/app/ml',
8787
category: DEFAULT_APP_CATEGORIES.kibana,
88-
updater$: this.appUpdater,
88+
updater$: this.appUpdater$,
8989
mount: async (params: AppMountParameters) => {
9090
const [coreStart, pluginsStart] = await core.getStartServices();
9191
const kibanaVersion = this.initializerContext.env.packageInfo.version;
@@ -133,23 +133,34 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
133133
});
134134
} else {
135135
// if ml is disabled in elasticsearch, disable ML in kibana
136-
this.appUpdater.next(() => ({
136+
this.appUpdater$.next(() => ({
137137
status: AppStatus.inaccessible,
138138
}));
139139
}
140140

141141
// register various ML plugin features which require a full license
142-
const { registerEmbeddables, registerManagementSection, registerMlUiActions } = await import(
143-
'./register_helper'
144-
);
145-
146-
if (isMlEnabled(license) && isFullLicense(license)) {
147-
const canManageMLJobs = capabilities.management?.insightsAndAlerting?.jobsListLink ?? false;
148-
if (canManageMLJobs && pluginsSetup.management !== undefined) {
149-
registerManagementSection(pluginsSetup.management, core).enable();
142+
// note including registerFeature in register_helper would cause the page bundle size to increase significantly
143+
const {
144+
registerEmbeddables,
145+
registerManagementSection,
146+
registerMlUiActions,
147+
registerSearchLinks,
148+
} = await import('./register_helper');
149+
150+
const mlEnabled = isMlEnabled(license);
151+
const fullLicense = isFullLicense(license);
152+
if (mlEnabled) {
153+
registerSearchLinks(this.appUpdater$, fullLicense);
154+
155+
if (fullLicense) {
156+
const canManageMLJobs =
157+
capabilities.management?.insightsAndAlerting?.jobsListLink ?? false;
158+
if (canManageMLJobs && pluginsSetup.management !== undefined) {
159+
registerManagementSection(pluginsSetup.management, core).enable();
160+
}
161+
registerEmbeddables(pluginsSetup.embeddable, core);
162+
registerMlUiActions(pluginsSetup.uiActions, core);
150163
}
151-
registerEmbeddables(pluginsSetup.embeddable, core);
152-
registerMlUiActions(pluginsSetup.uiActions, core);
153164
}
154165
});
155166

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { registerEmbeddables } from '../embeddables';
8+
export { registerManagementSection } from '../application/management';
9+
export { registerMlUiActions } from '../ui_actions';
10+
export { registerSearchLinks } from './register_search_links';

x-pack/plugins/ml/public/register_helper.ts renamed to x-pack/plugins/ml/public/register_helper/register_search_links/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export { registerEmbeddables } from './embeddables';
8-
export { registerFeature } from './register_feature';
9-
export { registerManagementSection } from './application/management';
10-
export { registerMlUiActions } from './ui_actions';
7+
export { registerSearchLinks } from './register_search_links';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { i18n } from '@kbn/i18n';
8+
import { BehaviorSubject } from 'rxjs';
9+
10+
import { AppUpdater } from 'src/core/public';
11+
import { getSearchDeepLinks } from './search_deep_links';
12+
13+
export function registerSearchLinks(
14+
appUpdater: BehaviorSubject<AppUpdater>,
15+
isFullLicense: boolean
16+
) {
17+
appUpdater.next(() => ({
18+
meta: {
19+
keywords: [
20+
i18n.translate('xpack.ml.keyword.ml', {
21+
defaultMessage: 'ML',
22+
}),
23+
],
24+
searchDeepLinks: getSearchDeepLinks(isFullLicense),
25+
},
26+
}));
27+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { i18n } from '@kbn/i18n';
8+
9+
import type { AppSearchDeepLink } from 'src/core/public';
10+
import { ML_PAGES } from '../../../common/constants/ml_url_generator';
11+
12+
const OVERVIEW_LINK_SEARCH_DEEP_LINK: AppSearchDeepLink = {
13+
id: 'mlOverviewSearchDeepLink',
14+
title: i18n.translate('xpack.ml.searchDeepLink.overview', {
15+
defaultMessage: 'Overview',
16+
}),
17+
path: `/${ML_PAGES.OVERVIEW}`,
18+
};
19+
20+
const ANOMALY_DETECTION_SEARCH_DEEP_LINK: AppSearchDeepLink = {
21+
id: 'mlAnomalyDetectionSearchDeepLink',
22+
title: i18n.translate('xpack.ml.searchDeepLink.anomalyDetection', {
23+
defaultMessage: 'Anomaly Detection',
24+
}),
25+
path: `/${ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE}`,
26+
};
27+
28+
const DATA_FRAME_ANALYTICS_SEARCH_DEEP_LINK: AppSearchDeepLink = {
29+
id: 'mlDataFrameAnalyticsSearchDeepLink',
30+
title: i18n.translate('xpack.ml.searchDeepLink.dataFrameAnalytics', {
31+
defaultMessage: 'Data Frame Analytics',
32+
}),
33+
path: `/${ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE}`,
34+
searchDeepLinks: [
35+
{
36+
id: 'mlTrainedModelsSearchDeepLink',
37+
title: i18n.translate('xpack.ml.searchDeepLink.trainedModels', {
38+
defaultMessage: 'Trained Models',
39+
}),
40+
path: `/${ML_PAGES.DATA_FRAME_ANALYTICS_MODELS_MANAGE}`,
41+
},
42+
],
43+
};
44+
45+
const DATA_VISUALIZER_SEARCH_DEEP_LINK: AppSearchDeepLink = {
46+
id: 'mlDataVisualizerSearchDeepLink',
47+
title: i18n.translate('xpack.ml.searchDeepLink.dataVisualizer', {
48+
defaultMessage: 'Data Visualizer',
49+
}),
50+
path: `/${ML_PAGES.DATA_VISUALIZER}`,
51+
};
52+
53+
const FILE_UPLOAD_SEARCH_DEEP_LINK: AppSearchDeepLink = {
54+
id: 'mlFileUploadSearchDeepLink',
55+
title: i18n.translate('xpack.ml.searchDeepLink.fileUpload', {
56+
defaultMessage: 'File Upload',
57+
}),
58+
path: `/${ML_PAGES.DATA_VISUALIZER_FILE}`,
59+
};
60+
61+
const INDEX_DATA_VISUALIZER_SEARCH_DEEP_LINK: AppSearchDeepLink = {
62+
id: 'mlIndexDataVisualizerSearchDeepLink',
63+
title: i18n.translate('xpack.ml.searchDeepLink.indexDataVisualizer', {
64+
defaultMessage: 'Index Data Visualizer',
65+
}),
66+
path: `/${ML_PAGES.DATA_VISUALIZER_INDEX_SELECT}`,
67+
};
68+
69+
const SETTINGS_SEARCH_DEEP_LINK: AppSearchDeepLink = {
70+
id: 'mlSettingsSearchDeepLink',
71+
title: i18n.translate('xpack.ml.searchDeepLink.settings', {
72+
defaultMessage: 'Settings',
73+
}),
74+
path: `/${ML_PAGES.SETTINGS}`,
75+
searchDeepLinks: [
76+
{
77+
id: 'mlCalendarSettingsSearchDeepLink',
78+
title: i18n.translate('xpack.ml.searchDeepLink.calendarSettings', {
79+
defaultMessage: 'Calendars',
80+
}),
81+
path: `/${ML_PAGES.CALENDARS_MANAGE}`,
82+
},
83+
{
84+
id: 'mlFilterListsSettingsSearchDeepLink',
85+
title: i18n.translate('xpack.ml.searchDeepLink.filterListsSettings', {
86+
defaultMessage: 'Filter Lists',
87+
}),
88+
path: `/${ML_PAGES.SETTINGS}`, // Link to settings page as read only users cannot view filter lists.
89+
},
90+
],
91+
};
92+
93+
export function getSearchDeepLinks(isFullLicense: boolean) {
94+
const deepLinks: AppSearchDeepLink[] = [
95+
DATA_VISUALIZER_SEARCH_DEEP_LINK,
96+
FILE_UPLOAD_SEARCH_DEEP_LINK,
97+
INDEX_DATA_VISUALIZER_SEARCH_DEEP_LINK,
98+
];
99+
100+
if (isFullLicense === true) {
101+
deepLinks.push(
102+
OVERVIEW_LINK_SEARCH_DEEP_LINK,
103+
ANOMALY_DETECTION_SEARCH_DEEP_LINK,
104+
DATA_FRAME_ANALYTICS_SEARCH_DEEP_LINK,
105+
SETTINGS_SEARCH_DEEP_LINK
106+
);
107+
}
108+
109+
return deepLinks;
110+
}

0 commit comments

Comments
 (0)