Skip to content

Commit

Permalink
🐛 Reset wizard form after analysis run (#1267)
Browse files Browse the repository at this point in the history
- Resolves #1256 
- When closing the wizard, the taskgroup state hangs around between
analysis runs causing problems. This PR cleans up the react state when
closing/submitting the analysis wizard

Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 authored Aug 8, 2023
1 parent e47565e commit 3d72ff9
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
const [stepIdReached, setStepIdReached] = React.useState(1);
const isMutating = useIsMutating();

React.useEffect(() => {
if (!currentTaskgroup) {
createTaskgroup(defaultTaskgroup);
}
}, []);

const onCreateTaskgroupSuccess = (data: Taskgroup) => {
setCurrentTaskgroup(data);
};
Expand Down Expand Up @@ -287,12 +281,22 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({

const isModeValid = applications.every((app) => isModeSupported(app, mode));

const handleCancel = () => {
if (currentTaskgroup && currentTaskgroup.id) {
deleteTaskgroup(currentTaskgroup.id);
}
setCurrentTaskgroup(null);
reset();
onClose();
};

const onSubmit = (fieldValues: AnalysisWizardFormValues) => {
if (currentTaskgroup) {
const taskgroup = setupTaskgroup(currentTaskgroup, fieldValues);

submitTaskgroup(taskgroup);
}
setCurrentTaskgroup(null);
reset();
onClose();
};

Expand All @@ -301,13 +305,11 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
{ prevId, prevName }
) => {
if (id && stepIdReached < (id as number)) setStepIdReached(id as number);
};

const handleClose = () => {
reset();
if (currentTaskgroup && currentTaskgroup.id)
deleteTaskgroup(currentTaskgroup.id);
onClose();
if (id === StepId.SetTargets) {
if (!currentTaskgroup) {
createTaskgroup(defaultTaskgroup);
}
}
};

const analyzableApplications = useAnalyzableApplications(applications, mode);
Expand Down Expand Up @@ -410,7 +412,7 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
onBack={onMove}
onSave={handleSubmit(onSubmit)}
onClose={() => {
handleClose();
handleCancel();
}}
/>
</FormProvider>
Expand Down

0 comments on commit 3d72ff9

Please sign in to comment.