|
|
@ -1,5 +1,5 @@ |
|
|
|
import { PlayCircle } from '@mui/icons-material'; |
|
|
|
import { PlayCircle } from '@mui/icons-material'; |
|
|
|
import { FC, 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'; |
|
|
|
|
|
|
|
|
|
|
@ -14,9 +14,12 @@ import { |
|
|
|
INPUT_ID_ANVIL_NETWORK_CONFIG_MTU, |
|
|
|
INPUT_ID_ANVIL_NETWORK_CONFIG_MTU, |
|
|
|
INPUT_ID_ANVIL_NETWORK_CONFIG_NTP, |
|
|
|
INPUT_ID_ANVIL_NETWORK_CONFIG_NTP, |
|
|
|
} from './AnvilNetworkConfigInputGroup'; |
|
|
|
} from './AnvilNetworkConfigInputGroup'; |
|
|
|
|
|
|
|
import api from '../../lib/api'; |
|
|
|
import ConfirmDialog from '../ConfirmDialog'; |
|
|
|
import ConfirmDialog from '../ConfirmDialog'; |
|
|
|
|
|
|
|
import EditManifestInputGroup from './EditManifestInputGroup'; |
|
|
|
import FlexBox from '../FlexBox'; |
|
|
|
import FlexBox from '../FlexBox'; |
|
|
|
import FormDialog from '../FormDialog'; |
|
|
|
import FormDialog from '../FormDialog'; |
|
|
|
|
|
|
|
import handleAPIError from '../../lib/handleAPIError'; |
|
|
|
import IconButton from '../IconButton'; |
|
|
|
import IconButton from '../IconButton'; |
|
|
|
import List from '../List'; |
|
|
|
import List from '../List'; |
|
|
|
import { MessageGroupForwardedRefContent } from '../MessageGroup'; |
|
|
|
import { MessageGroupForwardedRefContent } from '../MessageGroup'; |
|
|
@ -26,16 +29,32 @@ import Spinner from '../Spinner'; |
|
|
|
import { BodyText, HeaderText } from '../Text'; |
|
|
|
import { BodyText, HeaderText } from '../Text'; |
|
|
|
import useConfirmDialogProps from '../../hooks/useConfirmDialogProps'; |
|
|
|
import useConfirmDialogProps from '../../hooks/useConfirmDialogProps'; |
|
|
|
import useFormUtils from '../../hooks/useFormUtils'; |
|
|
|
import useFormUtils from '../../hooks/useFormUtils'; |
|
|
|
|
|
|
|
import useIsFirstRender from '../../hooks/useIsFirstRender'; |
|
|
|
|
|
|
|
import useProtectedState from '../../hooks/useProtectedState'; |
|
|
|
|
|
|
|
|
|
|
|
const ManageManifestPanel: FC = () => { |
|
|
|
const ManageManifestPanel: FC = () => { |
|
|
|
|
|
|
|
const isFirstRender = useIsFirstRender(); |
|
|
|
|
|
|
|
|
|
|
|
const confirmDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); |
|
|
|
const confirmDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); |
|
|
|
const formDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); |
|
|
|
const addManifestFormDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); |
|
|
|
|
|
|
|
const editManifestFormDialogRef = useRef<ConfirmDialogForwardedRefContent>( |
|
|
|
|
|
|
|
{}, |
|
|
|
|
|
|
|
); |
|
|
|
const messageGroupRef = useRef<MessageGroupForwardedRefContent>({}); |
|
|
|
const messageGroupRef = useRef<MessageGroupForwardedRefContent>({}); |
|
|
|
|
|
|
|
|
|
|
|
const [confirmDialogProps] = useConfirmDialogProps(); |
|
|
|
const [confirmDialogProps] = useConfirmDialogProps(); |
|
|
|
const [formDialogProps, setFormDialogProps] = useConfirmDialogProps(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [isEditManifests, setIsEditManifests] = useState<boolean>(false); |
|
|
|
const [isEditManifests, setIsEditManifests] = useState<boolean>(false); |
|
|
|
|
|
|
|
const [isLoadingManifestDetail, setIsLoadingManifestDetail] = |
|
|
|
|
|
|
|
useProtectedState<boolean>(true); |
|
|
|
|
|
|
|
const [isLoadingManifestTemplate, setIsLoadingManifestTemplate] = |
|
|
|
|
|
|
|
useState<boolean>(true); |
|
|
|
|
|
|
|
const [manifestDetail, setManifestDetail] = useProtectedState< |
|
|
|
|
|
|
|
APIManifestDetail | undefined |
|
|
|
|
|
|
|
>(undefined); |
|
|
|
|
|
|
|
const [manifestTemplate, setManifestTemplate] = useProtectedState< |
|
|
|
|
|
|
|
APIManifestTemplate | undefined |
|
|
|
|
|
|
|
>(undefined); |
|
|
|
|
|
|
|
|
|
|
|
const { data: manifestOverviews, isLoading: isLoadingManifestOverviews } = |
|
|
|
const { data: manifestOverviews, isLoading: isLoadingManifestOverviews } = |
|
|
|
periodicFetch<APIManifestOverviewList>(`${API_BASE_URL}/manifest`, { |
|
|
|
periodicFetch<APIManifestOverviewList>(`${API_BASE_URL}/manifest`, { |
|
|
@ -55,13 +74,79 @@ const ManageManifestPanel: FC = () => { |
|
|
|
); |
|
|
|
); |
|
|
|
const { isFormInvalid } = formUtils; |
|
|
|
const { isFormInvalid } = formUtils; |
|
|
|
|
|
|
|
|
|
|
|
const addAnvilManifestFormDialogProps = useMemo<ConfirmDialogProps>( |
|
|
|
const addManifestFormDialogProps = useMemo<ConfirmDialogProps>(() => { |
|
|
|
() => ({ |
|
|
|
let domain: string | undefined; |
|
|
|
|
|
|
|
let prefix: string | undefined; |
|
|
|
|
|
|
|
let sequence: number | undefined; |
|
|
|
|
|
|
|
let fences: APIManifestTemplateFenceList | undefined; |
|
|
|
|
|
|
|
let upses: APIManifestTemplateUpsList | undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (manifestTemplate) { |
|
|
|
|
|
|
|
({ domain, fences, prefix, sequence, upses } = manifestTemplate); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
actionProceedText: 'Add', |
|
|
|
actionProceedText: 'Add', |
|
|
|
content: <AddManifestInputGroup formUtils={formUtils} />, |
|
|
|
content: ( |
|
|
|
titleText: 'Add a Anvil! manifest', |
|
|
|
<AddManifestInputGroup |
|
|
|
}), |
|
|
|
formUtils={formUtils} |
|
|
|
[formUtils], |
|
|
|
knownFences={fences} |
|
|
|
|
|
|
|
knownUpses={upses} |
|
|
|
|
|
|
|
previous={{ domain, prefix, sequence }} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
titleText: 'Add an install manifest', |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}, [formUtils, manifestTemplate]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const editManifestFormDialogProps = useMemo<ConfirmDialogProps>(() => { |
|
|
|
|
|
|
|
let fences: APIManifestTemplateFenceList | undefined; |
|
|
|
|
|
|
|
let manifestName: string | undefined; |
|
|
|
|
|
|
|
let upses: APIManifestTemplateUpsList | undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (manifestTemplate) { |
|
|
|
|
|
|
|
({ fences, upses } = manifestTemplate); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (manifestDetail) { |
|
|
|
|
|
|
|
({ name: manifestName } = manifestDetail); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
actionProceedText: 'Edit', |
|
|
|
|
|
|
|
content: ( |
|
|
|
|
|
|
|
<EditManifestInputGroup |
|
|
|
|
|
|
|
formUtils={formUtils} |
|
|
|
|
|
|
|
knownFences={fences} |
|
|
|
|
|
|
|
knownUpses={upses} |
|
|
|
|
|
|
|
previous={manifestDetail} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
loading: isLoadingManifestDetail, |
|
|
|
|
|
|
|
titleText: `Update install manifest ${manifestName}`, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}, [formUtils, isLoadingManifestDetail, manifestDetail, manifestTemplate]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getManifestDetail = useCallback( |
|
|
|
|
|
|
|
(manifestUuid: string, finallyAppend?: () => void) => { |
|
|
|
|
|
|
|
setIsLoadingManifestDetail(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api |
|
|
|
|
|
|
|
.get<APIManifestDetail>(`manifest/${manifestUuid}`) |
|
|
|
|
|
|
|
.then(({ data }) => { |
|
|
|
|
|
|
|
data.uuid = manifestUuid; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setManifestDetail(data); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
|
|
handleAPIError(error); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.finally(() => { |
|
|
|
|
|
|
|
setIsLoadingManifestDetail(false); |
|
|
|
|
|
|
|
finallyAppend?.call(null); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
[setIsLoadingManifestDetail, setManifestDetail], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const listElement = useMemo( |
|
|
|
const listElement = useMemo( |
|
|
@ -74,12 +159,19 @@ const ManageManifestPanel: FC = () => { |
|
|
|
listEmpty="No manifest(s) registered." |
|
|
|
listEmpty="No manifest(s) registered." |
|
|
|
listItems={manifestOverviews} |
|
|
|
listItems={manifestOverviews} |
|
|
|
onAdd={() => { |
|
|
|
onAdd={() => { |
|
|
|
setFormDialogProps(addAnvilManifestFormDialogProps); |
|
|
|
addManifestFormDialogRef.current.setOpen?.call(null, true); |
|
|
|
formDialogRef.current.setOpen?.call(null, true); |
|
|
|
|
|
|
|
}} |
|
|
|
}} |
|
|
|
onEdit={() => { |
|
|
|
onEdit={() => { |
|
|
|
setIsEditManifests((previous) => !previous); |
|
|
|
setIsEditManifests((previous) => !previous); |
|
|
|
}} |
|
|
|
}} |
|
|
|
|
|
|
|
onItemClick={({ manifestName, manifestUUID }) => { |
|
|
|
|
|
|
|
setManifestDetail({ |
|
|
|
|
|
|
|
name: manifestName, |
|
|
|
|
|
|
|
uuid: manifestUUID, |
|
|
|
|
|
|
|
} as APIManifestDetail); |
|
|
|
|
|
|
|
editManifestFormDialogRef.current.setOpen?.call(null, true); |
|
|
|
|
|
|
|
getManifestDetail(manifestUUID); |
|
|
|
|
|
|
|
}} |
|
|
|
renderListItem={(manifestUUID, { manifestName }) => ( |
|
|
|
renderListItem={(manifestUUID, { manifestName }) => ( |
|
|
|
<FlexBox fullWidth row> |
|
|
|
<FlexBox fullWidth row> |
|
|
|
<IconButton disabled={isEditManifests} variant="normal"> |
|
|
|
<IconButton disabled={isEditManifests} variant="normal"> |
|
|
@ -90,19 +182,33 @@ const ManageManifestPanel: FC = () => { |
|
|
|
)} |
|
|
|
)} |
|
|
|
/> |
|
|
|
/> |
|
|
|
), |
|
|
|
), |
|
|
|
[ |
|
|
|
[getManifestDetail, isEditManifests, manifestOverviews, setManifestDetail], |
|
|
|
addAnvilManifestFormDialogProps, |
|
|
|
|
|
|
|
isEditManifests, |
|
|
|
|
|
|
|
manifestOverviews, |
|
|
|
|
|
|
|
setFormDialogProps, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const panelContent = useMemo( |
|
|
|
const panelContent = useMemo( |
|
|
|
() => (isLoadingManifestOverviews ? <Spinner /> : listElement), |
|
|
|
() => |
|
|
|
[isLoadingManifestOverviews, listElement], |
|
|
|
isLoadingManifestTemplate || isLoadingManifestOverviews ? ( |
|
|
|
|
|
|
|
<Spinner /> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
listElement |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
[isLoadingManifestOverviews, isLoadingManifestTemplate, listElement], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isFirstRender) { |
|
|
|
|
|
|
|
api |
|
|
|
|
|
|
|
.get<APIManifestTemplate>('/manifest/template') |
|
|
|
|
|
|
|
.then(({ data }) => { |
|
|
|
|
|
|
|
setManifestTemplate(data); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
|
|
handleAPIError(error); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.finally(() => { |
|
|
|
|
|
|
|
setIsLoadingManifestTemplate(false); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<> |
|
|
|
<> |
|
|
|
<Panel> |
|
|
|
<Panel> |
|
|
@ -112,14 +218,15 @@ const ManageManifestPanel: FC = () => { |
|
|
|
{panelContent} |
|
|
|
{panelContent} |
|
|
|
</Panel> |
|
|
|
</Panel> |
|
|
|
<FormDialog |
|
|
|
<FormDialog |
|
|
|
{...formDialogProps} |
|
|
|
{...addManifestFormDialogProps} |
|
|
|
ref={formDialogRef} |
|
|
|
disableProceed={isFormInvalid} |
|
|
|
proceedButtonProps={{ disabled: isFormInvalid }} |
|
|
|
ref={addManifestFormDialogRef} |
|
|
|
scrollBoxProps={{ |
|
|
|
scrollContent |
|
|
|
paddingRight: '.4em', |
|
|
|
/> |
|
|
|
paddingTop: '.6em', |
|
|
|
<FormDialog |
|
|
|
sx: { overflowX: 'hidden' }, |
|
|
|
{...editManifestFormDialogProps} |
|
|
|
}} |
|
|
|
disableProceed={isFormInvalid} |
|
|
|
|
|
|
|
ref={editManifestFormDialogRef} |
|
|
|
scrollContent |
|
|
|
scrollContent |
|
|
|
/> |
|
|
|
/> |
|
|
|
<ConfirmDialog {...confirmDialogProps} ref={confirmDialogRef} /> |
|
|
|
<ConfirmDialog {...confirmDialogProps} ref={confirmDialogRef} /> |
|
|
|