From ea7a3e7769384db40a2427ed9587f922d26358ca Mon Sep 17 00:00:00 2001 From: Brey Rivera Date: Mon, 31 Mar 2025 17:02:12 -0400 Subject: [PATCH] Refactor link operations and enhance substring extraction for port formatting --- frontend/src/hooks/useLinkOperations.ts | 1 - frontend/src/lib/helpers.ts | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/useLinkOperations.ts b/frontend/src/hooks/useLinkOperations.ts index 930edec..211450e 100644 --- a/frontend/src/hooks/useLinkOperations.ts +++ b/frontend/src/hooks/useLinkOperations.ts @@ -33,7 +33,6 @@ export function useLinkOperationsBase() { const interconnectDevices = await authenticatedApiClient.getDevicesByType('INTERCONNECT'); // only two devices here so find is okay - // TODO might have to make this more robust return interconnectDevices.data?.find(d => d.name === connectionInfo.interconnectDeviceName); }; diff --git a/frontend/src/lib/helpers.ts b/frontend/src/lib/helpers.ts index 245ce27..b0439c1 100644 --- a/frontend/src/lib/helpers.ts +++ b/frontend/src/lib/helpers.ts @@ -68,10 +68,16 @@ export const getCurvedPath = ( }; export function substringFromFirstNumber(port: string) { - const idx = port.search(/\d/); // find the index of the first number - if (idx !== -1) { - return port.substring(0, idx) + port.substring(idx); // concatenate prefix and the rest + // match up to the first 3 alphabetic characters followed by any numbers + const match = port.match(/^([a-zA-Z]{1,3})\D*(\d.*)$/); + + if (match) { + const prefix = match[1]; // up to the first 3 alphabetic characters + const numbers = match[2]; // all numbers after the prefix + return prefix + numbers; } + + // if no match, return an empty string return ""; }