@@ -53,10 +53,17 @@ interface Props {
5353 snapshot : ModelSnapshot ;
5454 snapshots : ModelSnapshot [ ] ;
5555 job : CombinedJobWithStats ;
56- closeFlyout ( reload : boolean ) : void ;
56+ closeFlyout ( ) : void ;
57+ refresh ( ) : void ;
5758}
5859
59- export const RevertModelSnapshotFlyout : FC < Props > = ( { snapshot, snapshots, job, closeFlyout } ) => {
60+ export const RevertModelSnapshotFlyout : FC < Props > = ( {
61+ snapshot,
62+ snapshots,
63+ job,
64+ closeFlyout,
65+ refresh,
66+ } ) => {
6067 const { toasts } = useNotifications ( ) ;
6168 const { loadAnomalyDataForJob, loadEventRateForJob } = useMemo (
6269 ( ) => chartLoaderProvider ( mlResultsService ) ,
@@ -73,7 +80,6 @@ export const RevertModelSnapshotFlyout: FC<Props> = ({ snapshot, snapshots, job,
7380 const [ eventRateData , setEventRateData ] = useState < LineChartPoint [ ] > ( [ ] ) ;
7481 const [ anomalies , setAnomalies ] = useState < Anomaly [ ] > ( [ ] ) ;
7582 const [ chartReady , setChartReady ] = useState ( false ) ;
76- const [ applying , setApplying ] = useState ( false ) ;
7783
7884 useEffect ( ( ) => {
7985 createChartData ( ) ;
@@ -110,13 +116,6 @@ export const RevertModelSnapshotFlyout: FC<Props> = ({ snapshot, snapshots, job,
110116 setChartReady ( true ) ;
111117 } , [ job ] ) ;
112118
113- function closeWithReload ( ) {
114- closeFlyout ( true ) ;
115- }
116- function closeWithoutReload ( ) {
117- closeFlyout ( false ) ;
118- }
119-
120119 function showRevertModal ( ) {
121120 setRevertModalVisible ( true ) ;
122121 }
@@ -125,7 +124,6 @@ export const RevertModelSnapshotFlyout: FC<Props> = ({ snapshot, snapshots, job,
125124 }
126125
127126 async function applyRevert ( ) {
128- setApplying ( true ) ;
129127 const end =
130128 replay && runInRealTime === false ? job . data_counts . latest_record_timestamp : undefined ;
131129 try {
@@ -138,17 +136,19 @@ export const RevertModelSnapshotFlyout: FC<Props> = ({ snapshot, snapshots, job,
138136 } ) )
139137 : undefined ;
140138
141- await ml . jobs . revertModelSnapshot (
142- job . job_id ,
143- currentSnapshot . snapshot_id ,
144- replay ,
145- end ,
146- events
147- ) ;
139+ ml . jobs
140+ . revertModelSnapshot ( job . job_id , currentSnapshot . snapshot_id , replay , end , events )
141+ . then ( ( ) => {
142+ toasts . addSuccess (
143+ i18n . translate ( 'xpack.ml.revertModelSnapshotFlyout.revertSuccessTitle' , {
144+ defaultMessage : 'Model snapshot revert successful' ,
145+ } )
146+ ) ;
147+ refresh ( ) ;
148+ } ) ;
148149 hideRevertModal ( ) ;
149- closeWithReload ( ) ;
150+ closeFlyout ( ) ;
150151 } catch ( error ) {
151- setApplying ( false ) ;
152152 toasts . addError ( new Error ( error . body . message ) , {
153153 title : i18n . translate ( 'xpack.ml.revertModelSnapshotFlyout.revertErrorTitle' , {
154154 defaultMessage : 'Model snapshot revert failed' ,
@@ -166,7 +166,7 @@ export const RevertModelSnapshotFlyout: FC<Props> = ({ snapshot, snapshots, job,
166166
167167 return (
168168 < >
169- < EuiFlyout onClose = { closeWithoutReload } hideCloseButton size = "m" >
169+ < EuiFlyout onClose = { closeFlyout } hideCloseButton size = "m" >
170170 < EuiFlyoutHeader hasBorder >
171171 < EuiTitle size = "s" >
172172 < h5 >
@@ -347,7 +347,7 @@ export const RevertModelSnapshotFlyout: FC<Props> = ({ snapshot, snapshots, job,
347347 < EuiFlyoutFooter >
348348 < EuiFlexGroup justifyContent = "spaceBetween" >
349349 < EuiFlexItem grow = { false } >
350- < EuiButtonEmpty iconType = "cross" onClick = { closeWithoutReload } flush = "left" >
350+ < EuiButtonEmpty iconType = "cross" onClick = { closeFlyout } flush = "left" >
351351 < FormattedMessage
352352 id = "xpack.ml.newJob.wizard.revertModelSnapshotFlyout.closeButton"
353353 defaultMessage = "Close"
@@ -392,10 +392,14 @@ export const RevertModelSnapshotFlyout: FC<Props> = ({ snapshot, snapshots, job,
392392 defaultMessage : 'Apply' ,
393393 }
394394 ) }
395- confirmButtonDisabled = { applying }
396395 buttonColor = "danger"
397396 defaultFocusedButton = "confirm"
398- />
397+ >
398+ < FormattedMessage
399+ id = "xpack.ml.newJob.wizard.revertModelSnapshotFlyout.modalBody"
400+ defaultMessage = "The snapshot revert will be carried out in the background and may take some time."
401+ />
402+ </ EuiConfirmModal >
399403 </ EuiOverlayMask >
400404 ) }
401405 </ >
0 commit comments