Skip to content

Commit cd52c2c

Browse files
changing to Map from Record
1 parent 10e657f commit cd52c2c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/components/Graphs/graphUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ export const generateColorMap = (items: NodeData[], colorBy: string): Record<str
4646
? Array.from(new Set(items.map((i) => i.providerType).filter(Boolean)))
4747
: Array.from(new Set(items.map((i) => i.providerConfigName).filter(Boolean)));
4848

49-
const map: Record<string, string> = {};
49+
const map = new Map<string, string>();
5050
keys.forEach((key, i) => {
51-
map[key] = colors[i % colors.length];
51+
map.set(key, colors[i % colors.length]);
5252
});
53-
return map;
53+
54+
return Object.fromEntries(map);
5455
};
5556

5657
export function extractRefs(item: ManagedResourceItem) {

src/components/Graphs/useGraph.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function buildGraph(
1919
dagreGraph.setDefaultEdgeLabel(() => ({}));
2020
dagreGraph.setGraph({ rankdir: 'TB' });
2121

22-
const nodeMap: Record<string, Node<NodeData>> = {};
22+
const nodeMap = new Map<string, Node<NodeData>>();
2323
treeData.forEach((n) => {
2424
const colorKey = colorBy === 'source' ? n.providerType : n.providerConfigName;
2525
const node: Node<NodeData> = {
@@ -39,7 +39,7 @@ function buildGraph(
3939
sourcePosition: Position.Bottom,
4040
targetPosition: Position.Top,
4141
};
42-
nodeMap[n.id] = node;
42+
nodeMap.set(n.id, node);
4343
dagreGraph.setNode(n.id, { width: nodeWidth, height: nodeHeight });
4444
});
4545

@@ -55,7 +55,7 @@ function buildGraph(
5555
});
5656
}
5757
n.extraRefs?.forEach((refId) => {
58-
if (nodeMap[refId]) {
58+
if (nodeMap.has(refId)) {
5959
dagreGraph.setEdge(refId, n.id);
6060
edgeList.push({
6161
id: `e-${refId}-${n.id}`,
@@ -68,12 +68,12 @@ function buildGraph(
6868
});
6969

7070
dagre.layout(dagreGraph);
71-
Object.values(nodeMap).forEach((node) => {
71+
nodeMap.forEach((node) => {
7272
const pos = dagreGraph.node(node.id);
7373
node.position = { x: pos.x - nodeWidth / 2, y: pos.y - nodeHeight / 2 };
7474
});
7575

76-
return { nodes: Object.values(nodeMap), edges: edgeList };
76+
return { nodes: Array.from(nodeMap.values()), edges: edgeList };
7777
}
7878

7979
export function useGraph(colorBy: ColorBy, onYamlClick: (item: ManagedResourceItem) => void) {

0 commit comments

Comments
 (0)