Skip to content

Commit

Permalink
fixing links when not in serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jun 29, 2023
1 parent 826b9d2 commit c29461a
Showing 1 changed file with 40 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,159 +12,154 @@ import { type AppDeepLink, AppNavLinkStatus } from '@kbn/core/public';
import { ML_PAGES } from '../../../common/constants/locator';
import type { MlCapabilities } from '../../shared';

function getNavStatus(
mlCapabilities: MlCapabilities,
statusIfServerless: boolean
): AppNavLinkStatus | undefined {
if (mlCapabilities.isADEnabled && mlCapabilities.isDFAEnabled && mlCapabilities.isNLPEnabled) {
// if all features are enabled we can assume that we are not running in serverless mode.
// returning default will not add the link to the nav menu, but the link will be registered for searching
return AppNavLinkStatus.default;
}

return statusIfServerless ? AppNavLinkStatus.visible : AppNavLinkStatus.hidden;
}

function getOverviewLinkDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<LinkId> {
return {
id: 'overview',
title: i18n.translate('xpack.ml.deepLink.overview', {
defaultMessage: 'Overview',
}),
path: `/${ML_PAGES.OVERVIEW}`,
navLinkStatus:
mlCapabilities.isADEnabled && mlCapabilities.isDFAEnabled && mlCapabilities.isNLPEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus: getNavStatus(mlCapabilities, false),
};
}

function getAnomalyDetectionDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<LinkId> {
const navLinkStatus = getNavStatus(mlCapabilities, mlCapabilities.isADEnabled);
return {
id: 'anomalyDetection',
title: i18n.translate('xpack.ml.deepLink.anomalyDetection', {
defaultMessage: 'Anomaly Detection',
}),
path: `/${ML_PAGES.ANOMALY_DETECTION_JOBS_MANAGE}`,
navLinkStatus: mlCapabilities.isADEnabled ? AppNavLinkStatus.visible : AppNavLinkStatus.hidden,
navLinkStatus,
deepLinks: [
{
id: 'anomalyExplorer',
title: i18n.translate('xpack.ml.deepLink.anomalyExplorer', {
defaultMessage: 'Anomaly explorer',
}),
path: `/${ML_PAGES.ANOMALY_EXPLORER}`,
navLinkStatus: mlCapabilities.isADEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
{
id: 'singleMetricViewer',
title: i18n.translate('xpack.ml.deepLink.singleMetricViewer', {
defaultMessage: 'Single metric viewer',
}),
path: `/${ML_PAGES.SINGLE_METRIC_VIEWER}`,
navLinkStatus: mlCapabilities.isADEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
],
};
}

function getDataFrameAnalyticsDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<LinkId> {
const navLinkStatus = getNavStatus(mlCapabilities, mlCapabilities.isDFAEnabled);
return {
id: 'dataFrameAnalytics',
title: i18n.translate('xpack.ml.deepLink.dataFrameAnalytics', {
defaultMessage: 'Data Frame Analytics',
}),
path: `/${ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE}`,
navLinkStatus: mlCapabilities.isDFAEnabled ? AppNavLinkStatus.visible : AppNavLinkStatus.hidden,
navLinkStatus,
deepLinks: [
{
id: 'resultExplorer',
title: i18n.translate('xpack.ml.deepLink.resultExplorer', {
defaultMessage: 'Results explorer',
}),
path: `/${ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION}`,
navLinkStatus: mlCapabilities.isDFAEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
{
id: 'analyticsMap',
title: i18n.translate('xpack.ml.deepLink.analyticsMap', {
defaultMessage: 'Analytics map',
}),
path: `/${ML_PAGES.DATA_FRAME_ANALYTICS_MAP}`,
navLinkStatus: mlCapabilities.isDFAEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
],
};
}

function getAiopsDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<LinkId> {
const navLinkStatus = getNavStatus(mlCapabilities, mlCapabilities.canUseAiops);
return {
id: 'aiOps',
title: i18n.translate('xpack.ml.deepLink.aiOps', {
defaultMessage: 'AIOps',
}),
// Default to the index select page for the explain log rate spikes since we don't have an AIops overview page
path: `/${ML_PAGES.AIOPS_EXPLAIN_LOG_RATE_SPIKES_INDEX_SELECT}`,
navLinkStatus: mlCapabilities.canUseAiops ? AppNavLinkStatus.visible : AppNavLinkStatus.hidden,
navLinkStatus,
deepLinks: [
{
id: 'explainLogRateSpikes',
title: i18n.translate('xpack.ml.deepLink.explainLogRateSpikes', {
defaultMessage: 'Explain Log Rate Spikes',
}),
path: `/${ML_PAGES.AIOPS_EXPLAIN_LOG_RATE_SPIKES_INDEX_SELECT}`,
navLinkStatus: mlCapabilities.canUseAiops
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
{
id: 'logPatternAnalysis',
title: i18n.translate('xpack.ml.deepLink.logPatternAnalysis', {
defaultMessage: 'Log Pattern Analysis',
}),
path: `/${ML_PAGES.AIOPS_LOG_CATEGORIZATION_INDEX_SELECT}`,
navLinkStatus: mlCapabilities.canUseAiops
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
{
id: 'changePointDetections',
title: i18n.translate('xpack.ml.deepLink.changePointDetection', {
defaultMessage: 'Change Point Detection',
}),
path: `/${ML_PAGES.AIOPS_CHANGE_POINT_DETECTION_INDEX_SELECT}`,
navLinkStatus: mlCapabilities.canUseAiops
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
],
};
}

function getModelManagementDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<LinkId> {
const navLinkStatus = getNavStatus(mlCapabilities, mlCapabilities.isNLPEnabled);
return {
id: 'modelManagement',
title: i18n.translate('xpack.ml.deepLink.modelManagement', {
defaultMessage: 'Model Management',
}),
path: `/${ML_PAGES.TRAINED_MODELS_MANAGE}`,
navLinkStatus: mlCapabilities.isNLPEnabled ? AppNavLinkStatus.visible : AppNavLinkStatus.hidden,
navLinkStatus,
deepLinks: [
{
id: 'nodesOverview',
title: i18n.translate('xpack.ml.deepLink.trainedModels', {
defaultMessage: 'Trained Models',
}),
path: `/${ML_PAGES.TRAINED_MODELS_MANAGE}`,
navLinkStatus: mlCapabilities.isNLPEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
{
id: 'nodes',
title: i18n.translate('xpack.ml.deepLink.nodes', {
defaultMessage: 'Nodes',
}),
path: `/${ML_PAGES.NODES}`,
navLinkStatus:
mlCapabilities.isADEnabled && mlCapabilities.isDFAEnabled && mlCapabilities.isNLPEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus: getNavStatus(mlCapabilities, false),
},
],
};
Expand All @@ -177,10 +172,7 @@ function getMemoryUsageDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<Lin
defaultMessage: 'Memory Usage',
}),
path: `/${ML_PAGES.MEMORY_USAGE}`,
navLinkStatus:
mlCapabilities.isADEnabled && mlCapabilities.isDFAEnabled && mlCapabilities.isNLPEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus: getNavStatus(mlCapabilities, false),
};
}

Expand All @@ -191,10 +183,7 @@ function getDataVisualizerDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<
defaultMessage: 'Data Visualizer',
}),
path: `/${ML_PAGES.DATA_VISUALIZER}`,
navLinkStatus:
mlCapabilities.isADEnabled && mlCapabilities.isDFAEnabled && mlCapabilities.isNLPEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus: getNavStatus(mlCapabilities, false),
};
}

Expand All @@ -206,10 +195,7 @@ function getFileUploadDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<Link
}),
keywords: ['CSV', 'JSON'],
path: `/${ML_PAGES.DATA_VISUALIZER_FILE}`,
navLinkStatus:
mlCapabilities.isADEnabled && mlCapabilities.isDFAEnabled && mlCapabilities.isNLPEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus: getNavStatus(mlCapabilities, false),
};
}

