From 6b220c342ccd72055e6f9a558ecd9b85e8cde68d Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 7 Jul 2023 21:51:44 +0700 Subject: [PATCH] fix(plugin-workflow): fix loop variable (#2211) --- .../workflow/src/client/nodes/calculation.tsx | 6 ++--- .../workflow/src/client/nodes/loop.tsx | 26 +++++++++++-------- .../workflow/src/client/nodes/update.tsx | 5 ++-- .../plugins/workflow/src/client/variable.tsx | 4 +-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/plugins/workflow/src/client/nodes/calculation.tsx b/packages/plugins/workflow/src/client/nodes/calculation.tsx index da63c019a..6633ff6b0 100644 --- a/packages/plugins/workflow/src/client/nodes/calculation.tsx +++ b/packages/plugins/workflow/src/client/nodes/calculation.tsx @@ -36,13 +36,13 @@ const DynamicConfig = ({ value, onChange }) => { { onChange(ev.target.value); }} > {t('Static', { ns: NAMESPACE })} - {t('Dynamic', { ns: NAMESPACE })} + {t('Dynamic', { ns: NAMESPACE })} {value !== false ? ( @@ -53,7 +53,7 @@ const DynamicConfig = ({ value, onChange }) => { { ns: NAMESPACE }, )} > - onChange(v)} scope={scope} /> + onChange(v)} scope={scope} /> ) : null} diff --git a/packages/plugins/workflow/src/client/nodes/loop.tsx b/packages/plugins/workflow/src/client/nodes/loop.tsx index c6e888330..603c5cf1c 100644 --- a/packages/plugins/workflow/src/client/nodes/loop.tsx +++ b/packages/plugins/workflow/src/client/nodes/loop.tsx @@ -9,18 +9,20 @@ import { addButtonClass, branchBlockClass, branchClass, nodeSubtreeClass } from import { nodesOptions, triggerOptions, useWorkflowVariableOptions, VariableOption } from '../variable'; function findOption(options: VariableOption[], paths: string[]) { - let current = options; + let opts = options; + let option = null; for (let i = 0; i < paths.length; i++) { const path = paths[i]; - const option = current.find((item) => item.value === path); - if (!option) { - return null; + const current = opts.find((item) => item.value === path); + if (!current) { + break; } - if (option.children) { - current = option.children; + option = current; + if (current.children) { + opts = current.children; } } - return current; + return option; } export default { @@ -124,7 +126,7 @@ 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 - const targetOption: VariableOption = { key: 'item', value: 'item', label: lang('Loop target') }; + let targetOption: VariableOption = { key: 'item', value: 'item', label: lang('Loop target') }; if (typeof target === 'string' && target.startsWith('{{') && target.endsWith('}}')) { const paths = target @@ -133,17 +135,19 @@ export default { .map((path) => path.trim()); const targetOptions = [nodesOptions, triggerOptions].map((item: any) => { - const opts = typeof item.useOptions === 'function' ? item.useOptions(options).filter(Boolean) : null; + const opts = item.useOptions(options).filter(Boolean); return { label: compile(item.title), value: item.value, key: item.value, - children: compile(opts), + children: opts, disabled: opts && !opts.length, }; }); - targetOption.children = findOption(targetOptions, paths); + const found = findOption(targetOptions, paths); + + targetOption = Object.assign({ ...targetOption }, found, targetOption); } return [ diff --git a/packages/plugins/workflow/src/client/nodes/update.tsx b/packages/plugins/workflow/src/client/nodes/update.tsx index 06588c6af..a26693722 100644 --- a/packages/plugins/workflow/src/client/nodes/update.tsx +++ b/packages/plugins/workflow/src/client/nodes/update.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { onFieldInputValueChange } from '@formily/core'; import { useForm, useField } from '@formily/react'; import { useCollectionDataSource } from '@nocobase/client'; @@ -8,7 +7,7 @@ import { FilterDynamicComponent } from '../components/FilterDynamicComponent'; import CollectionFieldset, { useCollectionUIFields } from '../components/CollectionFieldset'; import { isValidFilter } from '../utils'; -import { NAMESPACE } from '../locale'; +import { NAMESPACE, lang } from '../locale'; import { collection, filter, values } from '../schemas/collection'; import { RadioWithTooltip } from '../components/RadioWithTooltip'; @@ -74,7 +73,7 @@ export default { ...filter, title: `{{t("Only update records matching conditions", { ns: "${NAMESPACE}" })}}`, ['x-validator'](value) { - return isValidFilter(value) ? '' : `{{t("Please add at least one condition", { ns: "${NAMESPACE}" })}}`; + return isValidFilter(value) ? '' : lang('Please add at least one condition'); }, }, values: { diff --git a/packages/plugins/workflow/src/client/variable.tsx b/packages/plugins/workflow/src/client/variable.tsx index 984d15aed..d60d55caf 100644 --- a/packages/plugins/workflow/src/client/variable.tsx +++ b/packages/plugins/workflow/src/client/variable.tsx @@ -1,4 +1,4 @@ -import { useCollectionManager, useCompile } from '@nocobase/client'; +import { useCompile } from '@nocobase/client'; import { useFlowContext } from './FlowContext'; import { NAMESPACE, lang } from './locale'; import { instructions, useAvailableUpstreams, useNodeContext, useUpstreamScopes } from './nodes'; @@ -84,7 +84,7 @@ export const systemOptions = { export const BaseTypeSets = { boolean: new Set(['checkbox']), - number: new Set(['number', 'percent']), + number: new Set(['integer', 'number', 'percent']), string: new Set([ 'input', 'password',