Skip to content

Commit

Permalink
Merge pull request #2593 from headlamp-k8s/map-edges-fix
Browse files Browse the repository at this point in the history
frontend GraphView: Fix duplicate edges on the map and add unit test
  • Loading branch information
sniok authored Nov 25, 2024
2 parents ef7bee1 + ff5b147 commit 34bc552
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { KubeMetadata } from '../../../lib/k8s/KubeMetadata';
import { KubeObject } from '../../../lib/k8s/KubeObject';
import { groupGraph } from './graphGrouping';
import { GraphEdge, KubeObjectNode } from './graphModel';
import { GraphEdge, GroupNode, KubeObjectNode } from './graphModel';

describe('groupGraph', () => {
const nodes: KubeObjectNode[] = [
Expand Down Expand Up @@ -92,9 +92,11 @@ describe('groupGraph', () => {
{}
);
const instances = groupedGraph.data.nodes.map(node => node.id);
const edgeIds = (groupedGraph.data.nodes[0] as GroupNode).data.edges.map(edge => edge.id);

// Nodes 2 and 4 are connected by the egde and so are grouped together
// group-2 takes has 2 in it because it's the ID of the first node
expect(instances).toEqual(['group-2', '1', '3']);
expect(edgeIds).toEqual(['e2']);
});
});
2 changes: 0 additions & 2 deletions frontend/src/components/resourceMap/graph/graphGrouping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const getConnectedComponents = (nodes: KubeObjectNode[], edges: GraphEdge[]): Gr

const targetNode = graphLookup.getNode(edge.target);
if (targetNode) {
componentEdges.push(edge);
findConnectedComponent(targetNode, componentNodes, componentEdges);
}
});
Expand All @@ -85,7 +84,6 @@ const getConnectedComponents = (nodes: KubeObjectNode[], edges: GraphEdge[]): Gr

const sourceNode = graphLookup.getNode(edge.source);
if (sourceNode) {
componentEdges.push(edge);
findConnectedComponent(sourceNode, componentNodes, componentEdges);
}
});
Expand Down

0 comments on commit 34bc552

Please sign in to comment.