From 12c811eab3790ecf55289edd8938309b23543dd8 Mon Sep 17 00:00:00 2001 From: Junyi Date: Tue, 12 Sep 2023 13:29:05 +0700 Subject: [PATCH] fix(plugin-workflow): fix scope variable in loop (#2633) --- .../workflow/src/client/nodes/loop.tsx | 23 +++++++++++++++---- .../plugins/workflow/src/client/variable.tsx | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/plugins/workflow/src/client/nodes/loop.tsx b/packages/plugins/workflow/src/client/nodes/loop.tsx index 146183af6..fa048d54f 100644 --- a/packages/plugins/workflow/src/client/nodes/loop.tsx +++ b/packages/plugins/workflow/src/client/nodes/loop.tsx @@ -6,7 +6,13 @@ import { Branch } from '../Branch'; import { useFlowContext } from '../FlowContext'; import { NAMESPACE, lang } from '../locale'; import useStyles from '../style'; -import { VariableOption, defaultFieldNames, nodesOptions, triggerOptions, useWorkflowVariableOptions } from '../variable'; +import { + VariableOption, + defaultFieldNames, + nodesOptions, + triggerOptions, + useWorkflowVariableOptions, +} from '../variable'; function findOption(options: VariableOption[], paths: string[]) { let opts = options; @@ -15,9 +21,12 @@ function findOption(options: VariableOption[], paths: string[]) { const path = paths[i]; const current = opts.find((item) => item.value === path); if (!current) { - break; + return null; } option = current; + if (!current.isLeaf && current.loadChildren) { + current.loadChildren(current); + } if (current.children) { opts = current.children; } @@ -111,7 +120,11 @@ export default { // find target data model by path described in `config.target` // 1. get options from $context/$jobsMapByNodeId // 2. route to sub-options and use as loop target options - let targetOption: VariableOption = { key: 'item', [fieldNames.value]: 'item', [fieldNames.label]: lang('Loop target') }; + let targetOption: VariableOption = { + key: 'item', + [fieldNames.value]: 'item', + [fieldNames.label]: lang('Loop target'), + }; if (typeof target === 'string' && target.startsWith('{{') && target.endsWith('}}')) { const paths = target @@ -122,7 +135,7 @@ export default { const targetOptions = [nodesOptions, triggerOptions].map((item: any) => { const opts = item.useOptions(options).filter(Boolean); return { - [fieldNames.label]: compile(item.title), + [fieldNames.label]: compile(item.label), [fieldNames.value]: item.value, key: item.value, [fieldNames.children]: opts, @@ -132,7 +145,7 @@ export default { const found = findOption(targetOptions, paths); - targetOption = Object.assign({ ...targetOption }, found, targetOption); + targetOption = Object.assign({}, found, targetOption); } return [ diff --git a/packages/plugins/workflow/src/client/variable.tsx b/packages/plugins/workflow/src/client/variable.tsx index 5ee107ebe..5b188aa64 100644 --- a/packages/plugins/workflow/src/client/variable.tsx +++ b/packages/plugins/workflow/src/client/variable.tsx @@ -260,7 +260,7 @@ function getNormalizedFields(collectionName, { compile, getCollectionFields }) { return otherFields.filter((field) => field.interface && !field.hidden); } -async function loadChildren(option) { +function loadChildren(option) { const appends = getNextAppends(option.field, option.appends); const result = getCollectionFieldOptions({ collection: option.field.target,