fix(striker-ui): extend iface drag begin to whole row

main
Tsu-ba-me 2 years ago
parent df70346824
commit f6cde6a903
  1. 80
      striker-ui/components/NetworkInitForm.tsx

@ -72,6 +72,7 @@ type NetworkInput = {
type NetworkInterfaceInputMap = Record< type NetworkInterfaceInputMap = Record<
string, string,
{ {
metadata: NetworkInterfaceOverviewMetadata;
isApplied?: boolean; isApplied?: boolean;
} }
>; >;
@ -130,6 +131,11 @@ const MOCK_NICS: NetworkInterfaceOverviewMetadata[] = [
}, },
]; ];
const CLASS_PREFIX = 'NetworkInitForm';
const CLASSES = {
ifaceNotApplied: `${CLASS_PREFIX}-network-interface-not-applied`,
};
const NETWORK_TYPES: Record<string, string> = { const NETWORK_TYPES: Record<string, string> = {
bcn: 'Back-Channel Network', bcn: 'Back-Channel Network',
ifn: 'Internet-Facing Network', ifn: 'Internet-Facing Network',
@ -574,19 +580,17 @@ const NetworkInitForm = forwardRef<
>(`${API_BASE_URL}/network-interface`, { >(`${API_BASE_URL}/network-interface`, {
refreshInterval: 2000, refreshInterval: 2000,
onSuccess: (data) => { onSuccess: (data) => {
if (data instanceof Array) { const map = data.reduce<NetworkInterfaceInputMap>((result, metadata) => {
const map = data.reduce<NetworkInterfaceInputMap>( const { networkInterfaceUUID } = metadata;
(reduceContainer, { networkInterfaceUUID }) => {
reduceContainer[networkInterfaceUUID] =
networkInterfaceInputMap[networkInterfaceUUID] ?? {};
return reduceContainer; result[networkInterfaceUUID] = networkInterfaceInputMap[
}, networkInterfaceUUID
{}, ] ?? { metadata };
);
return result;
}, {});
setNetworkInterfaceInputMap(map); setNetworkInterfaceInputMap(map);
}
}, },
}); });
@ -972,7 +976,8 @@ const NetworkInitForm = forwardRef<
}; };
}, [networkInterfaceHeld, networkInterfaceInputMap]); }, [networkInterfaceHeld, networkInterfaceInputMap]);
const dragAreaDraggingSx: MUIBoxProps['sx'] = useMemo( const dragAreaDraggingSx: MUIBoxProps['sx'] = useMemo(
() => (networkInterfaceHeld ? { cursor: 'grabbing' } : {}), () =>
networkInterfaceHeld ? { cursor: 'grabbing', userSelect: 'none' } : {},
[networkInterfaceHeld], [networkInterfaceHeld],
); );
const floatingNetworkInterface: JSX.Element = useMemo(() => { const floatingNetworkInterface: JSX.Element = useMemo(() => {
@ -1030,11 +1035,14 @@ const NetworkInitForm = forwardRef<
useEffect(() => { useEffect(() => {
const map = networkInterfaces.reduce<NetworkInterfaceInputMap>( const map = networkInterfaces.reduce<NetworkInterfaceInputMap>(
(reduceContainer, { networkInterfaceUUID }) => { (result, metadata) => {
reduceContainer[networkInterfaceUUID] = const { networkInterfaceUUID } = metadata;
networkInterfaceInputMap[networkInterfaceUUID] ?? {};
return reduceContainer; result[networkInterfaceUUID] = networkInterfaceInputMap[
networkInterfaceUUID
] ?? { metadata };
return result;
}, },
{}, {},
); );
@ -1110,8 +1118,42 @@ const NetworkInitForm = forwardRef<
columns={createNetworkInterfaceTableColumns((row) => { columns={createNetworkInterfaceTableColumns((row) => {
setNetworkInterfaceHeld(row); setNetworkInterfaceHeld(row);
}, networkInterfaceInputMap)} }, networkInterfaceInputMap)}
componentsProps={{
row: {
onMouseDown: ({
target: {
parentElement: {
dataset: { id: networkInterfaceUUID = undefined } = {},
} = {},
} = {},
}: {
target?: { parentElement?: { dataset?: { id?: string } } };
}) => {
if (networkInterfaceUUID) {
const { isApplied, metadata } =
networkInterfaceInputMap[networkInterfaceUUID];
if (!isApplied) {
setNetworkInterfaceHeld(metadata);
}
}
},
},
}}
disableColumnMenu disableColumnMenu
disableSelectionOnClick disableSelectionOnClick
getRowClassName={({ row: { networkInterfaceUUID } }) => {
const { isApplied } =
networkInterfaceInputMap[networkInterfaceUUID] ?? false;
let className = '';
if (!isApplied) {
className += ` ${CLASSES.ifaceNotApplied}`;
}
return className;
}}
getRowId={({ networkInterfaceUUID }) => networkInterfaceUUID} getRowId={({ networkInterfaceUUID }) => networkInterfaceUUID}
hideFooter hideFooter
rows={networkInterfaces} rows={networkInterfaces}
@ -1125,6 +1167,14 @@ const NetworkInitForm = forwardRef<
[`& .${muiGridClasses.cell}:focus`]: { [`& .${muiGridClasses.cell}:focus`]: {
outline: 'none', outline: 'none',
}, },
[`& .${muiGridClasses.row}.${CLASSES.ifaceNotApplied}:hover`]: {
cursor: 'grab',
[`& .${muiGridClasses.cell} p`]: {
cursor: 'auto',
},
},
}} }}
/> />
<FlexBox <FlexBox

Loading…
Cancel
Save