From 0a6df921597b55d47b9bfb3a7a4fedb7b1b71450 Mon Sep 17 00:00:00 2001 From: Junyi Date: Tue, 21 May 2024 17:47:41 +0800 Subject: [PATCH] fix(plugin-workflow): fix empty value in create and update node association values (#4433) --- .../client/components/CollectionFieldset.tsx | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/components/CollectionFieldset.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/components/CollectionFieldset.tsx index 8412f2faff..412f2f8c39 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/components/CollectionFieldset.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/components/CollectionFieldset.tsx @@ -21,7 +21,7 @@ import { useToken, } from '@nocobase/client'; import { Button, Dropdown, Form, Input, MenuProps } from 'antd'; -import React, { useMemo } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { lang } from '../locale'; import { useWorkflowVariableOptions } from '../variable'; @@ -36,10 +36,20 @@ function AssociationInput(props) { const { type } = fields.find((item) => item.name === fieldName); const value = Array.isArray(props.value) ? props.value.join(',') : props.value; - function onChange(ev) { - const trimed = ev.target.value.trim(); - props.onChange(['belongsTo', 'hasOne'].includes(type) ? trimed : trimed.split(/[,\s]+/)); - } + const onChange = useCallback( + (ev) => { + const trimed = ev.target.value.trim(); + const next = ['belongsTo', 'hasOne'].includes(type) + ? trimed || null + : trimed + .split(',') + .map((item) => item.trim()) + .filter((item) => item !== ''); + props.onChange(next); + }, + [props.onChange, type], + ); + return ; }