mirror of https://github.com/langgenius/dify.git
chore: handle key exists check
This commit is contained in:
parent
f930521d64
commit
a32465eeb8
|
|
@ -20,6 +20,7 @@ export type IConfigModalProps = {
|
|||
isCreate?: boolean
|
||||
payload?: InputVar
|
||||
isShow: boolean
|
||||
varKeys?: string[]
|
||||
onClose: () => void
|
||||
onConfirm: (newValue: InputVar, moreInfo?: MoreInfo) => void
|
||||
}
|
||||
|
|
@ -30,6 +31,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
|||
isCreate,
|
||||
payload,
|
||||
isShow,
|
||||
varKeys = [],
|
||||
onClose,
|
||||
onConfirm,
|
||||
}) => {
|
||||
|
|
@ -52,14 +54,28 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
|||
}
|
||||
}
|
||||
setTempPayload((prev) => {
|
||||
return {
|
||||
const newPayload = {
|
||||
...prev,
|
||||
[key]: value,
|
||||
}
|
||||
|
||||
return newPayload
|
||||
})
|
||||
}
|
||||
}, [t])
|
||||
|
||||
const handleVarKeyBlur = useCallback((e: any) => {
|
||||
if (tempPayload.label)
|
||||
return
|
||||
|
||||
setTempPayload((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
label: e.target.value,
|
||||
}
|
||||
})
|
||||
}, [tempPayload])
|
||||
|
||||
const handleConfirm = () => {
|
||||
const moreInfo = tempPayload.variable === payload?.variable
|
||||
? undefined
|
||||
|
|
@ -71,6 +87,13 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
|||
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.varNameRequired') })
|
||||
return
|
||||
}
|
||||
if (varKeys.map(key => key?.trim()).includes(tempPayload.variable.trim())) {
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
message: t('appDebug.varKeyError.keyAlreadyExists', { key: tempPayload.variable }),
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!tempPayload.label) {
|
||||
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.labelNameRequired') })
|
||||
return
|
||||
|
|
@ -125,6 +148,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
|||
className={inputClassName}
|
||||
value={variable}
|
||||
onChange={e => handlePayloadChange('variable')(e.target.value)}
|
||||
onBlur={handleVarKeyBlur}
|
||||
/>
|
||||
</Field>
|
||||
<Field title={t('appDebug.variableConig.labelName')}>
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
|
|||
const {
|
||||
mode,
|
||||
dataSets,
|
||||
externalDataToolsConfig,
|
||||
} = useContext(ConfigContext)
|
||||
const { eventEmitter } = useEventEmitterContextContext()
|
||||
|
||||
|
|
@ -381,6 +380,7 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
|
|||
updatePromptVariableItem(item)
|
||||
hideEditModal()
|
||||
}}
|
||||
varKeys={promptVariables.map(v => v.key)}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ type Props = {
|
|||
onChange?: (item: InputVar, moreInfo?: MoreInfo) => void
|
||||
onRemove?: () => void
|
||||
rightContent?: JSX.Element
|
||||
varKeys?: string[]
|
||||
}
|
||||
|
||||
const VarItem: FC<Props> = ({
|
||||
|
|
@ -24,6 +25,7 @@ const VarItem: FC<Props> = ({
|
|||
onChange = () => { },
|
||||
onRemove = () => { },
|
||||
rightContent,
|
||||
varKeys = [],
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
|
|
@ -78,6 +80,7 @@ const VarItem: FC<Props> = ({
|
|||
payload={payload}
|
||||
onClose={hideEditVarModal}
|
||||
onConfirm={handlePayloadChange}
|
||||
varKeys={varKeys}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ const VarList: FC<Props> = ({
|
|||
payload={item}
|
||||
onChange={handleVarChange(index)}
|
||||
onRemove={handleVarRemove(index)}
|
||||
varKeys={list.map(item => item.variable)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ const Panel: FC<NodePanelProps<StartNodeType>> = ({
|
|||
isShow={isShowAddVarModal}
|
||||
onClose={hideAddVarModal}
|
||||
onConfirm={handleAddVarConfirm}
|
||||
varKeys={inputs.variables.map(v => v.variable)}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue