Skip to content

Commit 5f0c9a5

Browse files
authored
vis: TopologyView: fix tree building so correct info is displayed (#1617)
1 parent 33ac116 commit 5f0c9a5

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

packages/ott-vis-panel/src/components/TreeDisplay.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ const TreeDisplay: React.FC<TreeDisplayProps> = ({
147147
balancerGroupStyle = "stacked",
148148
}) => {
149149
const svgRef = useRef<SVGSVGElement | null>(null);
150-
// const systemTree = useMemo(() => buildFullTree(systemState), [systemState]);
151150
const monolithTrees = buildMonolithTrees(systemState.flatMap(b => b.monoliths)).sort(
152151
(a, b) => d3.ascending(a.region, b.region) || d3.ascending(a.id, b.id)
153152
);

packages/ott-vis-panel/src/components/views/TopologyView.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import "./topology-view.css";
1717
import { useColorProvider } from "colors";
1818
import { useD3Zoom } from "chartutils";
19+
import { dedupeItems } from "aggregate";
1920

2021
/**
2122
* The goal of this component is to show a more accurate topology view from the perspective of actual network connections.
@@ -69,7 +70,11 @@ export const TopologyView: React.FC<TopologyViewProps> = ({
6970
}) => {
7071
const svgRef = useRef<SVGSVGElement | null>(null);
7172
const fullTree = d3.hierarchy(buildFullTree(systemState));
72-
const monolithTrees = pruneTrees(fullTree, "monolith", "room");
73+
const monolithTrees = dedupeItems(
74+
pruneTrees(fullTree, "monolith", "room"),
75+
tree => tree.data.id,
76+
(a, b) => a
77+
);
7378
const balancerTrees = filterTreeGroups(fullTree, ["balancer", "client"]);
7479
const colors = useColorProvider();
7580

packages/ott-vis-panel/src/treeutils.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { dedupeMonoliths } from "aggregate";
21
import * as d3 from "d3";
32
import type { Monolith, Room, SystemState } from "ott-vis/types";
43

@@ -16,30 +15,21 @@ export function buildFullTree(systemState: SystemState): TreeNode {
1615
group: "root",
1716
children: [],
1817
};
19-
const monoliths = systemState.flatMap(balancer => balancer.monoliths);
20-
const monolithNodes: Map<string, TreeNode> = new Map(
21-
buildMonolithTrees(monoliths).map(monolith => {
22-
return [monolith.id, monolith];
23-
})
24-
);
2518

2619
for (const balancer of systemState) {
2720
const balancerNode: TreeNode = {
2821
id: balancer.id,
2922
region: balancer.region,
3023
group: "balancer",
31-
children: [],
24+
children: buildMonolithTrees(balancer.monoliths),
3225
};
3326
tree.children.push(balancerNode);
34-
for (const monolith of balancer.monoliths) {
35-
balancerNode.children.push(monolithNodes.get(monolith.id) as TreeNode);
36-
}
3727
}
3828
return tree;
3929
}
4030

4131
export function buildMonolithTrees(monoliths: Monolith[]): TreeNode[] {
42-
return dedupeMonoliths(monoliths).map(monolith => {
32+
return monoliths.map(monolith => {
4333
const monolithNode: TreeNode = {
4434
id: monolith.id,
4535
region: monolith.region,

0 commit comments

Comments
 (0)