Skip to content

Commit 4bb8447

Browse files
committed
Cleaned up Flow.tsx, Still need to fully convert to TypeScript now that the mapping is working properly.
1 parent 8b8c34d commit 4bb8447

File tree

1 file changed

+16
-45
lines changed

1 file changed

+16
-45
lines changed

src/webview/Flow.tsx

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ const OverviewFlow = () => {
2424
const reactFlowWrapper = useRef<HTMLDivElement>(null);
2525
const initialNodes = [];
2626
const initialEdges = [];
27-
const initialEdge = [];
28-
const elements = [];
29-
// const elementsRef = useRef(elements);
30-
// const edgesRef = useRef(initialEdges)
31-
27+
3228
const [nodes, setNodes, onNodesChange] = useNodesState([]);
3329
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
3430

@@ -37,70 +33,44 @@ const OverviewFlow = () => {
3733
[]
3834
);
3935

40-
// const memoizedOnNodesChange = useCallback(
41-
// (newNodes) => {
42-
// setNodes(newNodes);
43-
// elementsRef.current = newNodes;
44-
// },
45-
// [setNodes]
46-
// );
47-
48-
// const memoizedOnEdgesChange = useCallback(
49-
// (newEdges) => {
50-
// setEdges(newEdges);
51-
// edgesRef.current = newEdges
52-
// },
53-
// [setEdges]
54-
// );
5536

5637
useEffect(() => {
5738
window.addEventListener('message', (e) => {
58-
const msg = e.data; // object containing type prop and value prop
39+
// object containing type prop and value prop
40+
const msg = e.data;
41+
5942
switch (msg.type) {
6043
case 'parsed-data': {
61-
// const results = new FlowBuilder(msg.value);
62-
// results.build(msg.settings)
63-
// setNodes(results.initialNodes);
64-
// setEdges(results.initialEdges);
6544
let data : object | undefined = msg.value;
6645
console.log('data', data)
6746
mappedData(data)
68-
console.log('nodes', elements)
47+
console.log('nodes', initialNodes)
6948
setEdges(initialEdges);
70-
setNodes(elements)
49+
setNodes(initialNodes)
7150
console.log('edges: ', edges);
7251
break;
7352
}
7453
}
7554
});
76-
77-
78-
79-
// memoizedOnEdgesChange(edgesRef.current);
80-
// memoizedOnNodesChange(elementsRef.current);
81-
82-
//Rendering reactFlow
83-
if (reactFlowWrapper.current) {
84-
// Set initial position for the nodes
85-
const initialPosition = { x: 0, y: 0 };
86-
// reactFlowWrapper.current?.fitView(initialPosition);
87-
}
88-
8955
}, []);
9056

57+
58+
// Function that creates Tree Structure
9159
function mappedData (data) {
92-
// create a holder for the heirarchical data (msg.value), data comes in an object of all the Trees
60+
61+
// Create a holder for the heirarchical data (msg.value), data comes in an object of all the Trees
9362
const root : any = d3.hierarchy(data)
9463
console.log('root', root)
95-
9664

9765
//create tree layout and give nodes their positions
9866
const treeLayout = d3.tree().size([800, 500])
9967
treeLayout(root);
10068

69+
// Iterate through each Tree and create a node
10170
root.each((node: any) : void => {
10271

103-
elements.push({
72+
// Create a Node from the current Root and add it to our nodes array
73+
initialNodes.push({
10474
id: node.data.id,
10575
type: 'default',
10676
data: { label: node.data.name },
@@ -116,7 +86,7 @@ const OverviewFlow = () => {
11686
}
11787
});
11888

119-
// figure out how to get edges to connect
89+
// If the current node has a parent, create an edge to show relationship
12090
if (node.data.parent) {
12191
const newEdge = {
12292
id: `${getNonce()}`,
@@ -131,7 +101,8 @@ const OverviewFlow = () => {
131101
const edgeExists = initialEdges.some(
132102
edge => edge.source === newEdge.source && edge.target === newEdge.target
133103
);
134-
104+
105+
// If edge does not exist, add to our edges array
135106
if (!edgeExists) {
136107
initialEdges.push(newEdge)
137108
}

0 commit comments

Comments
 (0)