Skip to content

Commit ac7dd20

Browse files
committed
Refactor NetworkNode and NetworkView components to streamline node selection logic and remove unused well-known ports
1 parent 7bb83d2 commit ac7dd20

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

frontend/src/components/NetworkNode.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ const WELL_KNOWN_PORTS: Record<number, string> = {
3737
53: 'DNS',
3838
80: 'HTTP',
3939
443: 'HTTPS',
40-
3389: 'RDP',
41-
5432: 'PostgreSQL',
42-
3306: 'MySQL',
43-
6379: 'Redis',
44-
8080: 'HTTP-Alt',
45-
8443: 'HTTPS-Alt',
46-
9090: 'Prometheus',
47-
27017: 'MongoDB',
4840
};
4941

5042
const NetworkNode = memo<NodeProps>(({ data, selected }) => {

frontend/src/pages/NetworkView.tsx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,18 +1424,44 @@ const NetworkView: React.FC = () => {
14241424
setSelectedLink(null)
14251425
}}
14261426
onSelectLog={(logEntry) => {
1427-
// Highlight the corresponding nodes in the graph
1428-
const srcNode = nodes.find(n =>
1427+
// First, find the source and destination nodes
1428+
const srcNode = nodes.find(n =>
14291429
n.ips?.includes(logEntry.srcIP) || n.ip === logEntry.srcIP || n.displayName === logEntry.srcDevice
14301430
)
1431-
const dstNode = nodes.find(n =>
1431+
const dstNode = nodes.find(n =>
14321432
n.ips?.includes(logEntry.dstIP) || n.ip === logEntry.dstIP || n.displayName === logEntry.dstDevice
14331433
)
1434-
1435-
if (srcNode) {
1434+
1435+
// Try to find the corresponding link/edge between these nodes
1436+
if (srcNode && dstNode) {
1437+
const matchingLink = links.find(link => {
1438+
const linkSourceId = typeof link.source === 'string' ? link.source : link.source.id
1439+
const linkTargetId = typeof link.target === 'string' ? link.target : link.target.id
1440+
1441+
// Check both directions (src->dst or dst->src)
1442+
return (
1443+
(linkSourceId === srcNode.id && linkTargetId === dstNode.id) ||
1444+
(linkSourceId === dstNode.id && linkTargetId === srcNode.id)
1445+
)
1446+
})
1447+
1448+
if (matchingLink) {
1449+
// Select the link/edge instead of a node
1450+
setSelectedLink(matchingLink)
1451+
setSelectedNode(null)
1452+
} else {
1453+
// If no link found, fall back to selecting the source node
1454+
setSelectedNode(srcNode)
1455+
setSelectedLink(null)
1456+
}
1457+
} else if (srcNode) {
1458+
// Only source node found
14361459
setSelectedNode(srcNode)
1460+
setSelectedLink(null)
14371461
} else if (dstNode) {
1462+
// Only destination node found
14381463
setSelectedNode(dstNode)
1464+
setSelectedLink(null)
14391465
}
14401466
}}
14411467
/>

0 commit comments

Comments
 (0)