mirror of
https://github.com/langgenius/dify.git
synced 2026-01-08 07:14:14 +00:00
chore: add var can not has exist key
This commit is contained in:
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user