balibabu
commited on
Commit
·
68707f1
1
Parent(s):
ad0d761
feat: remove dagre and elkjs #918 (#1506)
Browse files### What problem does this PR solve?
feat: remove dagre and elkjs #918
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/package-lock.json +0 -31
- web/package.json +0 -3
- web/src/pages/flow/elk-hooks.ts +0 -35
- web/src/pages/flow/elk-utils.ts +0 -42
- web/src/pages/flow/utils.ts +0 -43
web/package-lock.json
CHANGED
@@ -15,10 +15,8 @@
|
|
15 |
"antd": "^5.12.7",
|
16 |
"axios": "^1.6.3",
|
17 |
"classnames": "^2.5.1",
|
18 |
-
"dagre": "^0.8.5",
|
19 |
"dayjs": "^1.11.10",
|
20 |
"dompurify": "^3.1.6",
|
21 |
-
"elkjs": "^0.9.3",
|
22 |
"eventsource-parser": "^1.1.2",
|
23 |
"human-id": "^4.1.1",
|
24 |
"i18next": "^23.7.16",
|
@@ -52,7 +50,6 @@
|
|
52 |
"@redux-devtools/extension": "^3.3.0",
|
53 |
"@testing-library/jest-dom": "^6.4.5",
|
54 |
"@testing-library/react": "^15.0.7",
|
55 |
-
"@types/dagre": "^0.7.52",
|
56 |
"@types/dompurify": "^3.0.5",
|
57 |
"@types/jest": "^29.5.12",
|
58 |
"@types/lodash": "^4.14.202",
|
@@ -4844,12 +4841,6 @@
|
|
4844 |
"@types/d3-selection": "*"
|
4845 |
}
|
4846 |
},
|
4847 |
-
"node_modules/@types/dagre": {
|
4848 |
-
"version": "0.7.52",
|
4849 |
-
"resolved": "https://registry.npmmirror.com/@types/dagre/-/dagre-0.7.52.tgz",
|
4850 |
-
"integrity": "sha512-XKJdy+OClLk3hketHi9Qg6gTfe1F3y+UFnHxKA2rn9Dw+oXa4Gb378Ztz9HlMgZKSxpPmn4BNVh9wgkpvrK1uw==",
|
4851 |
-
"dev": true
|
4852 |
-
},
|
4853 |
"node_modules/@types/debug": {
|
4854 |
"version": "4.1.12",
|
4855 |
"resolved": "https://registry.npmmirror.com/@types/debug/-/debug-4.1.12.tgz",
|
@@ -10140,15 +10131,6 @@
|
|
10140 |
"node": ">=12"
|
10141 |
}
|
10142 |
},
|
10143 |
-
"node_modules/dagre": {
|
10144 |
-
"version": "0.8.5",
|
10145 |
-
"resolved": "https://registry.npmmirror.com/dagre/-/dagre-0.8.5.tgz",
|
10146 |
-
"integrity": "sha512-/aTqmnRta7x7MCCpExk7HQL2O4owCT2h8NT//9I1OQ9vt29Pa0BzSAkR5lwFUcQ7491yVi/3CXU9jQ5o0Mn2Sw==",
|
10147 |
-
"dependencies": {
|
10148 |
-
"graphlib": "^2.1.8",
|
10149 |
-
"lodash": "^4.17.15"
|
10150 |
-
}
|
10151 |
-
},
|
10152 |
"node_modules/data-uri-to-buffer": {
|
10153 |
"version": "4.0.1",
|
10154 |
"resolved": "https://registry.npmmirror.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
@@ -11114,11 +11096,6 @@
|
|
11114 |
"resolved": "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.767.tgz",
|
11115 |
"integrity": "sha512-nzzHfmQqBss7CE3apQHkHjXW77+8w3ubGCIoEijKCJebPufREaFETgGXWTkh32t259F3Kcq+R8MZdFdOJROgYw=="
|
11116 |
},
|
11117 |
-
"node_modules/elkjs": {
|
11118 |
-
"version": "0.9.3",
|
11119 |
-
"resolved": "https://registry.npmmirror.com/elkjs/-/elkjs-0.9.3.tgz",
|
11120 |
-
"integrity": "sha512-f/ZeWvW/BCXbhGEf1Ujp29EASo/lk1FDnETgNKwJrsVvGZhUWCZyg3xLJjAsxfOmt8KjswHmI5EwCQcPMpOYhQ=="
|
11121 |
-
},
|
11122 |
"node_modules/elliptic": {
|
11123 |
"version": "6.5.5",
|
11124 |
"resolved": "https://registry.npmmirror.com/elliptic/-/elliptic-6.5.5.tgz",
|
@@ -12982,14 +12959,6 @@
|
|
12982 |
"resolved": "https://registry.npmmirror.com/graphemer/-/graphemer-1.4.0.tgz",
|
12983 |
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag=="
|
12984 |
},
|
12985 |
-
"node_modules/graphlib": {
|
12986 |
-
"version": "2.1.8",
|
12987 |
-
"resolved": "https://registry.npmmirror.com/graphlib/-/graphlib-2.1.8.tgz",
|
12988 |
-
"integrity": "sha512-jcLLfkpoVGmH7/InMC/1hIvOPSUh38oJtGhvrOFGzioE1DZ+0YW16RgmOJhHiuWTvGiJQ9Z1Ik43JvkRPRvE+A==",
|
12989 |
-
"dependencies": {
|
12990 |
-
"lodash": "^4.17.15"
|
12991 |
-
}
|
12992 |
-
},
|
12993 |
"node_modules/gzip-size": {
|
12994 |
"version": "6.0.0",
|
12995 |
"resolved": "https://registry.npmmirror.com/gzip-size/-/gzip-size-6.0.0.tgz",
|
|
|
15 |
"antd": "^5.12.7",
|
16 |
"axios": "^1.6.3",
|
17 |
"classnames": "^2.5.1",
|
|
|
18 |
"dayjs": "^1.11.10",
|
19 |
"dompurify": "^3.1.6",
|
|
|
20 |
"eventsource-parser": "^1.1.2",
|
21 |
"human-id": "^4.1.1",
|
22 |
"i18next": "^23.7.16",
|
|
|
50 |
"@redux-devtools/extension": "^3.3.0",
|
51 |
"@testing-library/jest-dom": "^6.4.5",
|
52 |
"@testing-library/react": "^15.0.7",
|
|
|
53 |
"@types/dompurify": "^3.0.5",
|
54 |
"@types/jest": "^29.5.12",
|
55 |
"@types/lodash": "^4.14.202",
|
|
|
4841 |
"@types/d3-selection": "*"
|
4842 |
}
|
4843 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
4844 |
"node_modules/@types/debug": {
|
4845 |
"version": "4.1.12",
|
4846 |
"resolved": "https://registry.npmmirror.com/@types/debug/-/debug-4.1.12.tgz",
|
|
|
10131 |
"node": ">=12"
|
10132 |
}
|
10133 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10134 |
"node_modules/data-uri-to-buffer": {
|
10135 |
"version": "4.0.1",
|
10136 |
"resolved": "https://registry.npmmirror.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
|
|
11096 |
"resolved": "https://registry.npmmirror.com/electron-to-chromium/-/electron-to-chromium-1.4.767.tgz",
|
11097 |
"integrity": "sha512-nzzHfmQqBss7CE3apQHkHjXW77+8w3ubGCIoEijKCJebPufREaFETgGXWTkh32t259F3Kcq+R8MZdFdOJROgYw=="
|
11098 |
},
|
|
|
|
|
|
|
|
|
|
|
11099 |
"node_modules/elliptic": {
|
11100 |
"version": "6.5.5",
|
11101 |
"resolved": "https://registry.npmmirror.com/elliptic/-/elliptic-6.5.5.tgz",
|
|
|
12959 |
"resolved": "https://registry.npmmirror.com/graphemer/-/graphemer-1.4.0.tgz",
|
12960 |
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag=="
|
12961 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12962 |
"node_modules/gzip-size": {
|
12963 |
"version": "6.0.0",
|
12964 |
"resolved": "https://registry.npmmirror.com/gzip-size/-/gzip-size-6.0.0.tgz",
|
web/package.json
CHANGED
@@ -26,10 +26,8 @@
|
|
26 |
"antd": "^5.12.7",
|
27 |
"axios": "^1.6.3",
|
28 |
"classnames": "^2.5.1",
|
29 |
-
"dagre": "^0.8.5",
|
30 |
"dayjs": "^1.11.10",
|
31 |
"dompurify": "^3.1.6",
|
32 |
-
"elkjs": "^0.9.3",
|
33 |
"eventsource-parser": "^1.1.2",
|
34 |
"human-id": "^4.1.1",
|
35 |
"i18next": "^23.7.16",
|
@@ -63,7 +61,6 @@
|
|
63 |
"@redux-devtools/extension": "^3.3.0",
|
64 |
"@testing-library/jest-dom": "^6.4.5",
|
65 |
"@testing-library/react": "^15.0.7",
|
66 |
-
"@types/dagre": "^0.7.52",
|
67 |
"@types/dompurify": "^3.0.5",
|
68 |
"@types/jest": "^29.5.12",
|
69 |
"@types/lodash": "^4.14.202",
|
|
|
26 |
"antd": "^5.12.7",
|
27 |
"axios": "^1.6.3",
|
28 |
"classnames": "^2.5.1",
|
|
|
29 |
"dayjs": "^1.11.10",
|
30 |
"dompurify": "^3.1.6",
|
|
|
31 |
"eventsource-parser": "^1.1.2",
|
32 |
"human-id": "^4.1.1",
|
33 |
"i18next": "^23.7.16",
|
|
|
61 |
"@redux-devtools/extension": "^3.3.0",
|
62 |
"@testing-library/jest-dom": "^6.4.5",
|
63 |
"@testing-library/react": "^15.0.7",
|
|
|
64 |
"@types/dompurify": "^3.0.5",
|
65 |
"@types/jest": "^29.5.12",
|
66 |
"@types/lodash": "^4.14.202",
|
web/src/pages/flow/elk-hooks.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
import { useCallback, useLayoutEffect } from 'react';
|
2 |
-
import { getLayoutedElements } from './elk-utils';
|
3 |
-
|
4 |
-
export const elkOptions = {
|
5 |
-
'elk.algorithm': 'layered',
|
6 |
-
'elk.layered.spacing.nodeNodeBetweenLayers': '100',
|
7 |
-
'elk.spacing.nodeNode': '80',
|
8 |
-
};
|
9 |
-
|
10 |
-
export const useLayoutGraph = (
|
11 |
-
initialNodes,
|
12 |
-
initialEdges,
|
13 |
-
setNodes,
|
14 |
-
setEdges,
|
15 |
-
) => {
|
16 |
-
const onLayout = useCallback(({ direction, useInitialNodes = false }) => {
|
17 |
-
const opts = { 'elk.direction': direction, ...elkOptions };
|
18 |
-
const ns = initialNodes;
|
19 |
-
const es = initialEdges;
|
20 |
-
|
21 |
-
getLayoutedElements(ns, es, opts).then(
|
22 |
-
({ nodes: layoutedNodes, edges: layoutedEdges }) => {
|
23 |
-
setNodes(layoutedNodes);
|
24 |
-
setEdges(layoutedEdges);
|
25 |
-
|
26 |
-
// window.requestAnimationFrame(() => fitView());
|
27 |
-
},
|
28 |
-
);
|
29 |
-
}, []);
|
30 |
-
|
31 |
-
// Calculate the initial layout on mount.
|
32 |
-
useLayoutEffect(() => {
|
33 |
-
onLayout({ direction: 'RIGHT', useInitialNodes: true });
|
34 |
-
}, [onLayout]);
|
35 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/flow/elk-utils.ts
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
import ELK from 'elkjs/lib/elk.bundled.js';
|
2 |
-
import { Edge, Node } from 'reactflow';
|
3 |
-
|
4 |
-
const elk = new ELK();
|
5 |
-
|
6 |
-
export const getLayoutedElements = (
|
7 |
-
nodes: Node[],
|
8 |
-
edges: Edge[],
|
9 |
-
options = {},
|
10 |
-
) => {
|
11 |
-
const isHorizontal = options?.['elk.direction'] === 'RIGHT';
|
12 |
-
const graph = {
|
13 |
-
id: 'root',
|
14 |
-
layoutOptions: options,
|
15 |
-
children: nodes.map((node) => ({
|
16 |
-
...node,
|
17 |
-
// Adjust the target and source handle positions based on the layout
|
18 |
-
// direction.
|
19 |
-
targetPosition: isHorizontal ? 'left' : 'top',
|
20 |
-
sourcePosition: isHorizontal ? 'right' : 'bottom',
|
21 |
-
|
22 |
-
// Hardcode a width and height for elk to use when layouting.
|
23 |
-
width: 150,
|
24 |
-
height: 50,
|
25 |
-
})),
|
26 |
-
edges: edges,
|
27 |
-
};
|
28 |
-
|
29 |
-
return elk
|
30 |
-
.layout(graph)
|
31 |
-
.then((layoutedGraph) => ({
|
32 |
-
nodes: layoutedGraph.children.map((node) => ({
|
33 |
-
...node,
|
34 |
-
// React Flow expects a position property on the node instead of `x`
|
35 |
-
// and `y` fields.
|
36 |
-
position: { x: node.x, y: node.y },
|
37 |
-
})),
|
38 |
-
|
39 |
-
edges: layoutedGraph.edges,
|
40 |
-
}))
|
41 |
-
.catch(console.error);
|
42 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/flow/utils.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import { DSLComponents } from '@/interfaces/database/flow';
|
2 |
import { removeUselessFieldsFromValues } from '@/utils/form';
|
3 |
-
import dagre from 'dagre';
|
4 |
import { humanId } from 'human-id';
|
5 |
import { curry, sample } from 'lodash';
|
6 |
import pipe from 'lodash/fp/pipe';
|
@@ -80,48 +79,6 @@ export const buildNodesAndEdgesFromDSLComponents = (data: DSLComponents) => {
|
|
80 |
return { nodes, edges };
|
81 |
};
|
82 |
|
83 |
-
const dagreGraph = new dagre.graphlib.Graph();
|
84 |
-
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
85 |
-
|
86 |
-
const nodeWidth = 172;
|
87 |
-
const nodeHeight = 36;
|
88 |
-
|
89 |
-
export const getLayoutedElements = (
|
90 |
-
nodes: Node[],
|
91 |
-
edges: Edge[],
|
92 |
-
direction = 'TB',
|
93 |
-
) => {
|
94 |
-
const isHorizontal = direction === 'LR';
|
95 |
-
dagreGraph.setGraph({ rankdir: direction });
|
96 |
-
|
97 |
-
nodes.forEach((node) => {
|
98 |
-
dagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight });
|
99 |
-
});
|
100 |
-
|
101 |
-
edges.forEach((edge) => {
|
102 |
-
dagreGraph.setEdge(edge.source, edge.target);
|
103 |
-
});
|
104 |
-
|
105 |
-
dagre.layout(dagreGraph);
|
106 |
-
|
107 |
-
nodes.forEach((node) => {
|
108 |
-
const nodeWithPosition = dagreGraph.node(node.id);
|
109 |
-
node.targetPosition = isHorizontal ? Position.Left : Position.Top;
|
110 |
-
node.sourcePosition = isHorizontal ? Position.Right : Position.Bottom;
|
111 |
-
|
112 |
-
// We are shifting the dagre node position (anchor=center center) to the top left
|
113 |
-
// so it matches the React Flow node anchor point (top left).
|
114 |
-
node.position = {
|
115 |
-
x: nodeWithPosition.x - nodeWidth / 2,
|
116 |
-
y: nodeWithPosition.y - nodeHeight / 2,
|
117 |
-
};
|
118 |
-
|
119 |
-
return node;
|
120 |
-
});
|
121 |
-
|
122 |
-
return { nodes, edges };
|
123 |
-
};
|
124 |
-
|
125 |
const buildComponentDownstreamOrUpstream = (
|
126 |
edges: Edge[],
|
127 |
nodeId: string,
|
|
|
1 |
import { DSLComponents } from '@/interfaces/database/flow';
|
2 |
import { removeUselessFieldsFromValues } from '@/utils/form';
|
|
|
3 |
import { humanId } from 'human-id';
|
4 |
import { curry, sample } from 'lodash';
|
5 |
import pipe from 'lodash/fp/pipe';
|
|
|
79 |
return { nodes, edges };
|
80 |
};
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
const buildComponentDownstreamOrUpstream = (
|
83 |
edges: Edge[],
|
84 |
nodeId: string,
|