fix(striker-ui): add NIC to the correct link slot

main
Tsu-ba-me 2 years ago
parent a02e1a76fb
commit 22ba770677
  1. 39
      striker-ui/components/NetworkInitForm.tsx

@ -42,7 +42,7 @@ export type NetworkInterfaceInputMap = Record<
export type NetworkInput = { export type NetworkInput = {
inputUUID: string; inputUUID: string;
interfaces: NetworkInterfaceOverviewMetadata[]; interfaces: (NetworkInterfaceOverviewMetadata | undefined)[];
ipAddress: string; ipAddress: string;
name: string; name: string;
subnetMask: string; subnetMask: string;
@ -126,7 +126,7 @@ const createNetworkInterfaceTableColumns = (
field: '', field: '',
renderCell: ({ row }) => { renderCell: ({ row }) => {
const { isApplied } = const { isApplied } =
networkInterfaceInputMap[row.networkInterfaceUUID] || false; networkInterfaceInputMap[row.networkInterfaceUUID] ?? false;
let cursor = 'grab'; let cursor = 'grab';
let handleMouseDown: MUIBoxProps['onMouseDown'] = (...eventArgs) => { let handleMouseDown: MUIBoxProps['onMouseDown'] = (...eventArgs) => {
@ -241,7 +241,7 @@ const NetworkInitForm: FC = () => {
const map = data.reduce<NetworkInterfaceInputMap>( const map = data.reduce<NetworkInterfaceInputMap>(
(reduceContainer, { networkInterfaceUUID }) => { (reduceContainer, { networkInterfaceUUID }) => {
reduceContainer[networkInterfaceUUID] = reduceContainer[networkInterfaceUUID] =
networkInterfaceInputMap[networkInterfaceUUID] || {}; networkInterfaceInputMap[networkInterfaceUUID] ?? {};
return reduceContainer; return reduceContainer;
}, },
@ -283,7 +283,8 @@ const NetworkInitForm: FC = () => {
}; };
let createDropMouseUpHandler: ( let createDropMouseUpHandler: (
interfaces: NetworkInterfaceOverviewMetadata[], interfaces: (NetworkInterfaceOverviewMetadata | undefined)[],
interfaceIndex: number,
) => MUIBoxProps['onMouseUp']; ) => MUIBoxProps['onMouseUp'];
let floatingNetworkInterface: JSX.Element = <></>; let floatingNetworkInterface: JSX.Element = <></>;
let handleDragAreaMouseLeave: MUIBoxProps['onMouseLeave']; let handleDragAreaMouseLeave: MUIBoxProps['onMouseLeave'];
@ -294,12 +295,24 @@ const NetworkInitForm: FC = () => {
const { networkInterfaceUUID } = networkInterfaceHeld; const { networkInterfaceUUID } = networkInterfaceHeld;
createDropMouseUpHandler = createDropMouseUpHandler =
(interfaces: NetworkInterfaceOverviewMetadata[]) => () => { (
if (interfaces.length < MAX_INTERFACES_PER_NETWORK) { interfaces: (NetworkInterfaceOverviewMetadata | undefined)[],
interfaces.push(networkInterfaceHeld); interfaceIndex: number,
) =>
networkInterfaceInputMap[networkInterfaceUUID].isApplied = true; () => {
const { networkInterfaceUUID: previousNetworkInterfaceUUID } =
interfaces[interfaceIndex] ?? {};
if (
previousNetworkInterfaceUUID &&
previousNetworkInterfaceUUID !== networkInterfaceUUID
) {
networkInterfaceInputMap[previousNetworkInterfaceUUID].isApplied =
false;
} }
interfaces[interfaceIndex] = networkInterfaceHeld;
networkInterfaceInputMap[networkInterfaceUUID].isApplied = true;
}; };
floatingNetworkInterface = ( floatingNetworkInterface = (
@ -339,7 +352,7 @@ const NetworkInitForm: FC = () => {
const map = networkInterfaces.reduce<NetworkInterfaceInputMap>( const map = networkInterfaces.reduce<NetworkInterfaceInputMap>(
(reduceContainer, { networkInterfaceUUID }) => { (reduceContainer, { networkInterfaceUUID }) => {
reduceContainer[networkInterfaceUUID] = reduceContainer[networkInterfaceUUID] =
networkInterfaceInputMap[networkInterfaceUUID] || {}; networkInterfaceInputMap[networkInterfaceUUID] ?? {};
return reduceContainer; return reduceContainer;
}, },
@ -505,7 +518,8 @@ const NetworkInitForm: FC = () => {
const linkName = `Link ${linkNumber}`; const linkName = `Link ${linkNumber}`;
const networkInterfaceIndex = linkNumber - 1; const networkInterfaceIndex = linkNumber - 1;
const networkInterface = interfaces[networkInterfaceIndex]; const networkInterface = interfaces[networkInterfaceIndex];
const { networkInterfaceUUID } = networkInterface || {}; const { networkInterfaceUUID = '' } =
networkInterface ?? {};
return ( return (
<MUIBox <MUIBox
@ -529,6 +543,7 @@ const NetworkInitForm: FC = () => {
onMouseUp={createDropMouseUpHandler?.call( onMouseUp={createDropMouseUpHandler?.call(
null, null,
interfaces, interfaces,
networkInterfaceIndex,
)} )}
> >
{networkInterface ? ( {networkInterface ? (
@ -536,7 +551,7 @@ const NetworkInitForm: FC = () => {
key={`network-interface-${networkInterfaceUUID}`} key={`network-interface-${networkInterfaceUUID}`}
networkInterface={networkInterface} networkInterface={networkInterface}
onClose={() => { onClose={() => {
interfaces.splice(networkInterfaceIndex, 1); interfaces[networkInterfaceIndex] = undefined;
networkInterfaceInputMap[ networkInterfaceInputMap[
networkInterfaceUUID networkInterfaceUUID

Loading…
Cancel
Save