Skip to content

Commit

Permalink
[ML] Add ML deep links to navigational search
Browse files Browse the repository at this point in the history
  • Loading branch information
peteharverson committed Jan 21, 2021
1 parent dfd96d6 commit befab0c
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 6 deletions.
110 changes: 110 additions & 0 deletions x-pack/plugins/ml/public/ml_url_generator/search_deep_links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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 { AppSearchDeepLink } from 'src/core/public';
import { ML_PAGES } from '../../common/constants/ml_url_generator';

const OVERVIEW_LINK_SEARCH_DEEP_LINK: AppSearchDeepLink = {
id: 'mlOverviewSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.overview', {
defaultMessage: 'Overview',
}),
path: `/${ML_PAGES.OVERVIEW}`,
};

const ANOMALY_DETECTION_SEARCH_DEEP_LINK: AppSearchDeepLink = {
id: 'mlAnomalyDetectionSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.anomalyDetection', {
defaultMessage: 'Anomaly Detection',
}),
path: `/${ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE}`,
};

const DATA_FRAME_ANALYTICS_SEARCH_DEEP_LINK: AppSearchDeepLink = {
id: 'mlDataFrameAnalyticsSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.dataFrameAnalytics', {
defaultMessage: 'Data Frame Analytics',
}),
path: `/${ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE}`,
searchDeepLinks: [
{
id: 'mlTrainedModelsSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.trainedModels', {
defaultMessage: 'Trained Models',
}),
path: `/${ML_PAGES.DATA_FRAME_ANALYTICS_MODELS_MANAGE}`,
},
],
};

const DATA_VISUALIZER_SEARCH_DEEP_LINK: AppSearchDeepLink = {
id: 'mlDataVisualizerSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.dataVisualizer', {
defaultMessage: 'Data Visualizer',
}),
path: `/${ML_PAGES.DATA_VISUALIZER}`,
};

const FILE_UPLOAD_SEARCH_DEEP_LINK: AppSearchDeepLink = {
id: 'mlFileUploadSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.fileUpload', {
defaultMessage: 'File Upload',
}),
path: `/${ML_PAGES.DATA_VISUALIZER_FILE}`,
};

const INDEX_DATA_VISUALIZER_SEARCH_DEEP_LINK: AppSearchDeepLink = {
id: 'mlIndexDataVisualizerSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.indexDataVisualizer', {
defaultMessage: 'Index Data Visualizer',
}),
path: `/${ML_PAGES.DATA_VISUALIZER_INDEX_SELECT}`,
};

const SETTINGS_SEARCH_DEEP_LINK: AppSearchDeepLink = {
id: 'mlSettingsSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.settings', {
defaultMessage: 'Settings',
}),
path: `/${ML_PAGES.SETTINGS}`,
searchDeepLinks: [
{
id: 'mlCalendarSettingsSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.calendarSettings', {
defaultMessage: 'Calendars',
}),
path: `/${ML_PAGES.CALENDARS_MANAGE}`,
},
{
id: 'mlFilterListsSettingsSearchDeepLink',
title: i18n.translate('xpack.ml.searchDeepLink.filterListsSettings', {
defaultMessage: 'Filter Lists',
}),
path: `/${ML_PAGES.SETTINGS}`, // Link to settings page as read only users cannot view filter lists.
},
],
};

export function getSearchDeepLinks(isFullLicense: boolean) {
const deepLinks: AppSearchDeepLink[] = [
DATA_VISUALIZER_SEARCH_DEEP_LINK,
FILE_UPLOAD_SEARCH_DEEP_LINK,
INDEX_DATA_VISUALIZER_SEARCH_DEEP_LINK,
];

if (isFullLicense === true) {
deepLinks.push(
OVERVIEW_LINK_SEARCH_DEEP_LINK,
ANOMALY_DETECTION_SEARCH_DEEP_LINK,
DATA_FRAME_ANALYTICS_SEARCH_DEEP_LINK,
SETTINGS_SEARCH_DEEP_LINK
);
}

return deepLinks;
}
29 changes: 23 additions & 6 deletions x-pack/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { isFullLicense, isMlEnabled } from '../common/license';
import { setDependencyCache } from './application/util/dependency_cache';
import { registerFeature } from './register_feature';
// 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 Down Expand Up @@ -143,13 +144,29 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
'./register_helper'
);

if (isMlEnabled(license) && isFullLicense(license)) {
const canManageMLJobs = capabilities.management?.insightsAndAlerting?.jobsListLink ?? false;
if (canManageMLJobs && pluginsSetup.management !== undefined) {
registerManagementSection(pluginsSetup.management, core).enable();
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),
},
}));

if (fullLicense) {
const canManageMLJobs =
capabilities.management?.insightsAndAlerting?.jobsListLink ?? false;
if (canManageMLJobs && pluginsSetup.management !== undefined) {
registerManagementSection(pluginsSetup.management, core).enable();
}
registerEmbeddables(pluginsSetup.embeddable, core);
registerMlUiActions(pluginsSetup.uiActions, core);
}
registerEmbeddables(pluginsSetup.embeddable, core);
registerMlUiActions(pluginsSetup.uiActions, core);
}
});

Expand Down

0 comments on commit befab0c

Please sign in to comment.