Skip to content

Commit

Permalink
updating for rack location matching
Browse files Browse the repository at this point in the history
  • Loading branch information
thediymaker committed Feb 22, 2025
1 parent 10fd1cf commit 68a34ba
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions components/grouped-nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,28 @@ const StatusBadge = ({
};

const isNodeInAnyRack = (nodeName: string, config: NodeConfig): boolean => {
console.log("Checking node:", nodeName);

return Object.values(config).some(({ nodes: groupNodes }) =>
groupNodes.some((rackNodeRange) => {
console.log("Comparing with rack range:", rackNodeRange);

if (!rackNodeRange.includes("-")) {
return nodeName === rackNodeRange; // Direct match
const match = nodeName === rackNodeRange;
if (match) console.log(`Direct match found: ${nodeName}`);
return match;
}

const rangeParts = rackNodeRange.split("-");
if (rangeParts.length !== 2) {
return nodeName === rackNodeRange;
}

const [start, end] = rangeParts;
if (rangeParts.length < 2) return nodeName === rackNodeRange;

const startMatch = start.match(/^([a-zA-Z0-9_\-]+?)(\d+)$/);
const endMatch = end.match(/^(\d+)$/);
const startMatch = rangeParts[0].match(/^([a-zA-Z0-9_\-]+?)(\d+)$/);
const endMatch = rangeParts[1].match(/^(\d+)$/);

if (!startMatch || !endMatch) return nodeName === rackNodeRange;
if (!startMatch || !endMatch) {
console.log(`Skipping invalid range format: ${rackNodeRange}`);
return nodeName === rackNodeRange;
}

const [, startPrefix, startNumStr] = startMatch;
const startNum = parseInt(startNumStr);
Expand All @@ -137,9 +142,16 @@ const isNodeInAnyRack = (nodeName: string, config: NodeConfig): boolean => {
const [, nodePrefix, nodeNumStr] = nodeMatch;
const nodeNum = parseInt(nodeNumStr);

return (
nodePrefix === startPrefix && nodeNum >= startNum && nodeNum <= endNum
console.log(
`Matching node ${nodeName}: Prefix=${nodePrefix}, Num=${nodeNum} against range Prefix=${startPrefix}, Start=${startNum}, End=${endNum}`
);

const match =
nodePrefix === startPrefix && nodeNum >= startNum && nodeNum <= endNum;
if (match)
console.log(`Match found: ${nodeName} in range ${rackNodeRange}`);

return match;
})
);
};
Expand Down

0 comments on commit 68a34ba

Please # to comment.