From 7a4f2a011b7ef4ff7c7168dfac5c73efcc77b68b Mon Sep 17 00:00:00 2001 From: Junyi Date: Thu, 6 Apr 2023 11:23:57 +0700 Subject: [PATCH] fix(plugin-workflow): fix manual node drawer (#1653) --- packages/plugins/workflow/src/client/nodes/index.tsx | 3 +++ .../workflow/src/client/nodes/manual/WorkflowTodo.tsx | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/plugins/workflow/src/client/nodes/index.tsx b/packages/plugins/workflow/src/client/nodes/index.tsx index 165e1b570..b208450da 100644 --- a/packages/plugins/workflow/src/client/nodes/index.tsx +++ b/packages/plugins/workflow/src/client/nodes/index.tsx @@ -97,6 +97,9 @@ export function useNodeContext() { export function useAvailableUpstreams(node) { const stack: any[] = []; + if (!node) { + return []; + } for (let current = node.upstream; current; current = current.upstream) { stack.push(current); } diff --git a/packages/plugins/workflow/src/client/nodes/manual/WorkflowTodo.tsx b/packages/plugins/workflow/src/client/nodes/manual/WorkflowTodo.tsx index 395a6fbb4..8ca994784 100644 --- a/packages/plugins/workflow/src/client/nodes/manual/WorkflowTodo.tsx +++ b/packages/plugins/workflow/src/client/nodes/manual/WorkflowTodo.tsx @@ -379,7 +379,7 @@ function useFlowRecordFromBlock(opts) { function FlowContextProvider(props) { const api = useAPIClient(); - const { node, executionId } = useRecord(); + const { id, node, executionId } = useRecord(); const [flowContext, setFlowContext] = useState(null); useEffect(() => { @@ -393,7 +393,7 @@ function FlowContextProvider(props) { .then(({ data }) => { const { workflow: { nodes = [], ...workflow } = {}, - ...execution + execution } = data?.data ?? {}; linkNodes(nodes); setFlowContext({ @@ -402,14 +402,14 @@ function FlowContextProvider(props) { execution }); }); - }, [executionId]); + }, [id]); if (!flowContext) { return null; } - const nodes = useAvailableUpstreams(flowContext.nodes.find(item => item.id === node.id)); - const nodeComponents = nodes.reduce((components, { type }) => Object.assign(components, instructions.get(type).components), {}); + const upstreams = useAvailableUpstreams(flowContext.nodes.find(item => item.id === node.id)); + const nodeComponents = upstreams.reduce((components, { type }) => Object.assign(components, instructions.get(type).components), {}); return (