@@ -22,7 +22,12 @@ import { useMonitorId } from '../../../hooks';
2222import { setAlertFlyoutType , setAlertFlyoutVisible } from '../../../state/actions' ;
2323import { useAnomalyAlert } from './use_anomaly_alert' ;
2424import { ConfirmAlertDeletion } from './confirm_alert_delete' ;
25- import { deleteAnomalyAlertAction } from '../../../state/alerts/alerts' ;
25+ import {
26+ deleteAnomalyAlertAction ,
27+ getAnomalyAlertAction ,
28+ isAnomalyAlertDeleting ,
29+ } from '../../../state/alerts/alerts' ;
30+ import { UptimeEditAlertFlyoutComponent } from '../../common/alerts/uptime_edit_alert_flyout' ;
2631
2732interface Props {
2833 hasMLJob : boolean ;
@@ -33,11 +38,14 @@ interface Props {
3338export const ManageMLJobComponent = ( { hasMLJob, onEnableJob, onJobDelete } : Props ) => {
3439 const [ isPopOverOpen , setIsPopOverOpen ] = useState ( false ) ;
3540
41+ const [ isFlyoutOpen , setIsFlyoutOpen ] = useState ( false ) ;
42+
3643 const { basePath } = useContext ( UptimeSettingsContext ) ;
3744
3845 const canDeleteMLJob = useSelector ( canDeleteMLJobSelector ) ;
3946
4047 const isMLJobCreating = useSelector ( isMLJobCreatingSelector ) ;
48+ const isAlertDeleting = useSelector ( isAnomalyAlertDeleting ) ;
4149
4250 const { loading : isMLJobLoading } = useSelector ( hasMLJobSelector ) ;
4351
@@ -54,7 +62,7 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
5462 const deleteAnomalyAlert = ( ) =>
5563 dispatch ( deleteAnomalyAlertAction . get ( { alertId : anomalyAlert ?. id as string } ) ) ;
5664
57- const showLoading = isMLJobCreating || isMLJobLoading ;
65+ const showLoading = isMLJobCreating || isMLJobLoading || isAlertDeleting ;
5866
5967 const btnText = hasMLJob ? labels . ANOMALY_DETECTION : labels . ENABLE_ANOMALY_DETECTION ;
6068
@@ -63,7 +71,7 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
6371 data-test-subj = { hasMLJob ? 'uptimeManageMLJobBtn' : 'uptimeEnableAnomalyBtn' }
6472 onClick = { hasMLJob ? ( ) => setIsPopOverOpen ( true ) : onEnableJob }
6573 disabled = { hasMLJob && ! canDeleteMLJob }
66- isLoading = { isMLJobCreating || isMLJobLoading }
74+ isLoading = { showLoading }
6775 size = "s"
6876 aria-label = { labels . ENABLE_MANAGE_JOB }
6977 >
@@ -85,21 +93,27 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
8593 dateRange : { from : dateRangeStart , to : dateRangeEnd } ,
8694 } ) ,
8795 } ,
88- {
89- name : anomalyAlert ? labels . DISABLE_ANOMALY_ALERT : labels . ENABLE_ANOMALY_ALERT ,
90- 'data-test-subj' : anomalyAlert
91- ? 'uptimeDisableAnomalyAlertBtn'
92- : 'uptimeEnableAnomalyAlertBtn' ,
93- icon : < EuiIcon type = { anomalyAlert ? 'bellSlash' : 'bell' } size = "m" /> ,
94- onClick : ( ) => {
95- if ( anomalyAlert ) {
96- setIsConfirmAlertDeleteOpen ( true ) ;
97- } else {
98- dispatch ( setAlertFlyoutType ( CLIENT_ALERT_TYPES . DURATION_ANOMALY ) ) ;
99- dispatch ( setAlertFlyoutVisible ( true ) ) ;
100- }
101- } ,
102- } ,
96+ ...( anomalyAlert
97+ ? [
98+ {
99+ name : 'Anomaly alert' ,
100+ icon : 'bell' ,
101+ 'data-test-subj' : 'uptimeManageAnomalyAlertBtn' ,
102+ panel : 1 ,
103+ } ,
104+ ]
105+ : [
106+ {
107+ name : labels . ENABLE_ANOMALY_ALERT ,
108+ 'data-test-subj' : 'uptimeEnableAnomalyAlertBtn' ,
109+ icon : 'bell' ,
110+ onClick : ( ) => {
111+ dispatch ( setAlertFlyoutType ( CLIENT_ALERT_TYPES . DURATION_ANOMALY ) ) ;
112+ dispatch ( setAlertFlyoutVisible ( true ) ) ;
113+ setIsPopOverOpen ( false ) ;
114+ } ,
115+ } ,
116+ ] ) ,
103117 {
104118 name : labels . DISABLE_ANOMALY_DETECTION ,
105119 'data-test-subj' : 'uptimeDeleteMLJobBtn' ,
@@ -111,6 +125,27 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
111125 } ,
112126 ] ,
113127 } ,
128+ {
129+ id : 1 ,
130+ title : 'Anomaly alert' ,
131+ items : [
132+ {
133+ name : 'Edit' ,
134+ 'data-test-subj' : 'uptimeEditAnomalyAlertBtn' ,
135+ onClick : ( ) => {
136+ setIsFlyoutOpen ( true ) ;
137+ setIsPopOverOpen ( false ) ;
138+ } ,
139+ } ,
140+ {
141+ name : 'Disable' ,
142+ 'data-test-subj' : 'uptimeDisableAnomalyAlertBtn' ,
143+ onClick : ( ) => {
144+ setIsConfirmAlertDeleteOpen ( true ) ;
145+ } ,
146+ } ,
147+ ] ,
148+ } ,
114149 ] ;
115150
116151 return (
@@ -138,6 +173,14 @@ export const ManageMLJobComponent = ({ hasMLJob, onEnableJob, onJobDelete }: Pro
138173 } }
139174 />
140175 ) }
176+ < UptimeEditAlertFlyoutComponent
177+ initialAlert = { anomalyAlert ! }
178+ alertFlyoutVisible = { isFlyoutOpen }
179+ setAlertFlyoutVisibility = { ( ) => {
180+ setIsFlyoutOpen ( false ) ;
181+ dispatch ( getAnomalyAlertAction . get ( { monitorId } ) ) ;
182+ } }
183+ />
141184 </ >
142185 ) ;
143186} ;
0 commit comments