|
@@ -0,0 +1,74 @@
|
|
|
+import React, { useState, useReducer, useContext } from 'react'
|
|
|
+import ReactFlow, {
|
|
|
+ removeElements,
|
|
|
+ addEdge,
|
|
|
+ MiniMap,
|
|
|
+ Controls,
|
|
|
+ Background
|
|
|
+} from 'react-flow-renderer'
|
|
|
+import type { FC } from 'react'
|
|
|
+import type { Elements, NodeTypesType, EdgeTypesType } from 'react-flow-renderer'
|
|
|
+
|
|
|
+import './index.less'
|
|
|
+import { InputNode, OutputNode } from './components/Node'
|
|
|
+import { ButtonEdge } from './components/Edge/Edge'
|
|
|
+
|
|
|
+type ApprovalFlowProps<T = any> = {
|
|
|
+ elements: Elements<T>
|
|
|
+}
|
|
|
+
|
|
|
+const nodeTypes: NodeTypesType = {
|
|
|
+ start: InputNode,
|
|
|
+ end: OutputNode
|
|
|
+}
|
|
|
+
|
|
|
+const edgeTypes: EdgeTypesType = {
|
|
|
+ add: ButtonEdge
|
|
|
+}
|
|
|
+
|
|
|
+const flowContext = React.createContext()
|
|
|
+
|
|
|
+function reducer(state, action) {
|
|
|
+ switch (action.type) {
|
|
|
+ case 'reset':
|
|
|
+ return initialState
|
|
|
+ case 'increment':
|
|
|
+ return { count: state.count + 1 }
|
|
|
+ case 'decrement':
|
|
|
+ return { count: state.count - 1 }
|
|
|
+ default:
|
|
|
+ return state
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const initialElements = [
|
|
|
+ {
|
|
|
+ id: 'ewb-1',
|
|
|
+ type: 'start',
|
|
|
+ position: { x: 250, y: 0 }
|
|
|
+ },
|
|
|
+ { id: 'ewb-2', type: 'end', position: { x: 250, y: 300 } },
|
|
|
+
|
|
|
+ {
|
|
|
+ id: 'edge-1-2',
|
|
|
+ source: 'ewb-1',
|
|
|
+ target: 'ewb-2',
|
|
|
+ type: 'add'
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+const ApprovalFlow: FC<ApprovalFlowProps> = ({ elements }) => {
|
|
|
+ // const [elements, setElements] = useState<Elements>(initialElements);
|
|
|
+ const [elements, dispatch] = useReducer<Elements>(reducer, initialElements)
|
|
|
+ return (
|
|
|
+ <div className="w-full h-full">
|
|
|
+ <ReactFlow elements={elements} nodeTypes={nodeTypes} edgeTypes={edgeTypes}>
|
|
|
+ <MiniMap />
|
|
|
+ <Controls />
|
|
|
+ <Background />
|
|
|
+ </ReactFlow>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+export default ApprovalFlow
|