fix(striker-ui): enable confirm dialog for submit run manifest

main
Tsu-ba-me 2 years ago
parent 1b4a5baeb5
commit 39e3623085
  1. 57
      striker-ui/components/ManageManifest/ManageManifestPanel.tsx

@ -149,18 +149,20 @@ const ManageManifestPanel: FC = () => {
const runManifestFormDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); const runManifestFormDialogRef = useRef<ConfirmDialogForwardedRefContent>({});
const messageGroupRef = useRef<MessageGroupForwardedRefContent>({}); const messageGroupRef = useRef<MessageGroupForwardedRefContent>({});
const [confirmDialogProps] = useConfirmDialogProps(); const [confirmDialogProps, setConfirmDialogProps] = useConfirmDialogProps();
const [hostOverviews, setHostOverviews] = useProtectedState< const [hostOverviews, setHostOverviews] = useProtectedState<
APIHostOverviewList | undefined APIHostOverviewList | undefined
>(undefined); >(undefined);
const [isEditManifests, setIsEditManifests] = useState<boolean>(false); const [isEditManifests, setIsEditManifests] = useState<boolean>(false);
const [isLoadingHostOverviews, setIsLoadingHostOverviews] = const [isLoadingHostOverviews, setIsLoadingHostOverviews] =
useState<boolean>(true); useProtectedState<boolean>(true);
const [isLoadingManifestDetail, setIsLoadingManifestDetail] = const [isLoadingManifestDetail, setIsLoadingManifestDetail] =
useProtectedState<boolean>(true); useProtectedState<boolean>(true);
const [isLoadingManifestTemplate, setIsLoadingManifestTemplate] = const [isLoadingManifestTemplate, setIsLoadingManifestTemplate] =
useState<boolean>(true); useProtectedState<boolean>(true);
const [isSubmittingManifestExecution, setIsSubmittingManifestExecution] =
useProtectedState<boolean>(false);
const [manifestDetail, setManifestDetail] = useProtectedState< const [manifestDetail, setManifestDetail] = useProtectedState<
APIManifestDetail | undefined APIManifestDetail | undefined
>(undefined); >(undefined);
@ -196,8 +198,11 @@ const ManageManifestPanel: FC = () => {
); );
const { isFormInvalid: isRunFormInvalid } = runFormUtils; const { isFormInvalid: isRunFormInvalid } = runFormUtils;
const { hostConfig: { hosts: mdetailHosts = {} } = {}, name: mdetailName } = const {
useMemo<Partial<APIManifestDetail>>( hostConfig: { hosts: mdetailHosts = {} } = {},
name: mdetailName,
uuid: mdetailUuid,
} = useMemo<Partial<APIManifestDetail>>(
() => manifestDetail ?? {}, () => manifestDetail ?? {},
[manifestDetail], [manifestDetail],
); );
@ -283,19 +288,42 @@ const ManageManifestPanel: FC = () => {
), ),
loading: isLoadingManifestDetail, loading: isLoadingManifestDetail,
onSubmitAppend: (...args) => { onSubmitAppend: (...args) => {
getRunFormData(mdetailHosts, ...args); const body = getRunFormData(mdetailHosts, ...args);
setConfirmDialogProps({
actionProceedText: 'Run',
content: <></>,
onProceedAppend: () => {
setIsSubmittingManifestExecution(true);
api
.put(`/command/run-manifest/${mdetailUuid}`, body)
.catch((apiError) => {
handleAPIError(apiError);
})
.finally(() => {
setIsSubmittingManifestExecution(false);
});
},
titleText: `Are you sure you want to run manifest ${mdetailName}?`,
});
confirmDialogRef.current.setOpen?.call(null, true);
}, },
titleText: `Run install manifest ${mdetailName}`, titleText: `Run install manifest ${mdetailName}`,
}), }),
[ [
mdetailName, runFormUtils,
hostOverviews,
mdetailHosts,
isLoadingManifestDetail,
knownFences, knownFences,
hostOverviews,
knownUpses, knownUpses,
manifestDetail, manifestDetail,
runFormUtils, isLoadingManifestDetail,
mdetailName,
mdetailHosts,
setConfirmDialogProps,
setIsSubmittingManifestExecution,
mdetailUuid,
], ],
); );
@ -446,11 +474,16 @@ const ManageManifestPanel: FC = () => {
<FormDialog <FormDialog
{...runManifestFormDialogProps} {...runManifestFormDialogProps}
disableProceed={isRunFormInvalid} disableProceed={isRunFormInvalid}
loadingAction={isSubmittingManifestExecution}
preActionArea={messageArea} preActionArea={messageArea}
ref={runManifestFormDialogRef} ref={runManifestFormDialogRef}
scrollContent scrollContent
/> />
<ConfirmDialog {...confirmDialogProps} ref={confirmDialogRef} /> <ConfirmDialog
closeOnProceed
{...confirmDialogProps}
ref={confirmDialogRef}
/>
</> </>
); );
}; };

Loading…
Cancel
Save