fix(striker-ui): populate partial fields in PrepareNetworkForm

main
Tsu-ba-me 2 years ago
parent e02ffcd95a
commit 6f8a3f93c7
  1. 31
      striker-ui/components/PrepareNetworkForm.tsx

@ -24,6 +24,12 @@ const PrepareNetworkForm = withRouter(
}) => { }) => {
const { protect } = useProtect(); const { protect } = useProtect();
const [dataHostName, setDataHostName] = useProtectedState<
string | undefined
>(undefined, protect);
const [dataHostUUID, setDataHostUUID] = useProtectedState<
string | undefined
>(undefined, protect);
const [dataShortHostName, setDataShortHostName] = useProtectedState< const [dataShortHostName, setDataShortHostName] = useProtectedState<
string | undefined string | undefined
>(undefined, protect); >(undefined, protect);
@ -58,11 +64,12 @@ const PrepareNetworkForm = withRouter(
formControlProps={{ sx: { maxWidth: '20em' } }} formControlProps={{ sx: { maxWidth: '20em' } }}
id="prepare-network-host-name" id="prepare-network-host-name"
label="Host name" label="Host name"
value={dataHostName}
/> />
} }
required required
/> />
<NetworkInitForm /> <NetworkInitForm targetHostUUID={dataHostUUID} />
<FlexBox row justifyContent="flex-end"> <FlexBox row justifyContent="flex-end">
<ContainedButton>Prepare network</ContainedButton> <ContainedButton>Prepare network</ContainedButton>
</FlexBox> </FlexBox>
@ -72,14 +79,28 @@ const PrepareNetworkForm = withRouter(
} }
return result; return result;
}, [fatalErrorMessage, isLoading, panelHeaderElement]); }, [
dataHostName,
dataHostUUID,
fatalErrorMessage,
isLoading,
panelHeaderElement,
]);
useEffect(() => { useEffect(() => {
if (isReady) { if (isReady) {
if (queryHostUUID) { if (queryHostUUID) {
api api
.get<APIHostDetail>(`/host/${queryHostUUID}`) .get<APIHostDetail>(
.then(({ data: { shortHostName } }) => { `/host/${
queryHostUUID instanceof Array
? queryHostUUID[0]
: queryHostUUID
}`,
)
.then(({ data: { hostName, hostUUID, shortHostName } }) => {
setDataHostName(hostName);
setDataHostUUID(hostUUID);
setDataShortHostName(shortHostName); setDataShortHostName(shortHostName);
}) })
.catch((error) => { .catch((error) => {
@ -106,6 +127,8 @@ const PrepareNetworkForm = withRouter(
fatalErrorMessage, fatalErrorMessage,
isReady, isReady,
queryHostUUID, queryHostUUID,
setDataHostName,
setDataHostUUID,
setDataShortHostName, setDataShortHostName,
setFatalErrorMessage, setFatalErrorMessage,
setIsLoading, setIsLoading,

Loading…
Cancel
Save