Merge pull request 'Update DrawerControl.tsx' (#18) from that into main

Reviewed-on: #18
This commit is contained in:
andrew.ng 2025-11-27 20:28:35 +11:00
commit 33ba827207
1 changed files with 20 additions and 2 deletions

View File

@ -835,6 +835,24 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
return `${last}`;
};
const convertPortName = (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}`;
};
const changeShowPort = (status: string) => {
localStorage.setItem("show-switch-port", status);
setCheckedActive(status);
@ -847,8 +865,8 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
if (checkedActive === "config") {
const listInterface = stationAPI?.lines
?.filter((el) => el.interface)
.map((el) => el.interface);
return listInterface?.includes(portName);
.map((el) => convertPortName(el.interface || ""));
return listInterface?.includes(convertPortName(portName));
}
};