From a57a3f17ddc10c6de73388762f343c7a27e02ca1 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 30 Jul 2020 13:44:37 -0700 Subject: [PATCH] Closes #72914 by hiding anomaly detection settings links when the ml plugin is disabled. (#73638) Co-authored-by: Elastic Machine # Conflicts: # x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx # x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx # x-pack/plugins/apm/public/components/app/Settings/index.tsx --- .../apm/public/components/app/Home/index.tsx | 11 ++++--- .../anomaly_detection/add_environments.tsx | 2 +- .../app/Settings/anomaly_detection/index.tsx | 4 +-- .../public/components/app/Settings/index.tsx | 33 ++++++++++++------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/Home/index.tsx b/x-pack/plugins/apm/public/components/app/Home/index.tsx index b09c03f853aa9..c6c0861c26a34 100644 --- a/x-pack/plugins/apm/public/components/app/Home/index.tsx +++ b/x-pack/plugins/apm/public/components/app/Home/index.tsx @@ -83,7 +83,8 @@ interface Props { } export function Home({ tab }: Props) { - const { config } = useApmPluginContext(); + const { config, core } = useApmPluginContext(); + const isMLEnabled = !!core.application.capabilities.ml; const homeTabs = getHomeTabs(config); const selectedTab = homeTabs.find( (homeTab) => homeTab.name === tab @@ -105,9 +106,11 @@ export function Home({ tab }: Props) { - - - + {isMLEnabled && ( + + + + )} diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx index c9328c4988e5f..246d95613e55e 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx @@ -64,7 +64,7 @@ export const AddEnvironments = ({ return ( {MLErrorMessages.MISSING_WRITE_PRIVILEGES}} /> diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx index abbe1e2c83c7b..8c729b5c4ce9c 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx @@ -30,7 +30,7 @@ const DEFAULT_VALUE: AnomalyDetectionApiResponse = { export const AnomalyDetection = () => { const plugin = useApmPluginContext(); - const canGetJobs = !!plugin.core.application.capabilities.ml.canGetJobs; + const canGetJobs = !!plugin.core.application.capabilities.ml?.canGetJobs; const license = useLicense(); const hasValidLicense = license?.isActive && license?.hasAtLeast('platinum'); @@ -66,7 +66,7 @@ export const AnomalyDetection = () => { return ( {MLErrorMessages.MISSING_READ_PRIVILEGES}} /> diff --git a/x-pack/plugins/apm/public/components/app/Settings/index.tsx b/x-pack/plugins/apm/public/components/app/Settings/index.tsx index 6d8571bf57767..b93cb35de519c 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/index.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/index.tsx @@ -16,8 +16,11 @@ import { import { HomeLink } from '../../shared/Links/apm/HomeLink'; import { useLocation } from '../../../hooks/useLocation'; import { getAPMHref } from '../../shared/Links/apm/APMLink'; +import { useApmPluginContext } from '../../../hooks/useApmPluginContext'; export const Settings: React.FC = (props) => { + const plugin = useApmPluginContext(); + const isMLEnabled = !!plugin.core.application.capabilities.ml; const { search, pathname } = useLocation(); return ( <> @@ -48,17 +51,25 @@ export const Settings: React.FC = (props) => { '/settings/agent-configuration' ), }, - { - name: i18n.translate( - 'xpack.apm.settings.anomalyDetection', - { - defaultMessage: 'Anomaly detection', - } - ), - id: '4', - href: getAPMHref('/settings/anomaly-detection', search), - isSelected: pathname === '/settings/anomaly-detection', - }, + ...(isMLEnabled + ? [ + { + name: i18n.translate( + 'xpack.apm.settings.anomalyDetection', + { + defaultMessage: 'Anomaly detection', + } + ), + id: '4', + href: getAPMHref( + '/settings/anomaly-detection', + search + ), + isSelected: + pathname === '/settings/anomaly-detection', + }, + ] + : []), { name: i18n.translate('xpack.apm.settings.customizeApp', { defaultMessage: 'Customize app',