mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
chore: edit filed exists
This commit is contained in:
@ -19,7 +19,7 @@ type Props = {
|
|||||||
className?: string
|
className?: string
|
||||||
readonly: boolean
|
readonly: boolean
|
||||||
payload: InputVar
|
payload: InputVar
|
||||||
onChange?: (item: InputVar, moreInfo?: MoreInfo) => void
|
onChange?: (item: InputVar, moreInfo?: MoreInfo) => boolean
|
||||||
onRemove?: () => void
|
onRemove?: () => void
|
||||||
rightContent?: React.JSX.Element
|
rightContent?: React.JSX.Element
|
||||||
varKeys?: string[]
|
varKeys?: string[]
|
||||||
@ -31,7 +31,7 @@ const VarItem: FC<Props> = ({
|
|||||||
className,
|
className,
|
||||||
readonly,
|
readonly,
|
||||||
payload,
|
payload,
|
||||||
onChange = noop,
|
onChange = () => true,
|
||||||
onRemove = noop,
|
onRemove = noop,
|
||||||
rightContent,
|
rightContent,
|
||||||
varKeys = [],
|
varKeys = [],
|
||||||
@ -48,7 +48,9 @@ const VarItem: FC<Props> = ({
|
|||||||
}] = useBoolean(false)
|
}] = useBoolean(false)
|
||||||
|
|
||||||
const handlePayloadChange = useCallback((payload: InputVar, moreInfo?: MoreInfo) => {
|
const handlePayloadChange = useCallback((payload: InputVar, moreInfo?: MoreInfo) => {
|
||||||
onChange(payload, moreInfo)
|
const isValid = onChange(payload, moreInfo)
|
||||||
|
if(!isValid)
|
||||||
|
return
|
||||||
hideEditVarModal()
|
hideEditVarModal()
|
||||||
}, [onChange, hideEditVarModal])
|
}, [onChange, hideEditVarModal])
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -9,6 +9,8 @@ import { v4 as uuid4 } from 'uuid'
|
|||||||
import { ReactSortable } from 'react-sortablejs'
|
import { ReactSortable } from 'react-sortablejs'
|
||||||
import { RiDraggable } from '@remixicon/react'
|
import { RiDraggable } from '@remixicon/react'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
import { hasDuplicateStr } from '@/utils/var'
|
||||||
|
import Toast from '@/app/components/base/toast'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
readonly: boolean
|
readonly: boolean
|
||||||
@ -28,7 +30,27 @@ const VarList: FC<Props> = ({
|
|||||||
const newList = produce(list, (draft) => {
|
const newList = produce(list, (draft) => {
|
||||||
draft[index] = payload
|
draft[index] = payload
|
||||||
})
|
})
|
||||||
|
let errorMsgKey = ''
|
||||||
|
let typeName = ''
|
||||||
|
if(hasDuplicateStr(newList.map(item => item.variable))) {
|
||||||
|
errorMsgKey = 'appDebug.varKeyError.keyAlreadyExists'
|
||||||
|
typeName = 'appDebug.variableConfig.varName'
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
onChange(newList, moreInfo ? { index, payload: moreInfo } : undefined)
|
onChange(newList, moreInfo ? { index, payload: moreInfo } : undefined)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}, [list, onChange])
|
}, [list, onChange])
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ export const getNewVarInWorkflow = (key: string, type = InputVarType.textInput)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const checkKey = (key: string, canBeEmpty?: boolean) => {
|
export const checkKey = (key: string, canBeEmpty?: boolean, keys?: string[]) => {
|
||||||
if (key.length === 0 && !canBeEmpty)
|
if (key.length === 0 && !canBeEmpty)
|
||||||
return 'canNoBeEmpty'
|
return 'canNoBeEmpty'
|
||||||
|
|
||||||
@ -82,6 +82,17 @@ export const checkKeys = (keys: string[], canBeEmpty?: boolean) => {
|
|||||||
return { isValid, errorKey, errorMessageKey }
|
return { isValid, errorKey, errorMessageKey }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const hasDuplicateStr = (strArr: string[]) => {
|
||||||
|
const strObj: Record<string, number> = {}
|
||||||
|
strArr.forEach((str) => {
|
||||||
|
if (strObj[str])
|
||||||
|
strObj[str] += 1
|
||||||
|
else
|
||||||
|
strObj[str] = 1
|
||||||
|
})
|
||||||
|
return !!Object.keys(strObj).find(key => strObj[key] > 1)
|
||||||
|
}
|
||||||
|
|
||||||
const varRegex = /\{\{([a-zA-Z_]\w*)\}\}/g
|
const varRegex = /\{\{([a-zA-Z_]\w*)\}\}/g
|
||||||
export const getVars = (value: string) => {
|
export const getVars = (value: string) => {
|
||||||
if (!value)
|
if (!value)
|
||||||
|
|||||||
Reference in New Issue
Block a user