@@ -14,6 +14,7 @@ interface Props {
1414 dependentRequired ?: string [ ] ;
1515 expanded ?: boolean ;
1616 onlyTitle ?: boolean ;
17+ isArray ?: boolean ;
1718}
1819
1920const SchemaContext = React . createContext ( {
@@ -31,17 +32,22 @@ export const Schema: React.FunctionComponent<Props> = ({
3132 dependentRequired,
3233 expanded : propExpanded = false ,
3334 onlyTitle = false ,
35+ isArray = false ,
3436} ) => {
3537 const { reverse, deepExpanded } = useContext ( SchemaContext ) ;
36- const [ expanded , setExpanded ] = useState ( propExpanded ) ;
38+ const [ expanded , setExpanded ] = useState ( propExpanded || isArray ) ;
3739 const [ deepExpand , setDeepExpand ] = useState ( false ) ;
3840
3941 useEffect ( ( ) => {
40- setDeepExpand ( deepExpanded ) ;
42+ if ( ! isArray ) {
43+ setDeepExpand ( deepExpanded ) ;
44+ }
4145 } , [ deepExpanded , setDeepExpand ] ) ;
4246
4347 useEffect ( ( ) => {
44- setExpanded ( deepExpand ) ;
48+ if ( ! isArray ) {
49+ setExpanded ( deepExpand ) ;
50+ }
4551 } , [ deepExpand , setExpanded ] ) ;
4652
4753 if (
@@ -88,7 +94,7 @@ export const Schema: React.FunctionComponent<Props> = ({
8894 < div >
8995 < div className = "flex py-2" >
9096 < div className = { `${ onlyTitle ? '' : 'min-w-1/4' } mr-2` } >
91- { isExpandable && ! isCircular ? (
97+ { isExpandable && ! isCircular && ! isArray ? (
9298 < >
9399 < CollapseButton
94100 onClick = { ( ) => setExpanded ( prev => ! prev ) }
@@ -270,7 +276,7 @@ export const Schema: React.FunctionComponent<Props> = ({
270276 reverse ? 'bg-gray-200' : ''
271277 } ${ expanded ? 'block' : 'hidden' } `}
272278 >
273- < SchemaProperties schema = { schema } />
279+ < SchemaProperties schema = { schema } isArray = { isArray } />
274280 < SchemaItems schema = { schema } />
275281
276282 { schema . oneOf ( ) &&
@@ -368,10 +374,12 @@ export const Schema: React.FunctionComponent<Props> = ({
368374
369375interface SchemaPropertiesProps {
370376 schema : SchemaInterface ;
377+ isArray : boolean ;
371378}
372379
373380const SchemaProperties : React . FunctionComponent < SchemaPropertiesProps > = ( {
374381 schema,
382+ isArray,
375383} ) => {
376384 const properties = schema . properties ( ) ;
377385 if ( properties === undefined || ! Object . keys ( properties ) ) {
@@ -471,17 +479,22 @@ const SchemaItems: React.FunctionComponent<SchemaItemsProps> = ({ schema }) => {
471479 ! Array . isArray ( items ) &&
472480 Object . keys ( items . properties ( ) || { } ) . length
473481 ) {
474- return < SchemaProperties schema = { items } /> ;
482+ return < Schema schema = { items } isArray = { true } /> ;
475483 } else if ( Array . isArray ( items ) ) {
476484 return (
477485 < >
478486 { 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+ />
480493 ) ) }
481494 </ >
482495 ) ;
483496 }
484- return < Schema schema = { items } schemaName = "Items:" /> ;
497+ return < Schema schema = { items } isArray = { true } schemaName = "Items:" /> ;
485498} ;
486499
487500interface AdditionalItemsProps {
0 commit comments