@@ -102,6 +102,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
102
102
setTouched,
103
103
values,
104
104
touched,
105
+ dirty,
105
106
} = useFormikContext < WorkflowFormValues > ( ) ;
106
107
const dispatch = useAppDispatch ( ) ;
107
108
const dataSourceId = getDataSourceId ( ) ;
@@ -278,9 +279,36 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
278
279
setIngestProvisioned ( hasProvisionedIngestResources ( props . workflow ) ) ;
279
280
} , [ props . workflow ] ) ;
280
281
281
- // Utility fn to update the workflow UI config only. A get workflow API call is subsequently run
282
- // to fetch the updated state.
282
+ // maintain global states (button eligibility)
283
+ const ingestUndoButtonDisabled =
284
+ isRunningSave || isRunningIngest
285
+ ? true
286
+ : unsavedIngestProcessors
287
+ ? false
288
+ : ! dirty ;
289
+ const ingestSaveButtonDisabled = ingestUndoButtonDisabled ;
290
+ const ingestRunButtonDisabled = ! ingestTemplatesDifferent ;
291
+ const ingestToSearchButtonDisabled =
292
+ ingestTemplatesDifferent || isRunningIngest ;
293
+ const searchBackButtonDisabled =
294
+ isRunningSearch ||
295
+ ( isProposingNoSearchResources ? false : searchTemplatesDifferent ) ;
296
+ const searchUndoButtonDisabled =
297
+ isRunningSave || isRunningSearch
298
+ ? true
299
+ : unsavedSearchProcessors
300
+ ? false
301
+ : isEmpty ( touched ?. search ) || ! dirty ;
302
+ const searchSaveButtonDisabled = searchUndoButtonDisabled ;
303
+ const searchRunButtonDisabled =
304
+ isRunningSearch ||
305
+ ( isProposingNoSearchResources &&
306
+ hasProvisionedSearchResources ( props . workflow ) ) ;
307
+
308
+ // Utility fn to update the workflow UI config only, based on the current form values.
309
+ // A get workflow API call is subsequently run to fetch the updated state.
283
310
async function updateWorkflowUiConfig ( ) {
311
+ let success = false ;
284
312
setIsRunningSave ( true ) ;
285
313
const updatedTemplate = {
286
314
name : props . workflow ?. name ,
@@ -302,6 +330,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
302
330
)
303
331
. unwrap ( )
304
332
. then ( async ( result ) => {
333
+ success = true ;
305
334
setUnsavedIngestProcessors ( false ) ;
306
335
setUnsavedSearchProcessors ( false ) ;
307
336
setTouched ( { } ) ;
@@ -320,6 +349,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
320
349
. finally ( ( ) => {
321
350
setIsRunningSave ( false ) ;
322
351
} ) ;
352
+ return success ;
323
353
}
324
354
325
355
// Utility fn to revert any unsaved changes, reset the form
@@ -342,7 +372,9 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
342
372
reprovision : boolean
343
373
) : Promise < boolean > {
344
374
let success = false ;
345
- if ( reprovision ) {
375
+ if ( ! ingestTemplatesDifferent && ! searchTemplatesDifferent ) {
376
+ success = await updateWorkflowUiConfig ( ) ;
377
+ } else if ( reprovision ) {
346
378
await dispatch (
347
379
updateWorkflow ( {
348
380
apiBody : {
@@ -794,29 +826,15 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
794
826
< EuiSmallButtonIcon
795
827
iconType = "editorUndo"
796
828
aria-label = "undo changes"
797
- isDisabled = {
798
- isRunningSave || isRunningIngest
799
- ? true
800
- : unsavedIngestProcessors
801
- ? false
802
- : isEmpty ( touched ?. ingest ?. enrich ) &&
803
- isEmpty ( touched ?. ingest ?. index )
804
- }
829
+ isDisabled = { ingestUndoButtonDisabled }
805
830
onClick = { ( ) => {
806
831
revertUnsavedChanges ( ) ;
807
832
} }
808
833
/>
809
834
</ EuiFlexItem >
810
835
< EuiFlexItem grow = { false } >
811
836
< EuiSmallButtonEmpty
812
- disabled = {
813
- isRunningSave || isRunningIngest
814
- ? true
815
- : unsavedIngestProcessors
816
- ? false
817
- : isEmpty ( touched ?. ingest ?. enrich ) &&
818
- isEmpty ( touched ?. ingest ?. index )
819
- }
837
+ disabled = { ingestSaveButtonDisabled }
820
838
isLoading = { isRunningSave }
821
839
onClick = { ( ) => {
822
840
updateWorkflowUiConfig ( ) ;
@@ -831,7 +849,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
831
849
onClick = { ( ) => {
832
850
validateAndRunIngestion ( ) ;
833
851
} }
834
- disabled = { ! ingestTemplatesDifferent }
852
+ disabled = { ingestRunButtonDisabled }
835
853
isLoading = { isRunningIngest }
836
854
>
837
855
Build and run ingestion
@@ -843,7 +861,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
843
861
onClick = { ( ) => {
844
862
setSelectedStep ( STEP . SEARCH ) ;
845
863
} }
846
- disabled = { ingestTemplatesDifferent || isRunningIngest }
864
+ disabled = { ingestToSearchButtonDisabled }
847
865
>
848
866
{ `Search pipeline >` }
849
867
</ EuiSmallButton >
@@ -853,12 +871,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
853
871
< >
854
872
< EuiFlexItem grow = { false } >
855
873
< EuiSmallButtonEmpty
856
- disabled = {
857
- isRunningSearch ||
858
- ( isProposingNoSearchResources
859
- ? false
860
- : searchTemplatesDifferent )
861
- }
874
+ disabled = { searchBackButtonDisabled }
862
875
onClick = { ( ) => setSelectedStep ( STEP . INGEST ) }
863
876
>
864
877
Back
@@ -868,27 +881,15 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
868
881
< EuiSmallButtonIcon
869
882
iconType = "editorUndo"
870
883
aria-label = "undo changes"
871
- isDisabled = {
872
- isRunningSave || isRunningSearch
873
- ? true
874
- : unsavedSearchProcessors
875
- ? false
876
- : isEmpty ( touched ?. search )
877
- }
884
+ isDisabled = { searchUndoButtonDisabled }
878
885
onClick = { ( ) => {
879
886
revertUnsavedChanges ( ) ;
880
887
} }
881
888
/>
882
889
</ EuiFlexItem >
883
890
< EuiFlexItem grow = { false } >
884
891
< EuiSmallButtonEmpty
885
- disabled = {
886
- isRunningSave || isRunningSearch
887
- ? true
888
- : unsavedSearchProcessors
889
- ? false
890
- : isEmpty ( touched ?. search )
891
- }
892
+ disabled = { searchSaveButtonDisabled }
892
893
isLoading = { isRunningSave }
893
894
onClick = { ( ) => {
894
895
updateWorkflowUiConfig ( ) ;
@@ -899,11 +900,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
899
900
</ EuiFlexItem >
900
901
< EuiFlexItem grow = { false } >
901
902
< EuiSmallButton
902
- disabled = {
903
- isRunningSearch ||
904
- ( isProposingNoSearchResources &&
905
- hasProvisionedSearchResources ( props . workflow ) )
906
- }
903
+ disabled = { searchRunButtonDisabled }
907
904
isLoading = { isRunningSearch }
908
905
fill = { false }
909
906
onClick = { ( ) => {
0 commit comments