From 60a425a92d009df786520949bc1d7509ad78831c Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 18 Jul 2022 15:20:04 -0400 Subject: [PATCH] fix(striker-ui): add close button to BriefNetworkInterface --- striker-ui/pages/init/index.tsx | 64 +++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/striker-ui/pages/init/index.tsx b/striker-ui/pages/init/index.tsx index d6ea2888..a959c9e0 100644 --- a/striker-ui/pages/init/index.tsx +++ b/striker-ui/pages/init/index.tsx @@ -2,10 +2,13 @@ import { FC, useEffect, useState } from 'react'; import { Box as MUIBox, BoxProps as MUIBoxProps, + IconButton as MUIIconButton, + IconButtonProps as MUIIconButtonProps, iconButtonClasses as muiIconButtonClasses, } from '@mui/material'; import { Check as MUICheckIcon, + Close as MUICloseIcon, DragHandle as MUIDragHandleIcon, } from '@mui/icons-material'; import { @@ -90,12 +93,25 @@ const DataGridCellText: FC = ({ /> ); +type BriefNetworkInterfaceOptionalProps = { + onClose?: MUIIconButtonProps['onClick']; +}; + +const BRIEF_NETWORK_INTERFACE_DEFAULT_PROPS: Required< + Omit +> & + Pick = { + onClose: undefined, +}; + const BriefNetworkInterface: FC< - MUIBoxProps & { - networkInterface: NetworkInterfaceOverviewMetadata; - } + MUIBoxProps & + BriefNetworkInterfaceOptionalProps & { + networkInterface: NetworkInterfaceOverviewMetadata; + } > = ({ networkInterface: { networkInterfaceName, networkInterfaceState }, + onClose, sx: rootSx, ...restRootProps }) => ( @@ -118,9 +134,16 @@ const BriefNetworkInterface: FC< sx={{ height: 'auto' }} /> + {onClose && ( + + + + )} ); +BriefNetworkInterface.defaultProps = BRIEF_NETWORK_INTERFACE_DEFAULT_PROPS; + const createNetworkInterfaceTableColumns = ( handleDragMouseDown: ( row: NetworkInterfaceOverviewMetadata, @@ -376,12 +399,6 @@ const NetworkInterfaceList: FC = () => { }, }} /> - - {networkInputs.map(({ interfaces, ipAddress, name, subnetMask }) => ( @@ -414,12 +431,29 @@ const NetworkInterfaceList: FC = () => { }} > {interfaces.length > 0 ? ( - interfaces.map((networkInterface) => ( - - )) + interfaces.map( + (networkInterface, networkInterfaceIndex) => { + const { networkInterfaceUUID } = networkInterface; + + return ( + { + interfaces.splice(networkInterfaceIndex, 1); + + networkInterfaceInputMap[ + networkInterfaceUUID + ].isApplied = false; + + setNetworkInterfaceInputMap({ + ...networkInterfaceInputMap, + }); + }} + /> + ); + }, + ) ) : ( )}