Create App.js
Browse files- src/App.js +62 -0
src/App.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useCallback } from 'react';
|
| 2 |
+
import ReactFlow, {
|
| 3 |
+
addEdge,
|
| 4 |
+
MiniMap,
|
| 5 |
+
Controls,
|
| 6 |
+
Background,
|
| 7 |
+
useNodesState,
|
| 8 |
+
useEdgesState,
|
| 9 |
+
} from 'reactflow';
|
| 10 |
+
|
| 11 |
+
import { nodes as initialNodes, edges as initialEdges } from './initial-elements';
|
| 12 |
+
import CustomNode from './CustomNode';
|
| 13 |
+
|
| 14 |
+
import 'reactflow/dist/style.css';
|
| 15 |
+
import './overview.css';
|
| 16 |
+
|
| 17 |
+
const nodeTypes = {
|
| 18 |
+
custom: CustomNode,
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
const minimapStyle = {
|
| 22 |
+
height: 120,
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
const onInit = (reactFlowInstance) => console.log('flow loaded:', reactFlowInstance);
|
| 26 |
+
|
| 27 |
+
const OverviewFlow = () => {
|
| 28 |
+
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
|
| 29 |
+
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
| 30 |
+
const onConnect = useCallback((params) => setEdges((eds) => addEdge(params, eds)), []);
|
| 31 |
+
|
| 32 |
+
// we are using a bit of a shortcut here to adjust the edge type
|
| 33 |
+
// this could also be done with a custom edge for example
|
| 34 |
+
const edgesWithUpdatedTypes = edges.map((edge) => {
|
| 35 |
+
if (edge.sourceHandle) {
|
| 36 |
+
const edgeType = nodes.find((node) => node.type === 'custom').data.selects[edge.sourceHandle];
|
| 37 |
+
edge.type = edgeType;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
return edge;
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
return (
|
| 44 |
+
<ReactFlow
|
| 45 |
+
nodes={nodes}
|
| 46 |
+
edges={edgesWithUpdatedTypes}
|
| 47 |
+
onNodesChange={onNodesChange}
|
| 48 |
+
onEdgesChange={onEdgesChange}
|
| 49 |
+
onConnect={onConnect}
|
| 50 |
+
onInit={onInit}
|
| 51 |
+
fitView
|
| 52 |
+
attributionPosition="top-right"
|
| 53 |
+
nodeTypes={nodeTypes}
|
| 54 |
+
>
|
| 55 |
+
<MiniMap style={minimapStyle} zoomable pannable />
|
| 56 |
+
<Controls />
|
| 57 |
+
<Background color="#aaa" gap={16} />
|
| 58 |
+
</ReactFlow>
|
| 59 |
+
);
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
export default OverviewFlow;
|