Skip to content

Commit b87f32e

Browse files
authored
Fix reprovision bug; improve button state and readability (#364)
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent eb21762 commit b87f32e

File tree

1 file changed

+43
-46
lines changed

1 file changed

+43
-46
lines changed

public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx

+43-46
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
102102
setTouched,
103103
values,
104104
touched,
105+
dirty,
105106
} = useFormikContext<WorkflowFormValues>();
106107
const dispatch = useAppDispatch();
107108
const dataSourceId = getDataSourceId();
@@ -278,9 +279,36 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
278279
setIngestProvisioned(hasProvisionedIngestResources(props.workflow));
279280
}, [props.workflow]);
280281

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.
283310
async function updateWorkflowUiConfig() {
311+
let success = false;
284312
setIsRunningSave(true);
285313
const updatedTemplate = {
286314
name: props.workflow?.name,
@@ -302,6 +330,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
302330
)
303331
.unwrap()
304332
.then(async (result) => {
333+
success = true;
305334
setUnsavedIngestProcessors(false);
306335
setUnsavedSearchProcessors(false);
307336
setTouched({});
@@ -320,6 +349,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
320349
.finally(() => {
321350
setIsRunningSave(false);
322351
});
352+
return success;
323353
}
324354

325355
// Utility fn to revert any unsaved changes, reset the form
@@ -342,7 +372,9 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
342372
reprovision: boolean
343373
): Promise<boolean> {
344374
let success = false;
345-
if (reprovision) {
375+
if (!ingestTemplatesDifferent && !searchTemplatesDifferent) {
376+
success = await updateWorkflowUiConfig();
377+
} else if (reprovision) {
346378
await dispatch(
347379
updateWorkflow({
348380
apiBody: {
@@ -794,29 +826,15 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
794826
<EuiSmallButtonIcon
795827
iconType="editorUndo"
796828
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}
805830
onClick={() => {
806831
revertUnsavedChanges();
807832
}}
808833
/>
809834
</EuiFlexItem>
810835
<EuiFlexItem grow={false}>
811836
<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}
820838
isLoading={isRunningSave}
821839
onClick={() => {
822840
updateWorkflowUiConfig();
@@ -831,7 +849,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
831849
onClick={() => {
832850
validateAndRunIngestion();
833851
}}
834-
disabled={!ingestTemplatesDifferent}
852+
disabled={ingestRunButtonDisabled}
835853
isLoading={isRunningIngest}
836854
>
837855
Build and run ingestion
@@ -843,7 +861,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
843861
onClick={() => {
844862
setSelectedStep(STEP.SEARCH);
845863
}}
846-
disabled={ingestTemplatesDifferent || isRunningIngest}
864+
disabled={ingestToSearchButtonDisabled}
847865
>
848866
{`Search pipeline >`}
849867
</EuiSmallButton>
@@ -853,12 +871,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
853871
<>
854872
<EuiFlexItem grow={false}>
855873
<EuiSmallButtonEmpty
856-
disabled={
857-
isRunningSearch ||
858-
(isProposingNoSearchResources
859-
? false
860-
: searchTemplatesDifferent)
861-
}
874+
disabled={searchBackButtonDisabled}
862875
onClick={() => setSelectedStep(STEP.INGEST)}
863876
>
864877
Back
@@ -868,27 +881,15 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
868881
<EuiSmallButtonIcon
869882
iconType="editorUndo"
870883
aria-label="undo changes"
871-
isDisabled={
872-
isRunningSave || isRunningSearch
873-
? true
874-
: unsavedSearchProcessors
875-
? false
876-
: isEmpty(touched?.search)
877-
}
884+
isDisabled={searchUndoButtonDisabled}
878885
onClick={() => {
879886
revertUnsavedChanges();
880887
}}
881888
/>
882889
</EuiFlexItem>
883890
<EuiFlexItem grow={false}>
884891
<EuiSmallButtonEmpty
885-
disabled={
886-
isRunningSave || isRunningSearch
887-
? true
888-
: unsavedSearchProcessors
889-
? false
890-
: isEmpty(touched?.search)
891-
}
892+
disabled={searchSaveButtonDisabled}
892893
isLoading={isRunningSave}
893894
onClick={() => {
894895
updateWorkflowUiConfig();
@@ -899,11 +900,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
899900
</EuiFlexItem>
900901
<EuiFlexItem grow={false}>
901902
<EuiSmallButton
902-
disabled={
903-
isRunningSearch ||
904-
(isProposingNoSearchResources &&
905-
hasProvisionedSearchResources(props.workflow))
906-
}
903+
disabled={searchRunButtonDisabled}
907904
isLoading={isRunningSearch}
908905
fill={false}
909906
onClick={() => {

0 commit comments

Comments
 (0)