@@ -173,26 +173,35 @@ const ParameterField: FC<ParameterFieldProps> = ({
173
173
< SelectValue placeholder = "Select option" />
174
174
</ SelectTrigger >
175
175
< SelectContent >
176
- { parameter . options . map ( ( option ) => (
177
- < SelectItem key = { option . value . value } value = { option . value . value } >
178
- < OptionDisplay option = { option } />
179
- </ SelectItem >
180
- ) ) }
176
+ { parameter . options
177
+ . filter (
178
+ ( option ) : option is NonNullable < typeof option > =>
179
+ option !== null ,
180
+ )
181
+ . map ( ( option ) => (
182
+ < SelectItem key = { option . value . value } value = { option . value . value } >
183
+ < OptionDisplay option = { option } />
184
+ </ SelectItem >
185
+ ) ) }
181
186
</ SelectContent >
182
187
</ Select >
183
188
) ;
184
189
185
190
case "multi-select" : {
186
191
// Map parameter options to MultiSelectCombobox options format
187
- const comboboxOptions : Option [ ] = parameter . options . map ( ( opt ) => ( {
188
- value : opt . value . value ,
189
- label : opt . name ,
190
- disable : false ,
191
- } ) ) ;
192
+ const comboboxOptions : Option [ ] = parameter . options
193
+ . filter ( ( opt ) : opt is NonNullable < typeof opt > => opt !== null )
194
+ . map ( ( opt ) => ( {
195
+ value : opt . value . value ,
196
+ label : opt . name ,
197
+ disable : false ,
198
+ } ) ) ;
192
199
193
200
const defaultOptions : Option [ ] = JSON . parse ( defaultValue ) . map (
194
201
( val : string ) => {
195
- const option = parameter . options . find ( ( o ) => o . value . value === val ) ;
202
+ const option = parameter . options
203
+ . filter ( ( o ) : o is NonNullable < typeof o > => o !== null )
204
+ . find ( ( o ) => o . value . value === val ) ;
196
205
return {
197
206
value : val ,
198
207
label : option ?. name || val ,
@@ -242,20 +251,24 @@ const ParameterField: FC<ParameterFieldProps> = ({
242
251
disabled = { disabled }
243
252
defaultValue = { defaultValue }
244
253
>
245
- { parameter . options . map ( ( option ) => (
246
- < div
247
- key = { option . value . value }
248
- className = "flex items-center space-x-2"
249
- >
250
- < RadioGroupItem
251
- id = { option . value . value }
252
- value = { option . value . value }
253
- />
254
- < Label htmlFor = { option . value . value } className = "cursor-pointer" >
255
- < OptionDisplay option = { option } />
256
- </ Label >
257
- </ div >
258
- ) ) }
254
+ { parameter . options
255
+ . filter (
256
+ ( option ) : option is NonNullable < typeof option > => option !== null ,
257
+ )
258
+ . map ( ( option ) => (
259
+ < div
260
+ key = { option . value . value }
261
+ className = "flex items-center space-x-2"
262
+ >
263
+ < RadioGroupItem
264
+ id = { option . value . value }
265
+ value = { option . value . value }
266
+ />
267
+ < Label htmlFor = { option . value . value } className = "cursor-pointer" >
268
+ < OptionDisplay option = { option } />
269
+ </ Label >
270
+ </ div >
271
+ ) ) }
259
272
</ RadioGroup >
260
273
) ;
261
274
@@ -281,7 +294,10 @@ const ParameterField: FC<ParameterFieldProps> = ({
281
294
const inputProps : Record < string , unknown > = { } ;
282
295
283
296
if ( parameter . type === "number" ) {
284
- const validations = parameter . validations [ 0 ] || { } ;
297
+ const validations =
298
+ parameter . validations . filter (
299
+ ( v ) : v is NonNullable < typeof v > => v !== null ,
300
+ ) [ 0 ] || { } ;
285
301
const { validation_min, validation_max } = validations ;
286
302
287
303
if ( validation_min !== null ) {
@@ -349,19 +365,24 @@ const ParameterDiagnostics: FC<ParameterDiagnosticsProps> = ({
349
365
} ) => {
350
366
return (
351
367
< div className = "flex flex-col gap-2" >
352
- { diagnostics . map ( ( diagnostic , index ) => (
353
- < div
354
- key = { `diagnostic-${ diagnostic . summary } -${ index } ` }
355
- className = { `text-xs px-1 ${
356
- diagnostic . severity === "error"
357
- ? "text-content-destructive"
358
- : "text-content-warning"
359
- } `}
360
- >
361
- < div className = "font-medium" > { diagnostic . summary } </ div >
362
- { diagnostic . detail && < div > { diagnostic . detail } </ div > }
363
- </ div >
364
- ) ) }
368
+ { diagnostics
369
+ . filter (
370
+ ( diagnostic ) : diagnostic is NonNullable < typeof diagnostic > =>
371
+ diagnostic !== null ,
372
+ )
373
+ . map ( ( diagnostic , index ) => (
374
+ < div
375
+ key = { `diagnostic-${ diagnostic . summary } -${ index } ` }
376
+ className = { `text-xs px-1 ${
377
+ diagnostic . severity === "error"
378
+ ? "text-content-destructive"
379
+ : "text-content-warning"
380
+ } `}
381
+ >
382
+ < div className = "font-medium" > { diagnostic . summary } </ div >
383
+ { diagnostic . detail && < div > { diagnostic . detail } </ div > }
384
+ </ div >
385
+ ) ) }
365
386
</ div >
366
387
) ;
367
388
} ;
@@ -433,12 +454,12 @@ export const useValidationSchemaForDynamicParameters = (
433
454
if ( parameter ) {
434
455
switch ( parameter . type ) {
435
456
case "number" : {
436
- const minValidation = parameter . validations . find (
437
- ( v ) => v . validation_min !== null ,
438
- ) ;
439
- const maxValidation = parameter . validations . find (
440
- ( v ) => v . validation_max !== null ,
441
- ) ;
457
+ const minValidation = parameter . validations
458
+ . filter ( ( v ) : v is NonNullable < typeof v > => v !== null )
459
+ . find ( ( v ) => v . validation_min !== null ) ;
460
+ const maxValidation = parameter . validations
461
+ . filter ( ( v ) : v is NonNullable < typeof v > => v !== null )
462
+ . find ( ( v ) => v . validation_max !== null ) ;
442
463
443
464
if (
444
465
minValidation &&
@@ -547,15 +568,15 @@ const parameterError = (
547
568
parameter : PreviewParameter ,
548
569
value ?: string ,
549
570
) : string | undefined => {
550
- const validation_error = parameter . validations . find (
551
- ( v ) => v . validation_error !== null ,
552
- ) ;
553
- const minValidation = parameter . validations . find (
554
- ( v ) => v . validation_min !== null ,
555
- ) ;
556
- const maxValidation = parameter . validations . find (
557
- ( v ) => v . validation_max !== null ,
558
- ) ;
571
+ const validation_error = parameter . validations
572
+ . filter ( ( v ) : v is NonNullable < typeof v > => v !== null )
573
+ . find ( ( v ) => v . validation_error !== null ) ;
574
+ const minValidation = parameter . validations
575
+ . filter ( ( v ) : v is NonNullable < typeof v > => v !== null )
576
+ . find ( ( v ) => v . validation_min !== null ) ;
577
+ const maxValidation = parameter . validations
578
+ . filter ( ( v ) : v is NonNullable < typeof v > => v !== null )
579
+ . find ( ( v ) => v . validation_max !== null ) ;
559
580
560
581
if ( ! validation_error || ! value ) {
561
582
return ;
0 commit comments