From 7a2a8a2ffd8d04263e5d497b34079e682233a966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=9E=E6=B3=95=E6=93=8D=E4=BD=9C?= Date: Tue, 17 Jun 2025 16:27:51 +0800 Subject: [PATCH] chore: check input variable key of code/template node is valid (#21057) --- .../_base/components/variable/var-list.tsx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-list.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-list.tsx index 72e9384d5..181b27805 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-list.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-list.tsx @@ -8,6 +8,8 @@ import VarReferencePicker from './var-reference-picker' import Input from '@/app/components/base/input' import type { ValueSelector, Var, Variable } from '@/app/components/workflow/types' import { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types' +import { checkKeys } from '@/utils/var' +import Toast from '@/app/components/base/toast' type Props = { nodeId: string @@ -36,9 +38,27 @@ const VarList: FC = ({ const handleVarNameChange = useCallback((index: number) => { return (e: React.ChangeEvent) => { - onVarNameChange?.(list[index].variable, e.target.value) + const newKey = e.target.value + const { isValid, errorKey, errorMessageKey } = checkKeys([newKey], true) + if (!isValid) { + Toast.notify({ + type: 'error', + message: t(`appDebug.varKeyError.${errorMessageKey}`, { key: errorKey }), + }) + return + } + + if (list.map(item => item.variable?.trim()).includes(newKey.trim())) { + Toast.notify({ + type: 'error', + message: t('appDebug.varKeyError.keyAlreadyExists', { key: newKey }), + }) + return + } + + onVarNameChange?.(list[index].variable, newKey) const newList = produce(list, (draft) => { - draft[index].variable = e.target.value + draft[index].variable = newKey }) onChange(newList) }