mirror of https://github.com/langgenius/dify.git
chore: improve bool input of start node (#26647)
This commit is contained in:
parent
dbd23f91e5
commit
9cca605bac
|
|
@ -32,6 +32,19 @@ import { TransferMethod } from '@/types/app'
|
|||
import type { FileEntity } from '@/app/components/base/file-uploader/types'
|
||||
|
||||
const TEXT_MAX_LENGTH = 256
|
||||
const CHECKBOX_DEFAULT_TRUE_VALUE = 'true'
|
||||
const CHECKBOX_DEFAULT_FALSE_VALUE = 'false'
|
||||
|
||||
const getCheckboxDefaultSelectValue = (value: InputVar['default']) => {
|
||||
if (typeof value === 'boolean')
|
||||
return value ? CHECKBOX_DEFAULT_TRUE_VALUE : CHECKBOX_DEFAULT_FALSE_VALUE
|
||||
if (typeof value === 'string')
|
||||
return value.toLowerCase() === CHECKBOX_DEFAULT_TRUE_VALUE ? CHECKBOX_DEFAULT_TRUE_VALUE : CHECKBOX_DEFAULT_FALSE_VALUE
|
||||
return CHECKBOX_DEFAULT_FALSE_VALUE
|
||||
}
|
||||
|
||||
const parseCheckboxSelectValue = (value: string) =>
|
||||
value === CHECKBOX_DEFAULT_TRUE_VALUE
|
||||
|
||||
export type IConfigModalProps = {
|
||||
isCreate?: boolean
|
||||
|
|
@ -198,6 +211,8 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
|||
handlePayloadChange('variable')(e.target.value)
|
||||
}, [handlePayloadChange, t])
|
||||
|
||||
const checkboxDefaultSelectValue = useMemo(() => getCheckboxDefaultSelectValue(tempPayload.default), [tempPayload.default])
|
||||
|
||||
const handleConfirm = () => {
|
||||
const moreInfo = tempPayload.variable === payload?.variable
|
||||
? undefined
|
||||
|
|
@ -324,6 +339,23 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
|||
</Field>
|
||||
)}
|
||||
|
||||
{type === InputVarType.checkbox && (
|
||||
<Field title={t('appDebug.variableConfig.defaultValue')}>
|
||||
<SimpleSelect
|
||||
className="w-full"
|
||||
optionWrapClassName="max-h-[140px] overflow-y-auto"
|
||||
items={[
|
||||
{ value: CHECKBOX_DEFAULT_TRUE_VALUE, name: t('appDebug.variableConfig.startChecked') },
|
||||
{ value: CHECKBOX_DEFAULT_FALSE_VALUE, name: t('appDebug.variableConfig.noDefaultSelected') },
|
||||
]}
|
||||
defaultValue={checkboxDefaultSelectValue}
|
||||
onSelect={item => handlePayloadChange('default')(parseCheckboxSelectValue(String(item.value)))}
|
||||
placeholder={t('appDebug.variableConfig.selectDefaultValue')}
|
||||
allowSearch={false}
|
||||
/>
|
||||
</Field>
|
||||
)}
|
||||
|
||||
{type === InputVarType.select && (
|
||||
<>
|
||||
<Field title={t('appDebug.variableConfig.options')}>
|
||||
|
|
|
|||
|
|
@ -235,13 +235,15 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
|||
}
|
||||
}
|
||||
|
||||
if(item.checkbox) {
|
||||
if (item.checkbox) {
|
||||
const preset = initInputs[item.checkbox.variable] === true
|
||||
return {
|
||||
...item.checkbox,
|
||||
default: false,
|
||||
default: preset || item.default || item.checkbox.default,
|
||||
type: 'checkbox',
|
||||
}
|
||||
}
|
||||
|
||||
if (item.select) {
|
||||
const isInputInOptions = item.select.options.includes(initInputs[item.select.variable])
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -195,13 +195,16 @@ export const useEmbeddedChatbot = () => {
|
|||
type: 'number',
|
||||
}
|
||||
}
|
||||
|
||||
if (item.checkbox) {
|
||||
const preset = initInputs[item.checkbox.variable] === true
|
||||
return {
|
||||
...item.checkbox,
|
||||
default: false,
|
||||
default: preset || item.default || item.checkbox.default,
|
||||
type: 'checkbox',
|
||||
}
|
||||
}
|
||||
|
||||
if (item.select) {
|
||||
const isInputInOptions = item.select.options.includes(initInputs[item.select.variable])
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -126,8 +126,8 @@ const Result: FC<IResultProps> = ({
|
|||
|
||||
let hasEmptyInput = ''
|
||||
const requiredVars = prompt_variables?.filter(({ key, name, required, type }) => {
|
||||
if(type === 'boolean')
|
||||
return false // boolean input is not required
|
||||
if(type === 'boolean' || type === 'checkbox')
|
||||
return false // boolean/checkbox input is not required
|
||||
const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null)
|
||||
return res
|
||||
}) || [] // compatible with old version
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ const RunOnce: FC<IRunOnceProps> = ({
|
|||
promptConfig.prompt_variables.forEach((item) => {
|
||||
if (item.type === 'string' || item.type === 'paragraph')
|
||||
newInputs[item.key] = ''
|
||||
else if (item.type === 'checkbox')
|
||||
newInputs[item.key] = false
|
||||
else
|
||||
newInputs[item.key] = undefined
|
||||
})
|
||||
|
|
@ -77,6 +79,8 @@ const RunOnce: FC<IRunOnceProps> = ({
|
|||
newInputs[item.key] = item.default || ''
|
||||
else if (item.type === 'number')
|
||||
newInputs[item.key] = item.default
|
||||
else if (item.type === 'checkbox')
|
||||
newInputs[item.key] = item.default || false
|
||||
else if (item.type === 'file')
|
||||
newInputs[item.key] = item.default
|
||||
else if (item.type === 'file-list')
|
||||
|
|
@ -96,7 +100,7 @@ const RunOnce: FC<IRunOnceProps> = ({
|
|||
{(inputs === null || inputs === undefined || Object.keys(inputs).length === 0) || !isInitialized ? null
|
||||
: promptConfig.prompt_variables.map(item => (
|
||||
<div className='mt-4 w-full' key={item.key}>
|
||||
{item.type !== 'boolean' && (
|
||||
{item.type !== 'checkbox' && (
|
||||
<label className='system-md-semibold flex h-6 items-center text-text-secondary'>{item.name}</label>
|
||||
)}
|
||||
<div className='mt-1'>
|
||||
|
|
@ -134,7 +138,7 @@ const RunOnce: FC<IRunOnceProps> = ({
|
|||
onChange={(e: ChangeEvent<HTMLInputElement>) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
|
||||
/>
|
||||
)}
|
||||
{item.type === 'boolean' && (
|
||||
{item.type === 'checkbox' && (
|
||||
<BoolInput
|
||||
name={item.name || item.key}
|
||||
value={!!inputs[item.key]}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,17 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
|
|||
default: content.default,
|
||||
})
|
||||
}
|
||||
else if (type === 'boolean') {
|
||||
promptVariables.push({
|
||||
key: content.variable,
|
||||
name: content.label,
|
||||
required: content.required,
|
||||
type: 'checkbox',
|
||||
options: [],
|
||||
hide: content.hide,
|
||||
default: content.default,
|
||||
})
|
||||
}
|
||||
else if (type === 'select') {
|
||||
promptVariables.push({
|
||||
key: content.variable,
|
||||
|
|
|
|||
Loading…
Reference in New Issue