6
6
Response ,
7
7
Parameter ,
8
8
Request ,
9
- Diagnostics
9
+ Diagnostics ,
10
+ NullHCLString
10
11
} from "./types/preview" ;
11
12
import { Select , SelectTrigger , SelectValue , SelectContent , SelectGroup , SelectItem } from "./components/Select/Select" ;
12
13
import { Input } from "./components/Input/Input" ;
@@ -48,6 +49,10 @@ export function DynamicForm() {
48
49
fetchError
49
50
} = useDirectories ( serverAddress , urlTestdata ) ;
50
51
52
+ const parameterValue = ( value : NullHCLString ) => {
53
+ return value . valid ? value . value : "" ;
54
+ }
55
+
51
56
const handleTestdataChange = ( value : string ) => {
52
57
reset ( { } ) ;
53
58
setPrevValues ( { } ) ;
@@ -113,9 +118,7 @@ export function DynamicForm() {
113
118
if ( response ?. parameters ) {
114
119
const defaultValues : Record < string , string > = { } ;
115
120
response . parameters . forEach ( ( param ) => {
116
- // If the server-sent param.Value is empty, we can fall back to `default_value`
117
- defaultValues [ param . name ] =
118
- param . value . value || param . default_value . value || "" ;
121
+ defaultValues [ param . name ] = parameterValue ( param . value ) ;
119
122
} ) ;
120
123
121
124
// Use RHF's `reset` to update the entire form
@@ -194,7 +197,7 @@ export function DynamicForm() {
194
197
render = { ( { field } ) => (
195
198
< Select
196
199
onValueChange = { field . onChange }
197
- defaultValue = { param . default_value . value }
200
+ defaultValue = { parameterValue ( param . default_value ) }
198
201
>
199
202
< SelectTrigger className = "w-[300px]" >
200
203
< SelectValue placeholder = { param . description } />
@@ -204,7 +207,7 @@ export function DynamicForm() {
204
207
{ ( param . options || [ ] ) . map ( ( option , idx ) => {
205
208
if ( ! option ) return null ;
206
209
return (
207
- < SelectItem key = { idx } value = { option . value . value } > { option . name } </ SelectItem >
210
+ < SelectItem key = { idx } value = { parameterValue ( option . value ) } > { option . name } </ SelectItem >
208
211
) ;
209
212
} ) }
210
213
</ SelectGroup >
@@ -234,7 +237,7 @@ export function DynamicForm() {
234
237
} }
235
238
onChange = { ( selectedOptions ) => {
236
239
const values = selectedOptions . map ( opt => opt . value ) . join ( ',' ) ;
237
- field . onChange ( values ) ;
240
+ field . onChange ( JSON . stringify ( values ) ) ;
238
241
} }
239
242
options = { param . options ?. map ( opt => ( {
240
243
value : opt ?. value ?. value || '' ,
@@ -264,17 +267,16 @@ export function DynamicForm() {
264
267
{ param . display_name || param . name }
265
268
{ param . icon && < img src = { param . icon } alt = "" style = { { marginLeft : 6 } } /> }
266
269
</ label >
267
- < output className = "text-sm font-medium tabular-nums" > { param . value . value } </ output >
270
+ < output className = "text-sm font-medium tabular-nums" > { parameterValue ( param . value ) } </ output >
268
271
</ div >
269
272
{ param . description && < div className = "text-sm" > { param . description } </ div > }
270
273
< Controller
271
274
name = { param . name }
272
275
control = { methods . control }
273
276
render = { ( { field } ) => (
274
277
< div className = "w-[300px]" >
275
- < Slider defaultValue = { param . default_value ? [ Number ( param . default_value ) ] : [ 0 ] } max = { param . validations [ 0 ] . validation_max || undefined } min = { param . validations [ 0 ] . validation_min || undefined } step = { 1 }
278
+ < Slider defaultValue = { param ? .default_value ?. value ? [ Number ( param . default_value . value ) ] : [ 0 ] } max = { param . validations [ 0 ] . validation_max || undefined } min = { param . validations [ 0 ] . validation_min || undefined } step = { 1 }
276
279
onValueChange = { ( value ) => {
277
- console . log ( "value" , value [ 0 ] . toString ( ) ) ;
278
280
field . onChange ( value [ 0 ] . toString ( ) ) ;
279
281
} } />
280
282
</ div >
@@ -290,21 +292,21 @@ export function DynamicForm() {
290
292
{ param . display_name || param . name }
291
293
{ param . icon && < img src = { param . icon } alt = "" style = { { marginLeft : 6 } } /> }
292
294
</ label >
293
- < output className = "text-sm font-medium tabular-nums" > { param . value . value } </ output >
295
+ < output className = "text-sm font-medium tabular-nums" > { parameterValue ( param . value ) } </ output >
294
296
</ div >
295
297
{ param . description && < div className = "text-sm" > { param . description } </ div > }
296
298
< Controller
297
299
name = { param . name }
298
300
control = { methods . control }
299
301
render = { ( { field } ) => (
300
302
< div className = "w-[300px]" >
301
- < RadioGroup defaultValue = { param . default_value . value } onValueChange = { field . onChange } >
303
+ < RadioGroup defaultValue = { parameterValue ( param . default_value ) } onValueChange = { field . onChange } >
302
304
{ ( param . options || [ ] ) . map ( ( option , idx ) => {
303
305
if ( ! option ) return null ;
304
306
return (
305
307
< div key = { idx } className = "flex items-center space-x-2" >
306
- < RadioGroupItem value = { option . value . value } id = { option . value . value } />
307
- < Label htmlFor = { option . value . value } > { option . name } </ Label >
308
+ < RadioGroupItem value = { parameterValue ( option . value ) } id = { parameterValue ( option . value ) } />
309
+ < Label htmlFor = { parameterValue ( option . value ) } > { option . name } </ Label >
308
310
</ div >
309
311
) ;
310
312
} ) }
@@ -333,7 +335,7 @@ export function DynamicForm() {
333
335
render = { ( { field } ) => (
334
336
< Select
335
337
onValueChange = { field . onChange }
336
- defaultValue = { param . value . value }
338
+ defaultValue = { parameterValue ( param . value ) }
337
339
>
338
340
< SelectTrigger className = "w-[300px]" >
339
341
< SelectValue placeholder = { param . description } />
@@ -343,7 +345,7 @@ export function DynamicForm() {
343
345
{ ( param . options || [ ] ) . map ( ( option , idx ) => {
344
346
if ( ! option ) return null ;
345
347
return (
346
- < SelectItem key = { idx } value = { option . value . value } > { option . name } </ SelectItem >
348
+ < SelectItem key = { idx } value = { parameterValue ( option . value ) } > { option . name } </ SelectItem >
347
349
) ;
348
350
} ) }
349
351
</ SelectGroup >
@@ -374,7 +376,7 @@ export function DynamicForm() {
374
376
className = "w-[300px]"
375
377
type = { mapParamTypeToInputType ( param . type ) }
376
378
value = { field . value }
377
- defaultValue = { param . default_value . value }
379
+ defaultValue = { parameterValue ( param . default_value ) }
378
380
/>
379
381
) }
380
382
/>
0 commit comments