fix(striker-ui): revise data passing to NetworkInitForm

main
Tsu-ba-me 2 years ago
parent 58c9e05a9b
commit 43f4d89271
  1. 8
      striker-ui/components/NetworkInitForm.tsx
  2. 38
      striker-ui/components/PrepareNetworkForm.tsx
  3. 1
      striker-ui/types/APIHost.d.ts

@ -581,10 +581,10 @@ NetworkForm.defaultProps = {
const NetworkInitForm = forwardRef< const NetworkInitForm = forwardRef<
NetworkInitFormForwardedRefContent, NetworkInitFormForwardedRefContent,
{ {
targetHostUUID?: string; hostDetail?: APIHostDetail;
toggleSubmitDisabled?: (testResult: boolean) => void; toggleSubmitDisabled?: (testResult: boolean) => void;
} }
>(({ targetHostUUID = 'local', toggleSubmitDisabled }, ref) => { >(({ hostDetail: { hostUUID = 'local' } = {}, toggleSubmitDisabled }, ref) => {
const [dragMousePosition, setDragMousePosition] = useState<{ const [dragMousePosition, setDragMousePosition] = useState<{
x: number; x: number;
y: number; y: number;
@ -604,7 +604,7 @@ const NetworkInitForm = forwardRef<
const { data: networkInterfaces = MOCK_NICS, isLoading } = periodicFetch< const { data: networkInterfaces = MOCK_NICS, isLoading } = periodicFetch<
NetworkInterfaceOverviewMetadata[] NetworkInterfaceOverviewMetadata[]
>(`${API_BASE_URL}/network-interface/${targetHostUUID}`, { >(`${API_BASE_URL}/network-interface/${hostUUID}`, {
refreshInterval: 2000, refreshInterval: 2000,
onSuccess: (data) => { onSuccess: (data) => {
const map = data.reduce<NetworkInterfaceInputMap>((result, metadata) => { const map = data.reduce<NetworkInterfaceInputMap>((result, metadata) => {
@ -1385,7 +1385,7 @@ const NetworkInitForm = forwardRef<
}); });
NetworkInitForm.defaultProps = { NetworkInitForm.defaultProps = {
targetHostUUID: 'local', hostDetail: undefined,
toggleSubmitDisabled: undefined, toggleSubmitDisabled: undefined,
}; };
NetworkInitForm.displayName = 'NetworkInitForm'; NetworkInitForm.displayName = 'NetworkInitForm';

@ -24,14 +24,8 @@ const PrepareNetworkForm = withRouter(
}) => { }) => {
const { protect } = useProtect(); const { protect } = useProtect();
const [dataHostName, setDataHostName] = useProtectedState< const [dataHostDetail, setHostDetail] = useProtectedState<
string | undefined APIHostDetail | undefined
>(undefined, protect);
const [dataHostUUID, setDataHostUUID] = useProtectedState<
string | undefined
>(undefined, protect);
const [dataShortHostName, setDataShortHostName] = useProtectedState<
string | undefined
>(undefined, protect); >(undefined, protect);
const [fatalErrorMessage, setFatalErrorMessage] = useProtectedState< const [fatalErrorMessage, setFatalErrorMessage] = useProtectedState<
Message | undefined Message | undefined
@ -41,10 +35,12 @@ const PrepareNetworkForm = withRouter(
const panelHeaderElement = useMemo( const panelHeaderElement = useMemo(
() => ( () => (
<PanelHeader> <PanelHeader>
<HeaderText>Prepare network on {dataShortHostName}</HeaderText> <HeaderText>
Prepare network on {dataHostDetail?.shortHostName}
</HeaderText>
</PanelHeader> </PanelHeader>
), ),
[dataShortHostName], [dataHostDetail],
); );
const contentElement = useMemo(() => { const contentElement = useMemo(() => {
let result; let result;
@ -64,12 +60,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} value={dataHostDetail?.hostName}
/> />
} }
required required
/> />
<NetworkInitForm targetHostUUID={dataHostUUID} /> <NetworkInitForm hostDetail={dataHostDetail} />
<FlexBox row justifyContent="flex-end"> <FlexBox row justifyContent="flex-end">
<ContainedButton>Prepare network</ContainedButton> <ContainedButton>Prepare network</ContainedButton>
</FlexBox> </FlexBox>
@ -79,13 +75,7 @@ const PrepareNetworkForm = withRouter(
} }
return result; return result;
}, [ }, [dataHostDetail, fatalErrorMessage, isLoading, panelHeaderElement]);
dataHostName,
dataHostUUID,
fatalErrorMessage,
isLoading,
panelHeaderElement,
]);
useEffect(() => { useEffect(() => {
if (isReady) { if (isReady) {
@ -98,10 +88,8 @@ const PrepareNetworkForm = withRouter(
: queryHostUUID : queryHostUUID
}`, }`,
) )
.then(({ data: { hostName, hostUUID, shortHostName } }) => { .then(({ data }) => {
setDataHostName(hostName); setHostDetail(data);
setDataHostUUID(hostUUID);
setDataShortHostName(shortHostName);
}) })
.catch((error) => { .catch((error) => {
const { children } = handleAPIError(error); const { children } = handleAPIError(error);
@ -127,10 +115,8 @@ const PrepareNetworkForm = withRouter(
fatalErrorMessage, fatalErrorMessage,
isReady, isReady,
queryHostUUID, queryHostUUID,
setDataHostName,
setDataHostUUID,
setDataShortHostName,
setFatalErrorMessage, setFatalErrorMessage,
setHostDetail,
setIsLoading, setIsLoading,
]); ]);

@ -30,6 +30,7 @@ type APIHostInstallTarget = 'enabled' | 'disabled';
type APIHostDetail = { type APIHostDetail = {
hostName: string; hostName: string;
hostType: string;
hostUUID: string; hostUUID: string;
installTarget: APIHostInstallTarget; installTarget: APIHostInstallTarget;
shortHostName: string; shortHostName: string;

Loading…
Cancel
Save