diff --git a/x-pack/plugins/uptime/public/components/monitor/ml/manage_ml_job.tsx b/x-pack/plugins/uptime/public/components/monitor/ml/manage_ml_job.tsx index 2a8f3d32a2670..719bc329c626a 100644 --- a/x-pack/plugins/uptime/public/components/monitor/ml/manage_ml_job.tsx +++ b/x-pack/plugins/uptime/public/components/monitor/ml/manage_ml_job.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React, { useCallback, useContext, useEffect, useState } from 'react'; +import React, { useCallback, useContext, useState } from 'react'; import { EuiButton, EuiContextMenu, EuiIcon, EuiPopover } from '@elastic/eui'; import { useSelector, useDispatch } from 'react-redux'; @@ -14,6 +14,7 @@ import { canDeleteMLJobSelector, hasMLJobSelector, isMLJobCreatingSelector, + mlCapabilitiesSelector, } from '../../../state/selectors'; import { UptimeSettingsContext } from '../../../contexts'; import * as labels from './translations'; @@ -49,6 +50,7 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro const isAlertDeleting = useSelector(isAnomalyAlertDeleting); const { loading: isMLJobLoading } = useSelector(hasMLJobSelector); + const { loading: isCapbilityLoading } = useSelector(mlCapabilitiesSelector); const { dateRangeStart, dateRangeEnd } = useGetUrlParams(); @@ -63,7 +65,7 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro const deleteAnomalyAlert = () => dispatch(deleteAnomalyAlertAction.get({ alertId: anomalyAlert?.id as string })); - const showLoading = isMLJobCreating || isMLJobLoading || isAlertDeleting; + const showLoading = isMLJobCreating || isMLJobLoading || isAlertDeleting || isCapbilityLoading; const btnText = hasMLJob ? labels.ANOMALY_DETECTION : labels.ENABLE_ANOMALY_DETECTION; @@ -179,11 +181,13 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro }} /> )} - + {isFlyoutOpen && ( + + )} ); }; diff --git a/x-pack/plugins/uptime/public/state/selectors/index.ts b/x-pack/plugins/uptime/public/state/selectors/index.ts index afe4f25b7b18f..53aaa5ca30ea6 100644 --- a/x-pack/plugins/uptime/public/state/selectors/index.ts +++ b/x-pack/plugins/uptime/public/state/selectors/index.ts @@ -37,22 +37,22 @@ export const selectPingList = ({ pingList }: AppState) => pingList; export const snapshotDataSelector = ({ snapshot }: AppState) => snapshot; -const mlCapabilitiesSelector = (state: AppState) => state.ml.mlCapabilities.data; +export const mlCapabilitiesSelector = (state: AppState) => state.ml.mlCapabilities; export const hasMLFeatureSelector = createSelector( mlCapabilitiesSelector, (mlCapabilities) => - mlCapabilities?.isPlatinumOrTrialLicense && mlCapabilities?.mlFeatureEnabledInSpace + mlCapabilities?.data?.isPlatinumOrTrialLicense && mlCapabilities?.data?.mlFeatureEnabledInSpace ); export const canCreateMLJobSelector = createSelector( mlCapabilitiesSelector, - (mlCapabilities) => mlCapabilities?.capabilities.canCreateJob + (mlCapabilities) => mlCapabilities?.data?.capabilities?.canCreateJob ); export const canDeleteMLJobSelector = createSelector( mlCapabilitiesSelector, - (mlCapabilities) => mlCapabilities?.capabilities.canDeleteJob + (mlCapabilities) => mlCapabilities?.data?.capabilities?.canDeleteJob ); export const hasMLJobSelector = ({ ml }: AppState) => ml.mlJob;