import React from 'react' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Checkbox } from '@/components/ui/checkbox' import { getBackendFieldType, basicBackendFieldsConfig } from '@/lib/zodFormUtils' import ExtraArgsInput from '@/components/form/ExtraArgsInput' interface BackendFormFieldProps { fieldKey: string value: string | number | boolean | string[] | Record | undefined onChange: (key: string, value: string | number | boolean | string[] | Record | undefined) => void } const BackendFormField: React.FC = ({ fieldKey, value, onChange }) => { // Special handling for extra_args if (fieldKey === 'extra_args') { return ( | undefined} onChange={(newValue) => onChange(fieldKey, newValue)} description="Additional command line arguments to pass to the backend" /> ) } // Get configuration for basic fields, or use field name for advanced fields const config = basicBackendFieldsConfig[fieldKey] || { label: fieldKey } // Get type from Zod schema const fieldType = getBackendFieldType(fieldKey) const handleChange = (newValue: string | number | boolean | string[] | undefined) => { onChange(fieldKey, newValue) } const renderField = () => { switch (fieldType) { case 'boolean': return (
handleChange(checked)} />
) case 'number': return (
{ const numValue = e.target.value ? parseFloat(e.target.value) : undefined // Only update if the parsed value is valid or the input is empty if (e.target.value === '' || (numValue !== undefined && !isNaN(numValue))) { handleChange(numValue) } }} placeholder={config.placeholder} /> {config.description && (

{config.description}

)}
) case 'array': return (
{ const arrayValue = e.target.value ? e.target.value.split(',').map(s => s.trim()).filter(Boolean) : undefined handleChange(arrayValue) }} placeholder="item1, item2, item3" /> {config.description && (

{config.description}

)}

Separate multiple values with commas

) case 'text': default: return (
handleChange(e.target.value || undefined)} placeholder={config.placeholder} /> {config.description && (

{config.description}

)}
) } } return
{renderField()}
} export default BackendFormField