diff --git a/public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx b/public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx index aa21fb45..c58641fc 100644 --- a/public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx +++ b/public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx @@ -102,6 +102,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { setTouched, values, touched, + dirty, } = useFormikContext(); const dispatch = useAppDispatch(); const dataSourceId = getDataSourceId(); @@ -278,9 +279,36 @@ export function WorkflowInputs(props: WorkflowInputsProps) { setIngestProvisioned(hasProvisionedIngestResources(props.workflow)); }, [props.workflow]); - // Utility fn to update the workflow UI config only. A get workflow API call is subsequently run - // to fetch the updated state. + // maintain global states (button eligibility) + const ingestUndoButtonDisabled = + isRunningSave || isRunningIngest + ? true + : unsavedIngestProcessors + ? false + : !dirty; + const ingestSaveButtonDisabled = ingestUndoButtonDisabled; + const ingestRunButtonDisabled = !ingestTemplatesDifferent; + const ingestToSearchButtonDisabled = + ingestTemplatesDifferent || isRunningIngest; + const searchBackButtonDisabled = + isRunningSearch || + (isProposingNoSearchResources ? false : searchTemplatesDifferent); + const searchUndoButtonDisabled = + isRunningSave || isRunningSearch + ? true + : unsavedSearchProcessors + ? false + : isEmpty(touched?.search) || !dirty; + const searchSaveButtonDisabled = searchUndoButtonDisabled; + const searchRunButtonDisabled = + isRunningSearch || + (isProposingNoSearchResources && + hasProvisionedSearchResources(props.workflow)); + + // Utility fn to update the workflow UI config only, based on the current form values. + // A get workflow API call is subsequently run to fetch the updated state. async function updateWorkflowUiConfig() { + let success = false; setIsRunningSave(true); const updatedTemplate = { name: props.workflow?.name, @@ -302,6 +330,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { ) .unwrap() .then(async (result) => { + success = true; setUnsavedIngestProcessors(false); setUnsavedSearchProcessors(false); setTouched({}); @@ -320,6 +349,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { .finally(() => { setIsRunningSave(false); }); + return success; } // Utility fn to revert any unsaved changes, reset the form @@ -342,7 +372,9 @@ export function WorkflowInputs(props: WorkflowInputsProps) { reprovision: boolean ): Promise { let success = false; - if (reprovision) { + if (!ingestTemplatesDifferent && !searchTemplatesDifferent) { + success = await updateWorkflowUiConfig(); + } else if (reprovision) { await dispatch( updateWorkflow({ apiBody: { @@ -795,14 +827,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { { revertUnsavedChanges(); }} @@ -810,14 +835,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { { updateWorkflowUiConfig(); @@ -833,7 +851,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { validateAndRunIngestion(); }} data-testid="runIngestionButton" - disabled={!ingestTemplatesDifferent} + disabled={ingestRunButtonDisabled} isLoading={isRunningIngest} > Build and run ingestion @@ -846,7 +864,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { setSelectedStep(STEP.SEARCH); }} data-testid="searchPipelineButton" - disabled={ingestTemplatesDifferent || isRunningIngest} + disabled={ingestToSearchButtonDisabled} > {`Search pipeline >`} @@ -856,12 +874,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { <> setSelectedStep(STEP.INGEST)} > Back @@ -871,13 +884,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { { revertUnsavedChanges(); }} @@ -885,13 +892,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { { updateWorkflowUiConfig(); @@ -902,11 +903,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { {