fix: workflow restore (#3711)

This commit is contained in:
zxhlyh
2024-04-23 17:02:23 +08:00
committed by GitHub
parent 96160837d2
commit 83caffe000
9 changed files with 654 additions and 318 deletions

View File

@@ -14,6 +14,8 @@ import {
import ReactFlow, {
Background,
ReactFlowProvider,
useEdgesState,
useNodesState,
useOnViewportChange,
} from 'reactflow'
import type { Viewport } from 'reactflow'
@@ -46,9 +48,11 @@ import {
initialEdges,
initialNodes,
} from './utils'
import { WORKFLOW_DATA_UPDATE } from './constants'
import Loading from '@/app/components/base/loading'
import { FeaturesProvider } from '@/app/components/base/features'
import type { Features as FeaturesData } from '@/app/components/base/features/types'
import { useEventEmitterContextContext } from '@/context/event-emitter'
const nodeTypes = {
custom: CustomNode,
@@ -63,10 +67,12 @@ type WorkflowProps = {
viewport?: Viewport
}
const Workflow: FC<WorkflowProps> = memo(({
nodes,
edges,
nodes: originalNodes,
edges: originalEdges,
viewport,
}) => {
const [nodes, setNodes] = useNodesState(originalNodes)
const [edges, setEdges] = useEdgesState(originalEdges)
const showFeaturesPanel = useStore(state => state.showFeaturesPanel)
const nodeAnimation = useStore(s => s.nodeAnimation)
const {
@@ -76,6 +82,15 @@ const Workflow: FC<WorkflowProps> = memo(({
const { workflowReadOnly } = useWorkflowReadOnly()
const { nodesReadOnly } = useNodesReadOnly()
const { eventEmitter } = useEventEmitterContextContext()
eventEmitter?.useSubscription((v: any) => {
if (v.type === WORKFLOW_DATA_UPDATE) {
setNodes(v.payload.nodes)
setEdges(v.payload.edges)
}
})
useEffect(() => {
setAutoFreeze(false)