fix(striker-ui): reset checklist after delete in manage fences, manifests

main
Tsu-ba-me 1 year ago
parent cf4e4ff3f0
commit d7d7fcb039
  1. 16
      striker-ui/components/ManageFence/ManageFencePanel.tsx
  2. 16
      striker-ui/components/ManageManifest/ManageManifestPanel.tsx
  3. 4
      striker-ui/hooks/useChecklist.tsx

@ -155,8 +155,14 @@ const ManageFencePanel: FC = () => {
const formUtils = useFormUtils([INPUT_ID_FENCE_AGENT], messageGroupRef); const formUtils = useFormUtils([INPUT_ID_FENCE_AGENT], messageGroupRef);
const { isFormInvalid, isFormSubmitting, submitForm } = formUtils; const { isFormInvalid, isFormSubmitting, submitForm } = formUtils;
const { buildDeleteDialogProps, checks, getCheck, hasChecks, setCheck } = const {
useChecklist({ list: fenceOverviews }); buildDeleteDialogProps,
checks,
getCheck,
hasChecks,
resetChecklist,
setCheck,
} = useChecklist({ list: fenceOverviews });
const getFormSummaryEntryLabel = useCallback<GetFormEntryLabelFunction>( const getFormSummaryEntryLabel = useCallback<GetFormEntryLabelFunction>(
({ cap, depth, key }) => (depth === 0 ? cap(key) : key), ({ cap, depth, key }) => (depth === 0 ? cap(key) : key),
@ -238,7 +244,10 @@ const ManageFencePanel: FC = () => {
<>Failed to delete fence device(s). {parentMsg}</> <>Failed to delete fence device(s). {parentMsg}</>
), ),
method: 'delete', method: 'delete',
onSuccess: () => getFenceOverviews(), onSuccess: () => {
getFenceOverviews();
resetChecklist();
},
url: '/fence', url: '/fence',
}); });
}, },
@ -373,6 +382,7 @@ const ManageFencePanel: FC = () => {
getFormSummaryEntryLabel, getFormSummaryEntryLabel,
hasChecks, hasChecks,
isEditFences, isEditFences,
resetChecklist,
setCheck, setCheck,
setConfirmDialogProps, setConfirmDialogProps,
setFormDialogProps, setFormDialogProps,

@ -212,8 +212,14 @@ const ManageManifestPanel: FC = () => {
submitForm: submitRunForm, submitForm: submitRunForm,
} = runFormUtils; } = runFormUtils;
const { buildDeleteDialogProps, checks, getCheck, hasChecks, setCheck } = const {
useChecklist({ buildDeleteDialogProps,
checks,
getCheck,
hasChecks,
resetChecklist,
setCheck,
} = useChecklist({
list: manifestOverviews, list: manifestOverviews,
}); });
@ -437,7 +443,10 @@ const ManageManifestPanel: FC = () => {
<>Delete manifest(s) failed. {parentMsg}</> <>Delete manifest(s) failed. {parentMsg}</>
), ),
method: 'delete', method: 'delete',
onSuccess: () => getManifestOverviews(), onSuccess: () => {
getManifestOverviews();
resetChecklist();
},
url: `/manifest`, url: `/manifest`,
}); });
}, },
@ -494,6 +503,7 @@ const ManageManifestPanel: FC = () => {
hasChecks, hasChecks,
isEditManifests, isEditManifests,
manifestOverviews, manifestOverviews,
resetChecklist,
setCheck, setCheck,
setConfirmDialogProps, setConfirmDialogProps,
setManifestDetail, setManifestDetail,

@ -16,6 +16,7 @@ const useChecklist = ({
hasAllChecks: boolean; hasAllChecks: boolean;
hasChecks: boolean; hasChecks: boolean;
multipleItems: boolean; multipleItems: boolean;
resetChecklist: () => void;
setAllChecks: SetAllChecksFunction; setAllChecks: SetAllChecksFunction;
setCheck: SetCheckFunction; setCheck: SetCheckFunction;
} => { } => {
@ -61,6 +62,8 @@ const useChecklist = ({
[checklist], [checklist],
); );
const resetChecklist = useCallback(() => setChecklist({}), []);
const setAllChecks = useCallback<SetAllChecksFunction>( const setAllChecks = useCallback<SetAllChecksFunction>(
(checked) => (checked) =>
setChecklist( setChecklist(
@ -89,6 +92,7 @@ const useChecklist = ({
hasAllChecks, hasAllChecks,
hasChecks, hasChecks,
multipleItems, multipleItems,
resetChecklist,
setAllChecks, setAllChecks,
setCheck, setCheck,
}; };

Loading…
Cancel
Save