|
|
@ -1,4 +1,4 @@ |
|
|
|
import { FC, ReactNode, useCallback, useMemo, useRef, useState } from 'react'; |
|
|
|
import { FC, useCallback, useMemo, useRef, useState } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
import API_BASE_URL from '../../lib/consts/API_BASE_URL'; |
|
|
|
import API_BASE_URL from '../../lib/consts/API_BASE_URL'; |
|
|
|
|
|
|
|
|
|
|
@ -163,8 +163,6 @@ const ManageManifestPanel: FC = () => { |
|
|
|
useProtectedState<boolean>(true); |
|
|
|
useProtectedState<boolean>(true); |
|
|
|
const [isLoadingManifestTemplate, setIsLoadingManifestTemplate] = |
|
|
|
const [isLoadingManifestTemplate, setIsLoadingManifestTemplate] = |
|
|
|
useProtectedState<boolean>(true); |
|
|
|
useProtectedState<boolean>(true); |
|
|
|
const [isSubmittingForm, setIsSubmittingForm] = |
|
|
|
|
|
|
|
useProtectedState<boolean>(false); |
|
|
|
|
|
|
|
const [manifestDetail, setManifestDetail] = useProtectedState< |
|
|
|
const [manifestDetail, setManifestDetail] = useProtectedState< |
|
|
|
APIManifestDetail | undefined |
|
|
|
APIManifestDetail | undefined |
|
|
|
>(undefined); |
|
|
|
>(undefined); |
|
|
@ -188,7 +186,7 @@ const ManageManifestPanel: FC = () => { |
|
|
|
], |
|
|
|
], |
|
|
|
messageGroupRef, |
|
|
|
messageGroupRef, |
|
|
|
); |
|
|
|
); |
|
|
|
const { isFormInvalid, setApiMessage } = formUtils; |
|
|
|
const { isFormInvalid, isFormSubmitting, submitForm } = formUtils; |
|
|
|
|
|
|
|
|
|
|
|
const runFormUtils = useFormUtils( |
|
|
|
const runFormUtils = useFormUtils( |
|
|
|
[ |
|
|
|
[ |
|
|
@ -198,7 +196,11 @@ const ManageManifestPanel: FC = () => { |
|
|
|
], |
|
|
|
], |
|
|
|
messageGroupRef, |
|
|
|
messageGroupRef, |
|
|
|
); |
|
|
|
); |
|
|
|
const { isFormInvalid: isRunFormInvalid } = runFormUtils; |
|
|
|
const { |
|
|
|
|
|
|
|
isFormInvalid: isRunFormInvalid, |
|
|
|
|
|
|
|
isFormSubmitting: isRunFormSubmitting, |
|
|
|
|
|
|
|
submitForm: submitRunForm, |
|
|
|
|
|
|
|
} = runFormUtils; |
|
|
|
|
|
|
|
|
|
|
|
const { buildDeleteDialogProps, checks, getCheck, hasChecks, setCheck } = |
|
|
|
const { buildDeleteDialogProps, checks, getCheck, hasChecks, setCheck } = |
|
|
|
useChecklist({ |
|
|
|
useChecklist({ |
|
|
@ -224,40 +226,6 @@ const ManageManifestPanel: FC = () => { |
|
|
|
[manifestTemplate], |
|
|
|
[manifestTemplate], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const submitForm = useCallback( |
|
|
|
|
|
|
|
({ |
|
|
|
|
|
|
|
body, |
|
|
|
|
|
|
|
getErrorMsg, |
|
|
|
|
|
|
|
method, |
|
|
|
|
|
|
|
successMsg, |
|
|
|
|
|
|
|
url, |
|
|
|
|
|
|
|
}: { |
|
|
|
|
|
|
|
body: Record<string, unknown>; |
|
|
|
|
|
|
|
getErrorMsg: (parentMsg: ReactNode) => ReactNode; |
|
|
|
|
|
|
|
method: 'delete' | 'post' | 'put'; |
|
|
|
|
|
|
|
successMsg?: ReactNode; |
|
|
|
|
|
|
|
url: string; |
|
|
|
|
|
|
|
}) => { |
|
|
|
|
|
|
|
setIsSubmittingForm(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api |
|
|
|
|
|
|
|
.request({ data: body, method, url }) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
setApiMessage({ children: successMsg, type: 'info' }); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((apiError) => { |
|
|
|
|
|
|
|
const emsg = handleAPIError(apiError); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emsg.children = getErrorMsg(emsg.children); |
|
|
|
|
|
|
|
setApiMessage(emsg); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.finally(() => { |
|
|
|
|
|
|
|
setIsSubmittingForm(false); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
[setApiMessage, setIsSubmittingForm], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const addManifestFormDialogProps = useMemo<ConfirmDialogProps>( |
|
|
|
const addManifestFormDialogProps = useMemo<ConfirmDialogProps>( |
|
|
|
() => ({ |
|
|
|
() => ({ |
|
|
|
actionProceedText: 'Add', |
|
|
|
actionProceedText: 'Add', |
|
|
@ -378,7 +346,7 @@ const ManageManifestPanel: FC = () => { |
|
|
|
actionProceedText: 'Run', |
|
|
|
actionProceedText: 'Run', |
|
|
|
content: <FormSummary entries={body} hasPassword />, |
|
|
|
content: <FormSummary entries={body} hasPassword />, |
|
|
|
onProceedAppend: () => { |
|
|
|
onProceedAppend: () => { |
|
|
|
submitForm({ |
|
|
|
submitRunForm({ |
|
|
|
body, |
|
|
|
body, |
|
|
|
getErrorMsg: (parentMsg) => ( |
|
|
|
getErrorMsg: (parentMsg) => ( |
|
|
|
<>Failed to run install manifest. {parentMsg}</> |
|
|
|
<>Failed to run install manifest. {parentMsg}</> |
|
|
@ -405,7 +373,7 @@ const ManageManifestPanel: FC = () => { |
|
|
|
mdetailName, |
|
|
|
mdetailName, |
|
|
|
mdetailHosts, |
|
|
|
mdetailHosts, |
|
|
|
setConfirmDialogProps, |
|
|
|
setConfirmDialogProps, |
|
|
|
submitForm, |
|
|
|
submitRunForm, |
|
|
|
mdetailUuid, |
|
|
|
mdetailUuid, |
|
|
|
], |
|
|
|
], |
|
|
|
); |
|
|
|
); |
|
|
@ -582,7 +550,7 @@ const ManageManifestPanel: FC = () => { |
|
|
|
<FormDialog |
|
|
|
<FormDialog |
|
|
|
{...addManifestFormDialogProps} |
|
|
|
{...addManifestFormDialogProps} |
|
|
|
disableProceed={isFormInvalid} |
|
|
|
disableProceed={isFormInvalid} |
|
|
|
loadingAction={isSubmittingForm} |
|
|
|
loadingAction={isFormSubmitting} |
|
|
|
preActionArea={messageArea} |
|
|
|
preActionArea={messageArea} |
|
|
|
ref={addManifestFormDialogRef} |
|
|
|
ref={addManifestFormDialogRef} |
|
|
|
scrollContent |
|
|
|
scrollContent |
|
|
@ -591,7 +559,7 @@ const ManageManifestPanel: FC = () => { |
|
|
|
<FormDialog |
|
|
|
<FormDialog |
|
|
|
{...editManifestFormDialogProps} |
|
|
|
{...editManifestFormDialogProps} |
|
|
|
disableProceed={isFormInvalid} |
|
|
|
disableProceed={isFormInvalid} |
|
|
|
loadingAction={isSubmittingForm} |
|
|
|
loadingAction={isFormSubmitting} |
|
|
|
preActionArea={messageArea} |
|
|
|
preActionArea={messageArea} |
|
|
|
ref={editManifestFormDialogRef} |
|
|
|
ref={editManifestFormDialogRef} |
|
|
|
scrollContent |
|
|
|
scrollContent |
|
|
@ -600,7 +568,7 @@ const ManageManifestPanel: FC = () => { |
|
|
|
<FormDialog |
|
|
|
<FormDialog |
|
|
|
{...runManifestFormDialogProps} |
|
|
|
{...runManifestFormDialogProps} |
|
|
|
disableProceed={isRunFormInvalid} |
|
|
|
disableProceed={isRunFormInvalid} |
|
|
|
loadingAction={isSubmittingForm} |
|
|
|
loadingAction={isRunFormSubmitting} |
|
|
|
preActionArea={messageArea} |
|
|
|
preActionArea={messageArea} |
|
|
|
ref={runManifestFormDialogRef} |
|
|
|
ref={runManifestFormDialogRef} |
|
|
|
scrollContent |
|
|
|
scrollContent |
|
|
|