fix(plugin-workflow): fix loop variable (#2211)

This commit is contained in:
Junyi 2023-07-07 21:51:44 +07:00 committed by GitHub
parent 687f3c214d
commit 6b220c342c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 19 deletions

View File

@ -36,13 +36,13 @@ const DynamicConfig = ({ value, onChange }) => {
<FormLayout layout="vertical"> <FormLayout layout="vertical">
<FormItem colon label={t('Expression type', { ns: NAMESPACE })}> <FormItem colon label={t('Expression type', { ns: NAMESPACE })}>
<Radio.Group <Radio.Group
value={value === false ? false : value || null} value={value === false ? false : value || ''}
onChange={(ev) => { onChange={(ev) => {
onChange(ev.target.value); onChange(ev.target.value);
}} }}
> >
<Radio value={false}>{t('Static', { ns: NAMESPACE })}</Radio> <Radio value={false}>{t('Static', { ns: NAMESPACE })}</Radio>
<Radio value={value || null}>{t('Dynamic', { ns: NAMESPACE })}</Radio> <Radio value={value || ''}>{t('Dynamic', { ns: NAMESPACE })}</Radio>
</Radio.Group> </Radio.Group>
</FormItem> </FormItem>
{value !== false ? ( {value !== false ? (
@ -53,7 +53,7 @@ const DynamicConfig = ({ value, onChange }) => {
{ ns: NAMESPACE }, { ns: NAMESPACE },
)} )}
> >
<Variable.Input value={value || null} onChange={(v) => onChange(v)} scope={scope} /> <Variable.Input value={value || ''} onChange={(v) => onChange(v)} scope={scope} />
</FormItem> </FormItem>
) : null} ) : null}
</FormLayout> </FormLayout>

View File

@ -9,18 +9,20 @@ import { addButtonClass, branchBlockClass, branchClass, nodeSubtreeClass } from
import { nodesOptions, triggerOptions, useWorkflowVariableOptions, VariableOption } from '../variable'; import { nodesOptions, triggerOptions, useWorkflowVariableOptions, VariableOption } from '../variable';
function findOption(options: VariableOption[], paths: string[]) { function findOption(options: VariableOption[], paths: string[]) {
let current = options; let opts = options;
let option = null;
for (let i = 0; i < paths.length; i++) { for (let i = 0; i < paths.length; i++) {
const path = paths[i]; const path = paths[i];
const option = current.find((item) => item.value === path); const current = opts.find((item) => item.value === path);
if (!option) { if (!current) {
return null; break;
} }
if (option.children) { option = current;
current = option.children; if (current.children) {
opts = current.children;
} }
} }
return current; return option;
} }
export default { export default {
@ -124,7 +126,7 @@ export default {
// find target data model by path described in `config.target` // find target data model by path described in `config.target`
// 1. get options from $context/$jobsMapByNodeId // 1. get options from $context/$jobsMapByNodeId
// 2. route to sub-options and use as loop target options // 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('}}')) { if (typeof target === 'string' && target.startsWith('{{') && target.endsWith('}}')) {
const paths = target const paths = target
@ -133,17 +135,19 @@ export default {
.map((path) => path.trim()); .map((path) => path.trim());
const targetOptions = [nodesOptions, triggerOptions].map((item: any) => { 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 { return {
label: compile(item.title), label: compile(item.title),
value: item.value, value: item.value,
key: item.value, key: item.value,
children: compile(opts), children: opts,
disabled: opts && !opts.length, disabled: opts && !opts.length,
}; };
}); });
targetOption.children = findOption(targetOptions, paths); const found = findOption(targetOptions, paths);
targetOption = Object.assign({ ...targetOption }, found, targetOption);
} }
return [ return [

View File

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import { onFieldInputValueChange } from '@formily/core';
import { useForm, useField } from '@formily/react'; import { useForm, useField } from '@formily/react';
import { useCollectionDataSource } from '@nocobase/client'; import { useCollectionDataSource } from '@nocobase/client';
@ -8,7 +7,7 @@ import { FilterDynamicComponent } from '../components/FilterDynamicComponent';
import CollectionFieldset, { useCollectionUIFields } from '../components/CollectionFieldset'; import CollectionFieldset, { useCollectionUIFields } from '../components/CollectionFieldset';
import { isValidFilter } from '../utils'; import { isValidFilter } from '../utils';
import { NAMESPACE } from '../locale'; import { NAMESPACE, lang } from '../locale';
import { collection, filter, values } from '../schemas/collection'; import { collection, filter, values } from '../schemas/collection';
import { RadioWithTooltip } from '../components/RadioWithTooltip'; import { RadioWithTooltip } from '../components/RadioWithTooltip';
@ -74,7 +73,7 @@ export default {
...filter, ...filter,
title: `{{t("Only update records matching conditions", { ns: "${NAMESPACE}" })}}`, title: `{{t("Only update records matching conditions", { ns: "${NAMESPACE}" })}}`,
['x-validator'](value) { ['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: { values: {

View File

@ -1,4 +1,4 @@
import { useCollectionManager, useCompile } from '@nocobase/client'; import { useCompile } from '@nocobase/client';
import { useFlowContext } from './FlowContext'; import { useFlowContext } from './FlowContext';
import { NAMESPACE, lang } from './locale'; import { NAMESPACE, lang } from './locale';
import { instructions, useAvailableUpstreams, useNodeContext, useUpstreamScopes } from './nodes'; import { instructions, useAvailableUpstreams, useNodeContext, useUpstreamScopes } from './nodes';
@ -84,7 +84,7 @@ export const systemOptions = {
export const BaseTypeSets = { export const BaseTypeSets = {
boolean: new Set(['checkbox']), boolean: new Set(['checkbox']),
number: new Set(['number', 'percent']), number: new Set(['integer', 'number', 'percent']),
string: new Set([ string: new Set([
'input', 'input',
'password', 'password',