fix(striker-ui): guard against uninit subnodes in network init form

main
Tsu-ba-me 1 year ago
parent 49bd47322d
commit a91d4f6e5e
  1. 24
      striker-ui/components/NetworkInitForm.tsx
  2. 20
      striker-ui/types/APIHost.d.ts

@ -1317,14 +1317,22 @@ const NetworkInitForm = forwardRef<
networks: pNetworks,
} = hostDetail as APIHostDetail;
if (
[pDns, pGateway, pGatewayInterface, pNetworks].some(
(condition) => !condition,
)
) {
return;
}
dnsCSVInputRef.current.setValue?.call(null, pDns);
gatewayInputRef.current.setValue?.call(null, pGateway);
const applied: string[] = [];
const inputs = Object.values(pNetworks).reduce<NetworkInput[]>(
(previous, { ip, link1Uuid, link2Uuid = '', subnetMask, type }) => {
const typeCount =
getNetworkTypeCount(type, { inputs: previous }) + 1;
const inputs = Object.values(pNetworks as APIHostNetworkList).reduce<
NetworkInput[]
>((previous, { ip, link1Uuid, link2Uuid = '', subnetMask, type }) => {
const typeCount = getNetworkTypeCount(type, { inputs: previous }) + 1;
const isRequired = requiredNetworks[type] === typeCount;
const name = `${NETWORK_TYPES[type]} ${typeCount}`;
@ -1346,11 +1354,9 @@ const NetworkInitForm = forwardRef<
});
return previous;
},
[],
);
}, []);
setGatewayInterface(pGatewayInterface);
setGatewayInterface(pGatewayInterface as string);
setNetworkInterfaceInputMap((previous) => {
const result = { ...previous };
@ -1369,11 +1375,9 @@ const NetworkInitForm = forwardRef<
testInputToToggleSubmitDisabled();
}
}, [
createNetwork,
expectHostDetail,
getNetworkTypeCount,
hostDetail,
networkInputs,
networkInterfaceInputMap,
requiredNetworks,
testInputToToggleSubmitDisabled,

@ -39,14 +39,7 @@ type APIHostOverviewList = {
[hostUUID: string]: APIHostOverview;
};
type APIHostDetail = APIHostOverview & {
dns: string;
domain?: string;
gateway: string;
gatewayInterface: string;
installTarget: APIHostInstallTarget;
networks: {
[networkId: string]: {
type APIHostNetwork = {
createBridge?: NumberBoolean;
ip: string;
link1MacToSet: string;
@ -56,7 +49,18 @@ type APIHostDetail = APIHostOverview & {
subnetMask: string;
type: NetworkType;
};
type APIHostNetworkList = {
[networkId: string]: APIHostNetwork;
};
type APIHostDetail = APIHostOverview & {
dns?: string;
domain?: string;
gateway?: string;
gatewayInterface?: string;
installTarget?: APIHostInstallTarget;
networks?: APIHostNetworkList;
organization?: string;
prefix?: string;
sequence?: string;

Loading…
Cancel
Save