Expand All @@ -220,41 +206,35 @@ function getIndexDataVisualizerDeepLink(mlCapabilities: MlCapabilities): AppDeep
defaultMessage: 'Index Data Visualizer',
}),
path: `/${ML_PAGES.DATA_VISUALIZER_INDEX_SELECT}`,
navLinkStatus:
mlCapabilities.isADEnabled && mlCapabilities.isDFAEnabled && mlCapabilities.isNLPEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus: getNavStatus(mlCapabilities, false),
};
}

function getSettingsDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<LinkId> {
const navLinkStatus = getNavStatus(mlCapabilities, mlCapabilities.isADEnabled);
return {
id: 'settings',
title: i18n.translate('xpack.ml.deepLink.settings', {
defaultMessage: 'Settings',
}),
path: `/${ML_PAGES.SETTINGS}`,
navLinkStatus: mlCapabilities.isADEnabled ? AppNavLinkStatus.visible : AppNavLinkStatus.hidden,
navLinkStatus,
deepLinks: [
{
id: 'calendarSettings',
title: i18n.translate('xpack.ml.deepLink.calendarSettings', {
defaultMessage: 'Calendars',
}),
path: `/${ML_PAGES.CALENDARS_MANAGE}`,
navLinkStatus: mlCapabilities.isADEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
{
id: 'filterListsSettings',
title: i18n.translate('xpack.ml.deepLink.filterListsSettings', {
defaultMessage: 'Filter Lists',
}),
path: `/${ML_PAGES.SETTINGS}`, // Link to settings page as read only users cannot view filter lists.
navLinkStatus: mlCapabilities.isADEnabled
? AppNavLinkStatus.visible
: AppNavLinkStatus.hidden,
navLinkStatus,
},
],
};
Expand All @@ -267,7 +247,7 @@ function getNotificationsDeepLink(mlCapabilities: MlCapabilities): AppDeepLink<L
defaultMessage: 'Notifications',
}),
path: `/${ML_PAGES.NOTIFICATIONS}`,
navLinkStatus: AppNavLinkStatus.visible,
navLinkStatus: getNavStatus(mlCapabilities, true),
};
}

Expand Down

0 comments on commit c29461a

Please sign in to comment.