fix(plugin-workflow): fix manual node drawer (#1653)

This commit is contained in:
Junyi 2023-04-06 11:23:57 +07:00 committed by GitHub
parent 6f12e97f52
commit 7a4f2a011b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -97,6 +97,9 @@ export function useNodeContext() {
export function useAvailableUpstreams(node) { export function useAvailableUpstreams(node) {
const stack: any[] = []; const stack: any[] = [];
if (!node) {
return [];
}
for (let current = node.upstream; current; current = current.upstream) { for (let current = node.upstream; current; current = current.upstream) {
stack.push(current); stack.push(current);
} }

View File

@ -379,7 +379,7 @@ function useFlowRecordFromBlock(opts) {
function FlowContextProvider(props) { function FlowContextProvider(props) {
const api = useAPIClient(); const api = useAPIClient();
const { node, executionId } = useRecord(); const { id, node, executionId } = useRecord();
const [flowContext, setFlowContext] = useState<any>(null); const [flowContext, setFlowContext] = useState<any>(null);
useEffect(() => { useEffect(() => {
@ -393,7 +393,7 @@ function FlowContextProvider(props) {
.then(({ data }) => { .then(({ data }) => {
const { const {
workflow: { nodes = [], ...workflow } = {}, workflow: { nodes = [], ...workflow } = {},
...execution execution
} = data?.data ?? {}; } = data?.data ?? {};
linkNodes(nodes); linkNodes(nodes);
setFlowContext({ setFlowContext({
@ -402,14 +402,14 @@ function FlowContextProvider(props) {
execution execution
}); });
}); });
}, [executionId]); }, [id]);
if (!flowContext) { if (!flowContext) {
return null; return null;
} }
const nodes = useAvailableUpstreams(flowContext.nodes.find(item => item.id === node.id)); const upstreams = useAvailableUpstreams(flowContext.nodes.find(item => item.id === node.id));
const nodeComponents = nodes.reduce((components, { type }) => Object.assign(components, instructions.get(type).components), {}); const nodeComponents = upstreams.reduce((components, { type }) => Object.assign(components, instructions.get(type).components), {});
return ( return (
<FlowContext.Provider value={flowContext}> <FlowContext.Provider value={flowContext}>