mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-10 06:22:04 +00:00
fix(ui): pre-select backend default for boolean guardrail provider fields
Boolean fields in the auto-generated guardrail provider form (e.g. Noma `use_v2`) rendered as empty Selects because the Form.Item only populated `initialValue` for percentage fields, and the `defaultValue` passed to the Select child was silently dropped by antd's controlled-component wrapper. Users could not tell what the backend default was, and the visual ambiguity made flags like `use_v2` look inoperative even though the save path worked. Unify `initialValue` to fall back through `fieldValue → field.default_value → (percentage ? 0.5 : undefined)`, and switch Select.Option values from "true"/"false" strings to real booleans so the backend default flows through without stringification.
This commit is contained in:
@@ -157,10 +157,10 @@ const GuardrailProviderFields: React.FC<GuardrailProviderFieldsProps> = ({
|
||||
);
|
||||
}
|
||||
|
||||
const percentageInitialValue =
|
||||
field.type === "percentage" && (fieldValue === undefined || fieldValue === null)
|
||||
? (field.default_value ?? 0.5)
|
||||
: undefined;
|
||||
const resolvedInitialValue =
|
||||
fieldValue !== undefined
|
||||
? fieldValue
|
||||
: (field.default_value ?? (field.type === "percentage" ? 0.5 : undefined));
|
||||
|
||||
return (
|
||||
<Form.Item
|
||||
@@ -169,7 +169,7 @@ const GuardrailProviderFields: React.FC<GuardrailProviderFieldsProps> = ({
|
||||
label={fieldKey}
|
||||
tooltip={field.description}
|
||||
rules={field.required ? [{ required: true, message: `${fieldKey} is required` }] : undefined}
|
||||
initialValue={percentageInitialValue}
|
||||
initialValue={resolvedInitialValue}
|
||||
>
|
||||
{field.type === "select" && field.options ? (
|
||||
<Select placeholder={field.description} defaultValue={fieldValue || field.default_value}>
|
||||
@@ -188,12 +188,9 @@ const GuardrailProviderFields: React.FC<GuardrailProviderFieldsProps> = ({
|
||||
))}
|
||||
</Select>
|
||||
) : field.type === "bool" || field.type === "boolean" ? (
|
||||
<Select
|
||||
placeholder={field.description}
|
||||
defaultValue={fieldValue !== undefined ? String(fieldValue) : field.default_value}
|
||||
>
|
||||
<Select.Option value="true">True</Select.Option>
|
||||
<Select.Option value="false">False</Select.Option>
|
||||
<Select placeholder={field.description}>
|
||||
<Select.Option value={true}>True</Select.Option>
|
||||
<Select.Option value={false}>False</Select.Option>
|
||||
</Select>
|
||||
) : field.type === "percentage" && field.min != null && field.max != null ? (
|
||||
<Slider
|
||||
|
||||
Reference in New Issue
Block a user