Merge pull request 'Improve UI logic and port name handling in components' (#6) from that into main

Reviewed-on: #6
This commit is contained in:
andrew.ng 2025-11-25 18:44:06 +11:00
commit cd9eeb08b1
4 changed files with 38 additions and 13 deletions

View File

@ -892,7 +892,8 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
className={classes.buttonMenuTool} className={classes.buttonMenuTool}
disabled={isSubmit} disabled={isSubmit}
title={ title={
listPortsSelected.length === listPorts.flat().length listPortsSelected.length === listPorts.flat().length &&
listPorts.flat().length > 0
? "Deselect All" ? "Deselect All"
: "Select All" : "Select All"
} }
@ -908,10 +909,10 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
} }
}} }}
> >
{listPortsSelected.length === listPorts.flat().length {listPortsSelected.length === listPorts.flat().length &&
? "Deselect All" listPorts.flat().length > 0
: "Select All"}{" "} ? "Clear All"
{"(" + listPorts.flat().length + ")"} : "Select All"}
</Button> </Button>
<Button <Button
className={classes.buttonMenuTool} className={classes.buttonMenuTool}

View File

@ -401,7 +401,7 @@ const StationSetting = ({
> >
<Flex justify={"space-between"} gap={"sm"}> <Flex justify={"space-between"} gap={"sm"}>
{/* Station info */} {/* Station info */}
<Box w={"40%"}> <Box w={"30%"}>
<TextInput <TextInput
required required
name="name" name="name"
@ -689,7 +689,7 @@ const StationSetting = ({
</div> </div>
</Box> </Box>
{/* Lines */} {/* Lines */}
<Box w={"60%"}> <Box w={"70%"}>
<Table <Table
verticalSpacing="xs" verticalSpacing="xs"
horizontalSpacing="lg" horizontalSpacing="lg"

View File

@ -351,12 +351,32 @@ const ModalTerminal = ({
const findSwitchPort = (portName: string): SwitchPortsProps | null => { const findSwitchPort = (portName: string): SwitchPortsProps | null => {
if (listPorts?.length > 0) { if (listPorts?.length > 0) {
const port = listPorts.find((el) => el.name === portName); const port = listPorts.find(
(el) => normalizePortName(el.name) === normalizePortName(portName)
);
if (port) return port; if (port) return port;
} }
return null; return null;
}; };
const normalizePortName = (port: string): string => {
if (!port) return "";
// Example inputs: "Fa0/1", "Gi0/0/1", "Fa0/0/2"
const match = port.match(/^([A-Za-z]+)([\d/]+)$/);
if (!match) return port;
const type = match[1]; // Fa, Gi, Te, etc.
const numbers = match[2]; // "0/1" / "0/0/1" / "0/0/2"
// Get the last part after slash
const parts = numbers.split("/");
const last = parts[parts.length - 1];
return `${type?.slice(0, 2)}${last}`;
};
return ( return (
<Box> <Box>
<Modal <Modal
@ -494,11 +514,11 @@ const ModalTerminal = ({
{line?.interface ? ( {line?.interface ? (
findSwitchPort(line?.interface)?.status === "ON" ? ( findSwitchPort(line?.interface)?.status === "ON" ? (
<Text size="sm" ml={"4px"} c={"green"}> <Text size="sm" ml={"4px"} c={"green"}>
Connected ({line?.interface}) Connected ({normalizePortName(line?.interface)})
</Text> </Text>
) : ( ) : (
<Text size="sm" ml={"4px"} c={"red"}> <Text size="sm" ml={"4px"} c={"red"}>
Not Connected ({line?.interface}) Not Connected ({normalizePortName(line?.interface)})
</Text> </Text>
) )
) : ( ) : (

View File

@ -144,8 +144,12 @@ const TerminalCLI: React.FC<TerminalCLIProps> = ({
if (cliOpened) { if (cliOpened) {
setTimeout(() => { setTimeout(() => {
setLoading(false); setLoading(false);
}, 500); }, 100);
if (fitRef.current) fitRef.current?.fit(); if (fitRef.current) fitRef.current?.fit();
} else {
setLoading(true);
setIsInit(false);
terminal.current?.reset();
} }
}, [cliOpened]); }, [cliOpened]);
@ -170,8 +174,8 @@ const TerminalCLI: React.FC<TerminalCLIProps> = ({
useEffect(() => { useEffect(() => {
return () => { return () => {
setLoading(true); // setLoading(true);
setIsInit(false); // setIsInit(false);
// if (terminal.current) { // if (terminal.current) {
// terminal?.current.clear(); // terminal?.current.clear();
// terminal?.current.dispose(); // terminal?.current.dispose();