fix(striker-ui): set interfaces as applied during read from host detail in network config

main
Tsu-ba-me 1 year ago
parent 84620d9542
commit 483f8db9ed
  1. 36
      striker-ui/components/NetworkInitForm.tsx

@ -602,8 +602,6 @@ const NetworkInitForm = forwardRef<
[hostType], [hostType],
); );
const [isReadHostDetail, setIsReadHostDetail] = useState<boolean>(false);
const [dragMousePosition, setDragMousePosition] = useState<{ const [dragMousePosition, setDragMousePosition] = useState<{
x: number; x: number;
y: number; y: number;
@ -618,8 +616,11 @@ const NetworkInitForm = forwardRef<
>(); >();
const [gatewayInterface, setGatewayInterface] = useState<string>(''); const [gatewayInterface, setGatewayInterface] = useState<string>('');
const gatewayInputRef = useRef<InputForwardedRefContent<'string'>>({});
const dnsCSVInputRef = useRef<InputForwardedRefContent<'string'>>({}); const dnsCSVInputRef = useRef<InputForwardedRefContent<'string'>>({});
const gatewayInputRef = useRef<InputForwardedRefContent<'string'>>({});
/** Avoid state here to prevent triggering multiple renders when reading
* host detail. */
const isReadHostDetailRef = useRef<boolean>(false);
const messageGroupRef = useRef<MessageGroupForwardedRefContent>({}); const messageGroupRef = useRef<MessageGroupForwardedRefContent>({});
const { const {
@ -1181,16 +1182,19 @@ const NetworkInitForm = forwardRef<
Object.keys(networkInterfaceInputMap).length > 0 && Object.keys(networkInterfaceInputMap).length > 0 &&
expectHostDetail && expectHostDetail &&
hostDetail && hostDetail &&
!isReadHostDetail !isReadHostDetailRef.current
) { ) {
setNetworkInputs( isReadHostDetailRef.current = true;
Object.values(previousNetworks).reduce<NetworkInput[]>(
const applied: string[] = [];
const inputs = Object.values(previousNetworks).reduce<NetworkInput[]>(
(previous, { ip, link1Uuid, link2Uuid = '', subnetMask, type }) => { (previous, { ip, link1Uuid, link2Uuid = '', subnetMask, type }) => {
const name = NETWORK_TYPES[type]; const name = NETWORK_TYPES[type];
const typeCount = const typeCount = getNetworkTypeCount(type, { inputs: previous }) + 1;
getNetworkTypeCount(type, { inputs: previous }) + 1;
const isRequired = requiredNetworks[type] === typeCount; const isRequired = requiredNetworks[type] === typeCount;
applied.push(link1Uuid, link2Uuid);
previous.push({ previous.push({
inputUUID: uuidv4(), inputUUID: uuidv4(),
interfaces: [ interfaces: [
@ -1208,17 +1212,27 @@ const NetworkInitForm = forwardRef<
return previous; return previous;
}, },
[], [],
),
); );
setIsReadHostDetail(true); setNetworkInterfaceInputMap((previous) => {
const result = { ...previous };
applied.forEach((uuid) => {
if (result[uuid]) {
result[uuid].isApplied = true;
}
});
return result;
});
setNetworkInputs(inputs);
} }
}, [ }, [
createNetwork, createNetwork,
expectHostDetail, expectHostDetail,
getNetworkTypeCount, getNetworkTypeCount,
hostDetail, hostDetail,
isReadHostDetail,
networkInputs, networkInputs,
networkInterfaceInputMap, networkInterfaceInputMap,
previousNetworks, previousNetworks,

Loading…
Cancel
Save