Skip to content

Commit

Permalink
[uptime] Fix anomaly alert edit (#93025) (#93381)
Browse files Browse the repository at this point in the history
Co-authored-by: Shahzad <[email protected]>
  • Loading branch information
kibanamachine and shahzad31 authored Mar 3, 2021
1 parent 67994a9 commit 10516d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useKibana } from '../../../../../../../src/plugins/kibana_react/public'
import {
Alert,
TriggersAndActionsUIPublicPluginStart,
} from '../../../../../../plugins/triggers_actions_ui/public';
} from '../../../../../triggers_actions_ui/public';

interface Props {
alertFlyoutVisible: boolean;
Expand All @@ -27,19 +27,17 @@ export const UptimeEditAlertFlyoutComponent = ({
initialAlert,
setAlertFlyoutVisibility,
}: Props) => {
const onClose = () => {
setAlertFlyoutVisibility(false);
};
const { triggersActionsUi } = useKibana<KibanaDeps>().services;

const EditAlertFlyout = useMemo(
() =>
triggersActionsUi.getEditAlertFlyout({
initialAlert,
onClose,
onClose: () => {
setAlertFlyoutVisibility(false);
},
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
[initialAlert, setAlertFlyoutVisibility, triggersActionsUi]
);
return <>{alertFlyoutVisible && EditAlertFlyout}</>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useContext, useState } from 'react';
import React, { useCallback, useContext, useState } from 'react';

import { EuiButton, EuiContextMenu, EuiIcon, EuiPopover } from '@elastic/eui';
import { useSelector, useDispatch } from 'react-redux';
Expand All @@ -14,6 +14,7 @@ import {
canDeleteMLJobSelector,
hasMLJobSelector,
isMLJobCreatingSelector,
mlCapabilitiesSelector,
} from '../../../state/selectors';
import { UptimeSettingsContext } from '../../../contexts';
import * as labels from './translations';
Expand Down Expand Up @@ -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();

Expand All @@ -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;

Expand Down Expand Up @@ -149,6 +151,11 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
},
];

const onCloseFlyout = useCallback(() => {
setIsFlyoutOpen(false);
dispatch(getAnomalyAlertAction.get({ monitorId }));
}, [dispatch, monitorId]);

return (
<>
<EuiPopover
Expand All @@ -174,14 +181,13 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
}}
/>
)}
<UptimeEditAlertFlyoutComponent
initialAlert={anomalyAlert!}
alertFlyoutVisible={isFlyoutOpen}
setAlertFlyoutVisibility={() => {
setIsFlyoutOpen(false);
dispatch(getAnomalyAlertAction.get({ monitorId }));
}}
/>
{isFlyoutOpen && (
<UptimeEditAlertFlyoutComponent
initialAlert={anomalyAlert!}
alertFlyoutVisible={isFlyoutOpen}
setAlertFlyoutVisibility={onCloseFlyout}
/>
)}
</>
);
};
8 changes: 4 additions & 4 deletions x-pack/plugins/uptime/public/state/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 10516d3

Please sign in to comment.