Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor: update radio component to handle boolean values instead of numeric (#24956)

17hz2ac8f8003f03
diff --git a/web/app/components/base/form/components/base/base-field.tsx b/web/app/components/base/form/components/base/base-field.tsx
index 35ca251a5b2..c909eedc871 100644
--- a/web/app/components/base/form/components/base/base-field.tsx
+++ b/web/app/components/base/form/components/base/base-field.tsx
@@ -103,12 +103,6 @@ const BaseField = ({
})
}, [values, show_on])
- const booleanRadioValue = useMemo(() => {
- if (value === null || value === undefined)
- return undefined
- return value ? 1 : 0
- }, [value])
-
if (!show)
return null
@@ -215,11 +209,11 @@ const BaseField = ({
formSchema.type === FormTypeEnum.boolean && (
<Radio.Group
className='flex w-fit items-center'
- value={booleanRadioValue}
- onChange={val => field.handleChange(val === 1)}
+ value={value}
+ onChange={v => field.handleChange(v)}
>
- <Radio value={1} className='!mr-1'>True</Radio>
- <Radio value={0}>False</Radio>
+ <Radio value={true} className='!mr-1'>True</Radio>
+ <Radio value={false}>False</Radio>
</Radio.Group>
)
}
diff --git a/web/app/components/base/radio/component/group/index.tsx b/web/app/components/base/radio/component/group/index.tsx
index 7ead2f9d886..8bc90e2b1b4 100644
--- a/web/app/components/base/radio/component/group/index.tsx
+++ b/web/app/components/base/radio/component/group/index.tsx
@@ -5,7 +5,7 @@ import cn from '@/utils/classnames'
export type TRadioGroupProps = {
children?: ReactNode | ReactNode[]
- value?: string | number
+ value?: string | number | boolean
className?: string
onChange?: (value: any) => void
}
diff --git a/web/app/components/base/radio/component/radio/index.tsx b/web/app/components/base/radio/component/radio/index.tsx
index aa4e6d0c7f5..3f94e8b33fd 100644
--- a/web/app/components/base/radio/component/radio/index.tsx
+++ b/web/app/components/base/radio/component/radio/index.tsx
@@ -10,7 +10,7 @@ export type IRadioProps = {
labelClassName?: string
children?: string | ReactNode
checked?: boolean
- value?: string | number
+ value?: string | number | boolean
disabled?: boolean
onChange?: (e?: IRadioProps['value']) => void
}
diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx
index 3b3527a9fdc..7c259f1a788 100644
--- a/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx
+++ b/web/app/components/header/account-setting/model-provider-page/model-modal/Form.tsx
@@ -284,11 +284,11 @@ function Form<
</div>
<Radio.Group
className='flex items-center'
- value={value[variable] === null ? undefined : (value[variable] ? 1 : 0)}
- onChange={val => handleFormChange(variable, val === 1)}
+ value={value[variable]}
+ onChange={val => handleFormChange(variable, val)}
>
- <Radio value={1} className='!mr-1'>True</Radio>
- <Radio value={0}>False</Radio>
+ <Radio value={true} className='!mr-1'>True</Radio>
+ <Radio value={false}>False</Radio>
</Radio.Group>
</div>
{fieldMoreInfo?.(formSchema)}
diff --git a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx
index 719817152d9..f7f12682128 100644
--- a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx
+++ b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx
@@ -91,8 +91,8 @@ const ParameterItem: FC<ParameterItemProps> = ({
numberInputRef.current!.value = `${num}`
}
- const handleRadioChange = (v: number) => {
- handleInputChange(v === 1)
+ const handleRadioChange = (v: boolean) => {
+ handleInputChange(v)
}
const handleStringInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
@@ -187,11 +187,11 @@ const ParameterItem: FC<ParameterItemProps> = ({
return (
<Radio.Group
className='flex w-[178px] items-center'
- value={renderValue ? 1 : 0}
+ value={renderValue as boolean}
onChange={handleRadioChange}
>
- <Radio value={1} className='w-[83px]'>True</Radio>
- <Radio value={0} className='w-[83px]'>False</Radio>
+ <Radio value={true} className='w-[83px]'>True</Radio>
+ <Radio value={false} className='w-[83px]'>False</Radio>
</Radio.Group>
)
}