From f5f11f5a9eaab06bda7d3fab67fffe15d8300787 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 20 Aug 2025 14:23:33 +0800 Subject: [PATCH] feat: basic input field edit --- .../app/configuration/config-var/index.tsx | 26 +++++++++++++++++-- .../nodes/start/components/var-list.tsx | 4 +-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/web/app/components/app/configuration/config-var/index.tsx b/web/app/components/app/configuration/config-var/index.tsx index 8d1f4a8eff..2ac68227e3 100644 --- a/web/app/components/app/configuration/config-var/index.tsx +++ b/web/app/components/app/configuration/config-var/index.tsx @@ -12,7 +12,7 @@ import SelectVarType from './select-var-type' import Tooltip from '@/app/components/base/tooltip' import type { PromptVariable } from '@/models/debug' import { DEFAULT_VALUE_MAX_LEN } from '@/config' -import { getNewVar } from '@/utils/var' +import { getNewVar, hasDuplicateStr } from '@/utils/var' import Toast from '@/app/components/base/toast' import Confirm from '@/app/components/base/confirm' import ConfigContext from '@/context/debug-configuration' @@ -80,7 +80,28 @@ const ConfigVar: FC = ({ promptVariables, readonly, onPromptVar delete draft[currIndex].options }) + const newList = newPromptVariables + let errorMsgKey = '' + let typeName = '' + if (hasDuplicateStr(newList.map(item => item.key))) { + errorMsgKey = 'appDebug.varKeyError.keyAlreadyExists' + typeName = 'appDebug.variableConfig.varName' + } + else if (hasDuplicateStr(newList.map(item => item.name as string))) { + errorMsgKey = 'appDebug.varKeyError.keyAlreadyExists' + typeName = 'appDebug.variableConfig.labelName' + } + + if (errorMsgKey) { + Toast.notify({ + type: 'error', + message: t(errorMsgKey, { key: t(typeName) }), + }) + return false + } + onPromptVariablesChange?.(newPromptVariables) + return true } const { setShowExternalDataToolModal } = useModalContext() @@ -245,7 +266,8 @@ const ConfigVar: FC = ({ promptVariables, readonly, onPromptVar isShow={isShowEditModal} onClose={hideEditModal} onConfirm={(item) => { - updatePromptVariableItem(item) + const isValid = updatePromptVariableItem(item) + if (!isValid) return hideEditModal() }} varKeys={promptVariables.map(v => v.key)} diff --git a/web/app/components/workflow/nodes/start/components/var-list.tsx b/web/app/components/workflow/nodes/start/components/var-list.tsx index 3179e02cfd..bbfeed461a 100644 --- a/web/app/components/workflow/nodes/start/components/var-list.tsx +++ b/web/app/components/workflow/nodes/start/components/var-list.tsx @@ -32,11 +32,11 @@ const VarList: FC = ({ }) let errorMsgKey = '' let typeName = '' - if(hasDuplicateStr(newList.map(item => item.variable))) { + if (hasDuplicateStr(newList.map(item => item.variable))) { errorMsgKey = 'appDebug.varKeyError.keyAlreadyExists' typeName = 'appDebug.variableConfig.varName' } - else if(hasDuplicateStr(newList.map(item => item.label as string))) { + else if (hasDuplicateStr(newList.map(item => item.label as string))) { errorMsgKey = 'appDebug.varKeyError.keyAlreadyExists' typeName = 'appDebug.variableConfig.labelName' }