feat: support bool type variable frontend (#24437)

Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com>
This commit is contained in:
Joel
2025-08-26 18:16:05 +08:00
committed by GitHub
parent b5c2756261
commit dac72b078d
126 changed files with 3832 additions and 512 deletions

View File

@@ -19,7 +19,7 @@ type Props = {
className?: string
readonly: boolean
payload: InputVar
onChange?: (item: InputVar, moreInfo?: MoreInfo) => void
onChange?: (item: InputVar, moreInfo?: MoreInfo) => boolean
onRemove?: () => void
rightContent?: React.JSX.Element
varKeys?: string[]
@@ -31,7 +31,7 @@ const VarItem: FC<Props> = ({
className,
readonly,
payload,
onChange = noop,
onChange = () => true,
onRemove = noop,
rightContent,
varKeys = [],
@@ -48,7 +48,9 @@ const VarItem: FC<Props> = ({
}] = useBoolean(false)
const handlePayloadChange = useCallback((payload: InputVar, moreInfo?: MoreInfo) => {
onChange(payload, moreInfo)
const isValid = onChange(payload, moreInfo)
if(!isValid)
return
hideEditVarModal()
}, [onChange, hideEditVarModal])
return (

View File

@@ -9,6 +9,8 @@ import { v4 as uuid4 } from 'uuid'
import { ReactSortable } from 'react-sortablejs'
import { RiDraggable } from '@remixicon/react'
import cn from '@/utils/classnames'
import { hasDuplicateStr } from '@/utils/var'
import Toast from '@/app/components/base/toast'
type Props = {
readonly: boolean
@@ -28,7 +30,26 @@ const VarList: FC<Props> = ({
const newList = produce(list, (draft) => {
draft[index] = payload
})
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
}
onChange(newList, moreInfo ? { index, payload: moreInfo } : undefined)
return true
}
}, [list, onChange])