mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-24 18:23:07 +08:00
chore: improve the check time of variable name (#7569)
This commit is contained in:
@@ -42,18 +42,19 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
||||
const { type, label, variable, options, max_length } = tempPayload
|
||||
|
||||
const isStringInput = type === InputVarType.textInput || type === InputVarType.paragraph
|
||||
const checkVariableName = useCallback((value: string) => {
|
||||
const { isValid, errorMessageKey } = checkKeys([value], false)
|
||||
if (!isValid) {
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
message: t(`appDebug.varKeyError.${errorMessageKey}`, { key: t('appDebug.variableConig.varName') }),
|
||||
})
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}, [t])
|
||||
const handlePayloadChange = useCallback((key: string) => {
|
||||
return (value: any) => {
|
||||
if (key === 'variable') {
|
||||
const { isValid, errorKey, errorMessageKey } = checkKeys([value], true)
|
||||
if (!isValid) {
|
||||
Toast.notify({
|
||||
type: 'error',
|
||||
message: t(`appDebug.varKeyError.${errorMessageKey}`, { key: errorKey }),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
setTempPayload((prev) => {
|
||||
const newPayload = {
|
||||
...prev,
|
||||
@@ -63,19 +64,20 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
||||
return newPayload
|
||||
})
|
||||
}
|
||||
}, [t])
|
||||
}, [])
|
||||
|
||||
const handleVarKeyBlur = useCallback((e: any) => {
|
||||
if (tempPayload.label)
|
||||
const varName = e.target.value
|
||||
if (!checkVariableName(varName) || tempPayload.label)
|
||||
return
|
||||
|
||||
setTempPayload((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
label: e.target.value,
|
||||
label: varName,
|
||||
}
|
||||
})
|
||||
}, [tempPayload])
|
||||
}, [checkVariableName, tempPayload.label])
|
||||
|
||||
const handleConfirm = () => {
|
||||
const moreInfo = tempPayload.variable === payload?.variable
|
||||
@@ -84,10 +86,11 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
||||
type: ChangeType.changeVarName,
|
||||
payload: { beforeKey: payload?.variable || '', afterKey: tempPayload.variable },
|
||||
}
|
||||
if (!tempPayload.variable) {
|
||||
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.varNameRequired') })
|
||||
|
||||
const isVariableNameValid = checkVariableName(tempPayload.variable)
|
||||
if (!isVariableNameValid)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: check if key already exists. should the consider the edit case
|
||||
// if (varKeys.map(key => key?.trim()).includes(tempPayload.variable.trim())) {
|
||||
// Toast.notify({
|
||||
|
||||
Reference in New Issue
Block a user