chore: add var can not has exist key

This commit is contained in:
Joel
2025-08-20 14:06:46 +08:00
parent af6e5e8663
commit 96e8321462
3 changed files with 27 additions and 3 deletions

View File

@@ -36,8 +36,7 @@ const VarList: FC<Props> = ({
errorMsgKey = 'appDebug.varKeyError.keyAlreadyExists'
typeName = 'appDebug.variableConfig.varName'
}
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'
}

View File

@@ -34,7 +34,8 @@ const Panel: FC<NodePanelProps<StartNodeType>> = ({
} = useConfig(id, data)
const handleAddVarConfirm = (payload: InputVar) => {
handleAddVariable(payload)
const isValid = handleAddVariable(payload)
if (!isValid) return
hideAddVarModal()
}

View File

@@ -11,8 +11,12 @@ import {
useWorkflow,
} from '@/app/components/workflow/hooks'
import useInspectVarsCrud from '../../hooks/use-inspect-vars-crud'
import { hasDuplicateStr } from '@/utils/var'
import Toast from '@/app/components/base/toast'
import { useTranslation } from 'react-i18next'
const useConfig = (id: string, payload: StartNodeType) => {
const { t } = useTranslation()
const { nodesReadOnly: readOnly } = useNodesReadOnly()
const { handleOutVarRenameChange, isVarUsedInNodes, removeUsedVarInNodes } = useWorkflow()
const isChatMode = useIsChatMode()
@@ -80,7 +84,27 @@ const useConfig = (id: string, payload: StartNodeType) => {
const newInputs = produce(inputs, (draft: StartNodeType) => {
draft.variables.push(payload)
})
const newList = newInputs.variables
let errorMsgKey = ''
let typeName = ''
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))) {
errorMsgKey = 'appDebug.varKeyError.keyAlreadyExists'
typeName = 'appDebug.variableConfig.labelName'
}
if (errorMsgKey) {
Toast.notify({
type: 'error',
message: t(errorMsgKey, { key: t(typeName) }),
})
return false
}
setInputs(newInputs)
return true
}, [inputs, setInputs])
return {
readOnly,