fix(striker-ui): enable add network by dragging NIC

main
Tsu-ba-me 2 years ago
parent 60a425a92d
commit 6cbff16d28
  1. 92
      striker-ui/pages/init/index.tsx

@ -7,6 +7,7 @@ import {
iconButtonClasses as muiIconButtonClasses, iconButtonClasses as muiIconButtonClasses,
} from '@mui/material'; } from '@mui/material';
import { import {
Add as MUIAddIcon,
Check as MUICheckIcon, Check as MUICheckIcon,
Close as MUICloseIcon, Close as MUICloseIcon,
DragHandle as MUIDragHandleIcon, DragHandle as MUIDragHandleIcon,
@ -297,16 +298,17 @@ const NetworkInterfaceList: FC = () => {
interfaces: NetworkInterfaceOverviewMetadata[], interfaces: NetworkInterfaceOverviewMetadata[],
) => MUIBoxProps['onMouseUp']; ) => MUIBoxProps['onMouseUp'];
let floatingNetworkInterface: JSX.Element = <></>; let floatingNetworkInterface: JSX.Element = <></>;
let handleCreateNetworkMouseUp: MUIBoxProps['onMouseUp'];
let handlePanelMouseMove: MUIBoxProps['onMouseMove']; let handlePanelMouseMove: MUIBoxProps['onMouseMove'];
if (networkInterfaceHeld) { if (networkInterfaceHeld) {
const { networkInterfaceUUID } = networkInterfaceHeld;
createDropMouseUpHandler = createDropMouseUpHandler =
(interfaces: NetworkInterfaceOverviewMetadata[]) => () => { (interfaces: NetworkInterfaceOverviewMetadata[]) => () => {
interfaces.push(networkInterfaceHeld); interfaces.push(networkInterfaceHeld);
networkInterfaceInputMap[ networkInterfaceInputMap[networkInterfaceUUID].isApplied = true;
networkInterfaceHeld.networkInterfaceUUID
].isApplied = true;
}; };
floatingNetworkInterface = ( floatingNetworkInterface = (
@ -321,6 +323,17 @@ const NetworkInterfaceList: FC = () => {
/> />
); );
handleCreateNetworkMouseUp = () => {
networkInputs.push({
ipAddress: '',
name: '',
interfaces: [networkInterfaceHeld],
subnetMask: '',
});
networkInterfaceInputMap[networkInterfaceUUID].isApplied = true;
};
handlePanelMouseMove = ({ nativeEvent: { clientX, clientY } }) => { handlePanelMouseMove = ({ nativeEvent: { clientX, clientY } }) => {
setDragMousePosition({ setDragMousePosition({
x: clientX, x: clientX,
@ -399,24 +412,65 @@ const NetworkInterfaceList: FC = () => {
}, },
}} }}
/> />
{networkInputs.map(({ interfaces, ipAddress, name, subnetMask }) => ( <MUIBox
sx={{
display: 'flex',
flexDirection: 'row',
overflowX: 'auto',
'& > *': {
marginBottom: '1em',
marginTop: '1em',
},
'& > :not(:first-child)': {
marginLeft: '1em',
},
}}
>
<MUIBox
onMouseUp={handleCreateNetworkMouseUp}
sx={{
alignItems: 'center',
borderColor: TEXT,
borderStyle: 'dashed',
borderWidth: '4px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
padding: '.6em',
}}
>
<MUIAddIcon fontSize="large" sx={{ color: GREY }} />
<BodyText
text="Drag interfaces here to create a new network."
sx={{
textAlign: 'center',
}}
/>
</MUIBox>
{networkInputs.map(
({ interfaces, ipAddress, name, subnetMask }, networkIndex) => (
<InnerPanel key={`network-input-${name.toLowerCase()}`}> <InnerPanel key={`network-input-${name.toLowerCase()}`}>
<InnerPanelHeader> <InnerPanelHeader>
<BodyText text={name} /> <OutlinedInputWithLabel label="Network name" value={name} />
</InnerPanelHeader> </InnerPanelHeader>
<MUIBox <MUIBox
sx={{ sx={{
display: 'flex', display: 'flex',
flexDirection: { xs: 'column', md: 'row' }, flexDirection: 'column',
margin: '.6em', margin: '.6em',
'& > *': { '& > :not(:first-child)': {
flexBasis: '50%', marginTop: '1em',
}, },
}} }}
> >
<MUIBox <MUIBox
onMouseUp={createDropMouseUpHandler?.call(null, interfaces)} onMouseUp={createDropMouseUpHandler?.call(
null,
interfaces,
)}
sx={{ sx={{
borderColor: TEXT, borderColor: TEXT,
borderStyle: 'dashed', borderStyle: 'dashed',
@ -446,6 +500,13 @@ const NetworkInterfaceList: FC = () => {
networkInterfaceUUID networkInterfaceUUID
].isApplied = false; ].isApplied = false;
if (
networkIndex > 1 &&
interfaces.length === 0
) {
networkInputs.splice(networkIndex, 1);
}
setNetworkInterfaceInputMap({ setNetworkInterfaceInputMap({
...networkInterfaceInputMap, ...networkInterfaceInputMap,
}); });
@ -455,15 +516,9 @@ const NetworkInterfaceList: FC = () => {
}, },
) )
) : ( ) : (
<BodyText text="Drag interfaces here to add." /> <BodyText text="Drag interfaces here to add to this network." />
)} )}
</MUIBox> </MUIBox>
<MUIBox
sx={{
display: 'flex',
flexDirection: 'column',
}}
>
<OutlinedInputWithLabel <OutlinedInputWithLabel
label="IP address" label="IP address"
value={ipAddress} value={ipAddress}
@ -473,9 +528,10 @@ const NetworkInterfaceList: FC = () => {
value={subnetMask} value={subnetMask}
/> />
</MUIBox> </MUIBox>
</MUIBox>
</InnerPanel> </InnerPanel>
))} ),
)}
</MUIBox>
</MUIBox> </MUIBox>
)} )}
</Panel> </Panel>

Loading…
Cancel
Save