@@ -14,6 +14,7 @@ interface Props {
14
14
dependentRequired ?: string [ ] ;
15
15
expanded ?: boolean ;
16
16
onlyTitle ?: boolean ;
17
+ isArray ?: boolean ;
17
18
}
18
19
19
20
const SchemaContext = React . createContext ( {
@@ -31,17 +32,22 @@ export const Schema: React.FunctionComponent<Props> = ({
31
32
dependentRequired,
32
33
expanded : propExpanded = false ,
33
34
onlyTitle = false ,
35
+ isArray = false ,
34
36
} ) => {
35
37
const { reverse, deepExpanded } = useContext ( SchemaContext ) ;
36
- const [ expanded , setExpanded ] = useState ( propExpanded ) ;
38
+ const [ expanded , setExpanded ] = useState ( propExpanded || isArray ) ;
37
39
const [ deepExpand , setDeepExpand ] = useState ( false ) ;
38
40
39
41
useEffect ( ( ) => {
40
- setDeepExpand ( deepExpanded ) ;
42
+ if ( ! isArray ) {
43
+ setDeepExpand ( deepExpanded ) ;
44
+ }
41
45
} , [ deepExpanded , setDeepExpand ] ) ;
42
46
43
47
useEffect ( ( ) => {
44
- setExpanded ( deepExpand ) ;
48
+ if ( ! isArray ) {
49
+ setExpanded ( deepExpand ) ;
50
+ }
45
51
} , [ deepExpand , setExpanded ] ) ;
46
52
47
53
if (
@@ -88,7 +94,7 @@ export const Schema: React.FunctionComponent<Props> = ({
88
94
< div >
89
95
< div className = "flex py-2" >
90
96
< div className = { `${ onlyTitle ? '' : 'min-w-1/4' } mr-2` } >
91
- { isExpandable && ! isCircular ? (
97
+ { isExpandable && ! isCircular && ! isArray ? (
92
98
< >
93
99
< CollapseButton
94
100
onClick = { ( ) => setExpanded ( prev => ! prev ) }
@@ -270,7 +276,7 @@ export const Schema: React.FunctionComponent<Props> = ({
270
276
reverse ? 'bg-gray-200' : ''
271
277
} ${ expanded ? 'block' : 'hidden' } `}
272
278
>
273
- < SchemaProperties schema = { schema } />
279
+ < SchemaProperties schema = { schema } isArray = { isArray } />
274
280
< SchemaItems schema = { schema } />
275
281
276
282
{ schema . oneOf ( ) &&
@@ -368,10 +374,12 @@ export const Schema: React.FunctionComponent<Props> = ({
368
374
369
375
interface SchemaPropertiesProps {
370
376
schema : SchemaInterface ;
377
+ isArray : boolean ;
371
378
}
372
379
373
380
const SchemaProperties : React . FunctionComponent < SchemaPropertiesProps > = ( {
374
381
schema,
382
+ isArray,
375
383
} ) => {
376
384
const properties = schema . properties ( ) ;
377
385
if ( properties === undefined || ! Object . keys ( properties ) ) {
@@ -471,17 +479,22 @@ const SchemaItems: React.FunctionComponent<SchemaItemsProps> = ({ schema }) => {
471
479
! Array . isArray ( items ) &&
472
480
Object . keys ( items . properties ( ) || { } ) . length
473
481
) {
474
- return < SchemaProperties schema = { items } /> ;
482
+ return < Schema schema = { items } isArray = { true } /> ;
475
483
} else if ( Array . isArray ( items ) ) {
476
484
return (
477
485
< >
478
486
{ items . map ( ( item , idx ) => (
479
- < Schema schema = { item } schemaName = { `${ idx + 1 } item:` } key = { idx } />
487
+ < Schema
488
+ schema = { item }
489
+ isArray = { true }
490
+ schemaName = { `${ idx + 1 } item:` }
491
+ key = { idx }
492
+ />
480
493
) ) }
481
494
</ >
482
495
) ;
483
496
}
484
- return < Schema schema = { items } schemaName = "Items:" /> ;
497
+ return < Schema schema = { items } isArray = { true } schemaName = "Items:" /> ;
485
498
} ;
486
499
487
500
interface AdditionalItemsProps {
0 commit comments