4
4
*/
5
5
6
6
import React , { useEffect , useState , ReactElement } from 'react' ;
7
- import { useHistory } from 'react-router-dom' ;
8
7
import {
9
8
EuiPageHeader ,
10
9
EuiFlexGroup ,
@@ -29,10 +28,10 @@ import {
29
28
import {
30
29
APP_PATH ,
31
30
USE_NEW_HOME_PAGE ,
32
- constructUrlWithParams ,
33
31
getDataSourceId ,
34
32
dataSourceFilterFn ,
35
33
formikToUiConfig ,
34
+ constructHrefWithDataSourceId ,
36
35
} from '../../../utils' ;
37
36
import { ExportModal } from './export_modal' ;
38
37
import {
@@ -70,11 +69,11 @@ interface WorkflowDetailHeaderProps {
70
69
unsavedSearchProcessors : boolean ;
71
70
setUnsavedSearchProcessors : ( unsavedSearchProcessors : boolean ) => void ;
72
71
setActionMenu : ( menuMount ?: MountPoint ) => void ;
72
+ setBlockNavigation : ( blockNavigation : boolean ) => void ;
73
73
}
74
74
75
75
export function WorkflowDetailHeader ( props : WorkflowDetailHeaderProps ) {
76
76
const dispatch = useAppDispatch ( ) ;
77
- const history = useHistory ( ) ;
78
77
const { resetForm, setTouched, values, touched, dirty } = useFormikContext <
79
78
WorkflowFormValues
80
79
> ( ) ;
@@ -116,12 +115,6 @@ export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
116
115
} ;
117
116
} , [ setHeaderVariant , USE_NEW_HOME_PAGE ] ) ;
118
117
119
- const onExitButtonClick = ( ) => {
120
- history . replace (
121
- constructUrlWithParams ( APP_PATH . WORKFLOWS , undefined , dataSourceId )
122
- ) ;
123
- } ;
124
-
125
118
// get & render the data source component, if applicable
126
119
let DataSourceComponent : ReactElement | null = null ;
127
120
if ( dataSourceEnabled && getDataSourceManagementPlugin ( ) && dataSourceId ) {
@@ -200,21 +193,8 @@ export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
200
193
? ingestSaveButtonDisabled
201
194
: searchSaveButtonDisabled ;
202
195
203
- // Add warning when exiting with unsaved changes
204
- function alertFn ( e : BeforeUnloadEvent ) {
205
- e . preventDefault ( ) ;
206
- }
207
-
208
- // Hook for warning of unsaved changes if a browser refresh is detected
209
196
useEffect ( ( ) => {
210
- if ( ! saveDisabled ) {
211
- window . addEventListener ( 'beforeunload' , alertFn ) ;
212
- } else {
213
- window . removeEventListener ( 'beforeunload' , alertFn ) ;
214
- }
215
- return ( ) => {
216
- window . removeEventListener ( 'beforeunload' , alertFn ) ;
217
- } ;
197
+ props . setBlockNavigation ( ! saveDisabled ) ;
218
198
} , [ saveDisabled ] ) ;
219
199
220
200
// Utility fn to update the workflow UI config only, based on the current form values.
@@ -319,7 +299,10 @@ export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
319
299
iconType : 'exit' ,
320
300
tooltip : 'Return to projects' ,
321
301
ariaLabel : 'Exit' ,
322
- run : onExitButtonClick ,
302
+ href : constructHrefWithDataSourceId (
303
+ APP_PATH . WORKFLOWS ,
304
+ dataSourceId
305
+ ) ,
323
306
controlType : 'icon' ,
324
307
} as TopNavMenuIconData ,
325
308
{
@@ -407,15 +390,10 @@ export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
407
390
Export
408
391
</ EuiSmallButton > ,
409
392
< EuiSmallButtonEmpty
410
- onClick = { ( ) => {
411
- history . replace (
412
- constructUrlWithParams (
413
- APP_PATH . WORKFLOWS ,
414
- undefined ,
415
- dataSourceId
416
- )
417
- ) ;
418
- } }
393
+ href = { constructHrefWithDataSourceId (
394
+ APP_PATH . WORKFLOWS ,
395
+ dataSourceId
396
+ ) }
419
397
data-testid = "closeButton"
420
398
>
421
399
Close
@@ -430,6 +408,7 @@ export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
430
408
{ `Save` }
431
409
</ EuiSmallButtonEmpty > ,
432
410
< EuiSmallButtonIcon
411
+ data-testid = "undoButton"
433
412
iconType = "editorUndo"
434
413
aria-label = "undo changes"
435
414
isDisabled = { undoDisabled }
0 commit comments