MCPcopy Create free account
hub / github.com/bytebase/dbhub / ParameterInput

Function ParameterInput

frontend/src/components/tool/ParameterForm.tsx:49–131  ·  view source on GitHub ↗
({ parameter, value, onChange }: ParameterInputProps)

Source from the content-addressed store, hash-verified

47}
48
49function ParameterInput({ parameter, value, onChange }: ParameterInputProps) {
50 const { type, name } = parameter;
51
52 // Boolean type: checkbox
53 if (type === 'boolean') {
54 const [localChecked, setLocalChecked] = useState<boolean>(value === true || value === 'true');
55
56 // Sync local state when value prop changes
57 useEffect(() => {
58 const newChecked = value === true || value === 'true';
59 setLocalChecked(newChecked);
60 }, [value]);
61
62 return (
63 <div className="flex items-center h-10">
64 <Checkbox
65 checked={localChecked}
66 onCheckedChange={(checked) => {
67 setLocalChecked(checked);
68 onChange(checked);
69 }}
70 />
71 </div>
72 );
73 }
74
75 // Integer type: number input with step=1
76 if (type === 'integer') {
77 return (
78 <Input
79 type="number"
80 step={1}
81 value={value ?? ''}
82 onChange={(e) => {
83 const val = e.target.value;
84 onChange(val === '' ? undefined : parseInt(val, 10));
85 }}
86 placeholder={`Enter ${name}`}
87 />
88 );
89 }
90
91 // Float type: number input with step=any
92 if (type === 'float' || type === 'number') {
93 return (
94 <Input
95 type="number"
96 step="any"
97 value={value ?? ''}
98 onChange={(e) => {
99 const val = e.target.value;
100 onChange(val === '' ? undefined : parseFloat(val));
101 }}
102 placeholder={`Enter ${name}`}
103 />
104 );
105 }
106

Callers

nothing calls this directly

Calls 1

onChangeFunction · 0.85

Tested by

no test coverage detected