fix(loop-variables): validate variable name input (#21888)
This commit is contained in:
parent
a79f37b686
commit
317d287458
1 changed files with 18 additions and 0 deletions
|
|
@ -10,6 +10,8 @@ import type {
|
||||||
LoopVariable,
|
LoopVariable,
|
||||||
LoopVariablesComponentShape,
|
LoopVariablesComponentShape,
|
||||||
} from '@/app/components/workflow/nodes/loop/types'
|
} from '@/app/components/workflow/nodes/loop/types'
|
||||||
|
import { checkKeys, replaceSpaceWithUnderscreInVarNameInput } from '@/utils/var'
|
||||||
|
import Toast from '@/app/components/base/toast'
|
||||||
|
|
||||||
type ItemProps = {
|
type ItemProps = {
|
||||||
item: LoopVariable
|
item: LoopVariable
|
||||||
|
|
@ -21,7 +23,22 @@ const Item = ({
|
||||||
handleUpdateLoopVariable,
|
handleUpdateLoopVariable,
|
||||||
}: ItemProps) => {
|
}: ItemProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
const checkVariableName = (value: string) => {
|
||||||
|
const { isValid, errorMessageKey } = checkKeys([value], false)
|
||||||
|
if (!isValid) {
|
||||||
|
Toast.notify({
|
||||||
|
type: 'error',
|
||||||
|
message: t(`appDebug.varKeyError.${errorMessageKey}`, { key: t('workflow.env.modal.name') }),
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
const handleUpdateItemLabel = useCallback((e: any) => {
|
const handleUpdateItemLabel = useCallback((e: any) => {
|
||||||
|
replaceSpaceWithUnderscreInVarNameInput(e.target)
|
||||||
|
if (!!e.target.value && !checkVariableName(e.target.value))
|
||||||
|
return
|
||||||
handleUpdateLoopVariable(item.id, { label: e.target.value })
|
handleUpdateLoopVariable(item.id, { label: e.target.value })
|
||||||
}, [item.id, handleUpdateLoopVariable])
|
}, [item.id, handleUpdateLoopVariable])
|
||||||
|
|
||||||
|
|
@ -44,6 +61,7 @@ const Item = ({
|
||||||
<Input
|
<Input
|
||||||
value={item.label}
|
value={item.label}
|
||||||
onChange={handleUpdateItemLabel}
|
onChange={handleUpdateItemLabel}
|
||||||
|
onBlur={e => checkVariableName(e.target.value)}
|
||||||
autoFocus={!item.label}
|
autoFocus={!item.label}
|
||||||
placeholder={t('workflow.nodes.loop.variableName')}
|
placeholder={t('workflow.nodes.loop.variableName')}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue