|
@@ -1,10 +1,11 @@
|
|
|
-import { useContext } from 'react'
|
|
|
+import React, { useContext, useEffect } from 'react'
|
|
|
import ReactFlow, { Background, MiniMap, Controls } from 'react-flow-renderer'
|
|
|
import { Actions, FlowContext } from '../../context'
|
|
|
|
|
|
-import type { NodeTypesType, EdgeTypesType } from 'react-flow-renderer'
|
|
|
+import type { Elements, NodeTypesType, EdgeTypesType } from 'react-flow-renderer'
|
|
|
import { CommonNode, InputNode, OutputNode } from '../Node'
|
|
|
import { CommonEdge } from '../Edge'
|
|
|
+import type { ApprovalMethod, ApprovalType } from '../../enum'
|
|
|
|
|
|
const nodeTypes: NodeTypesType = {
|
|
|
start: InputNode,
|
|
@@ -16,8 +17,30 @@ const edgeTypes: EdgeTypesType = {
|
|
|
common: CommonEdge
|
|
|
}
|
|
|
|
|
|
-export default function FlowGroph() {
|
|
|
+type flowProcessDataItem = {
|
|
|
+ approvalType: ApprovalType
|
|
|
+ approvalMethod: ApprovalMethod
|
|
|
+ approvalAccounts: { ID: string; name: string }[]
|
|
|
+}
|
|
|
+
|
|
|
+type FlowGrophProps = {
|
|
|
+ flowProcess?: Elements
|
|
|
+ flowProcessData?: Record<string, flowProcessDataItem>
|
|
|
+}
|
|
|
+const FlowGroph: React.FC<FlowGrophProps> = ({ flowProcess, flowProcessData }) => {
|
|
|
const { flowState, dispatch } = useContext(FlowContext)
|
|
|
+ useEffect(() => {
|
|
|
+ if (flowProcess?.length) {
|
|
|
+ dispatch({
|
|
|
+ type: Actions.SET_ELEMENTS,
|
|
|
+ payload: flowProcess
|
|
|
+ })
|
|
|
+ dispatch({
|
|
|
+ type: Actions.SET_FLOW_NODE,
|
|
|
+ payload: new Map(Object.entries(flowProcessData))
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }, [flowProcess, flowProcessData])
|
|
|
const { elements } = flowState
|
|
|
|
|
|
const defaultOptions = {
|
|
@@ -30,7 +53,9 @@ export default function FlowGroph() {
|
|
|
type: Actions.SET_FLOW_INSTANCE,
|
|
|
payload: reactFlowInstance
|
|
|
})
|
|
|
- reactFlowInstance?.fitView()
|
|
|
+ // setTimeout(() => {
|
|
|
+ // reactFlowInstance?.fitView()
|
|
|
+ // }, 80)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -47,3 +72,5 @@ export default function FlowGroph() {
|
|
|
</ReactFlow>
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
+export default FlowGroph
|