Skip to content

Commit bee9c8a

Browse files
committed
improve fine-grained loading
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent e6e6b71 commit bee9c8a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

public/pages/workflow_detail/workspace/resizable_workspace.tsx

+14-10
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
7777
props.workflow
7878
);
7979

80-
// Loading state
81-
const [isProvisioning, setIsProvisioning] = useState<boolean>(false);
82-
const [isDeprovisioning, setIsDeprovisioning] = useState<boolean>(false);
83-
const [isSaving, setIsSaving] = useState<boolean>(false);
84-
const isLoadingGlobal =
85-
loading || isProvisioning || isDeprovisioning || isSaving;
86-
8780
// Formik form state
8881
const [formValues, setFormValues] = useState<WorkspaceFormValues>({});
8982
const [formSchema, setFormSchema] = useState<WorkspaceSchema>(yup.object({}));
@@ -109,7 +102,7 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
109102
ReactFlowComponent
110103
>();
111104

112-
// Save/provision button state
105+
// Save/provision/deprovision button state
113106
const isSaveable = isFirstSave ? true : isDirty;
114107
const isProvisionable =
115108
!isDirty &&
@@ -121,6 +114,14 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
121114
!props.isNewWorkflow &&
122115
props.workflow?.state !== WORKFLOW_STATE.NOT_STARTED;
123116

117+
// Loading state
118+
const [isProvisioning, setIsProvisioning] = useState<boolean>(false);
119+
const [isDeprovisioning, setIsDeprovisioning] = useState<boolean>(false);
120+
const [isSaving, setIsSaving] = useState<boolean>(false);
121+
const isCreating = isSaving && props.isNewWorkflow;
122+
const isLoadingGlobal =
123+
loading || isProvisioning || isDeprovisioning || isSaving || isCreating;
124+
124125
/**
125126
* Custom listener on when nodes are selected / de-selected. Passed to
126127
* downstream ReactFlow components you can listen using
@@ -251,9 +252,9 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
251252
// The workaround is to additionally execute validateForm() which will return any errors found.
252253
formikProps.submitForm();
253254
formikProps.validateForm().then((validationResults: {}) => {
254-
setIsSaving(false);
255255
if (Object.keys(validationResults).length > 0) {
256256
setFormValidOnSubmit(false);
257+
setIsSaving(false);
257258
} else {
258259
setFormValidOnSubmit(true);
259260
let curFlowState = reactFlowInstance.toObject() as WorkspaceFlowState;
@@ -275,6 +276,7 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
275276
} else {
276277
// TODO: bubble up flow error?
277278
setFlowValidOnSubmit(false);
279+
setIsSaving(false);
278280
}
279281
}
280282
});
@@ -383,6 +385,7 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
383385
(updatedWorkflow) => {
384386
if (updatedWorkflow.id) {
385387
// TODO: add update workflow API
388+
// make sure to set isSaving to false in catch block
386389
} else {
387390
dispatch(createWorkflow(updatedWorkflow))
388391
.unwrap()
@@ -394,13 +397,14 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
394397
.catch((error: any) => {
395398
// TODO: process error (toast msg?)
396399
console.log('error: ', error);
400+
setIsSaving(false);
397401
});
398402
}
399403
}
400404
);
401405
}}
402406
>
403-
{props.isNewWorkflow ? 'Create' : 'Save'}
407+
{props.isNewWorkflow || isCreating ? 'Create' : 'Save'}
404408
</EuiButton>,
405409
]}
406410
bottomBorder={false}

0 commit comments

Comments
 (0)