refactor(json-schema-2020-12): drop optimizeExpansion config option (#8612)

This option was removed and codebase has been
modified in a way as this option is always true.

Refs #8513
This commit is contained in:
Vladimír Gorej
2023-05-02 17:03:01 +02:00
committed by GitHub
parent 71554a7330
commit 7bfee4e492
8 changed files with 13 additions and 49 deletions

View File

@@ -9,7 +9,6 @@ import * as propTypes from "../../prop-types"
import {
useComponent,
useLevel,
useConfig,
useFn,
useIsEmbedded,
useIsExpandedDeeply,
@@ -24,7 +23,6 @@ import {
const JSONSchema = forwardRef(({ schema, name }, ref) => {
const fn = useFn()
const config = useConfig()
const isExpandedDeeply = useIsExpandedDeeply()
const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false)
@@ -127,7 +125,7 @@ const JSONSchema = forwardRef(({ schema, name }, ref) => {
"json-schema-2020-12-body--collapsed": !expanded,
})}
>
{!expanded && config.optimizeExpansion ? null : (
{expanded && (
<>
<KeywordDescription schema={schema} />
{!isCircular && isExpandable && (

View File

@@ -5,12 +5,11 @@ import React, { useCallback, useState } from "react"
import classNames from "classnames"
import { schema } from "../../prop-types"
import { useConfig, useComponent, useIsExpandedDeeply } from "../../hooks"
import { useComponent, useIsExpandedDeeply } from "../../hooks"
import { JSONSchemaDeepExpansionContext } from "../../context"
const $defs = ({ schema }) => {
const $defs = schema?.$defs || {}
const config = useConfig()
const isExpandedDeeply = useIsExpandedDeeply()
const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false)
@@ -51,7 +50,7 @@ const $defs = ({ schema }) => {
"json-schema-2020-12-keyword__children--collapsed": !expanded,
})}
>
{!expanded && config.optimizeExpansion ? null : (
{expanded && (
<>
{Object.entries($defs).map(([schemaName, schema]) => (
<li key={schemaName} className="json-schema-2020-12-property">

View File

@@ -5,18 +5,12 @@ import React, { useCallback, useState } from "react"
import classNames from "classnames"
import { schema } from "../../prop-types"
import {
useFn,
useConfig,
useComponent,
useIsExpandedDeeply,
} from "../../hooks"
import { useFn, useComponent, useIsExpandedDeeply } from "../../hooks"
import { JSONSchemaDeepExpansionContext } from "../../context"
const AllOf = ({ schema }) => {
const allOf = schema?.allOf || []
const fn = useFn()
const config = useConfig()
const isExpandedDeeply = useIsExpandedDeeply()
const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false)
@@ -58,7 +52,7 @@ const AllOf = ({ schema }) => {
"json-schema-2020-12-keyword__children--collapsed": !expanded,
})}
>
{!expanded && config.optimizeExpansion ? null : (
{expanded && (
<>
{allOf.map((schema, index) => (
<li key={`#${index}`} className="json-schema-2020-12-property">

View File

@@ -5,18 +5,12 @@ import React, { useCallback, useState } from "react"
import classNames from "classnames"
import { schema } from "../../prop-types"
import {
useFn,
useConfig,
useComponent,
useIsExpandedDeeply,
} from "../../hooks"
import { useFn, useComponent, useIsExpandedDeeply } from "../../hooks"
import { JSONSchemaDeepExpansionContext } from "../../context"
const AnyOf = ({ schema }) => {
const anyOf = schema?.anyOf || []
const fn = useFn()
const config = useConfig()
const isExpandedDeeply = useIsExpandedDeeply()
const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false)
@@ -58,7 +52,7 @@ const AnyOf = ({ schema }) => {
"json-schema-2020-12-keyword__children--collapsed": !expanded,
})}
>
{!expanded && config.optimizeExpansion ? null : (
{expanded && (
<>
{anyOf.map((schema, index) => (
<li key={`#${index}`} className="json-schema-2020-12-property">

View File

@@ -5,12 +5,11 @@ import React, { useCallback, useState } from "react"
import classNames from "classnames"
import { schema } from "../../prop-types"
import { useConfig, useComponent, useIsExpandedDeeply } from "../../hooks"
import { useComponent, useIsExpandedDeeply } from "../../hooks"
import { JSONSchemaDeepExpansionContext } from "../../context"
const DependentSchemas = ({ schema }) => {
const dependentSchemas = schema?.dependentSchemas || []
const config = useConfig()
const isExpandedDeeply = useIsExpandedDeeply()
const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false)
@@ -50,7 +49,7 @@ const DependentSchemas = ({ schema }) => {
"json-schema-2020-12-keyword__children--collapsed": !expanded,
})}
>
{!expanded && config.optimizeExpansion ? null : (
{expanded && (
<>
{Object.entries(dependentSchemas).map(([schemaName, schema]) => (
<li key={schemaName} className="json-schema-2020-12-property">

View File

@@ -5,18 +5,12 @@ import React, { useCallback, useState } from "react"
import classNames from "classnames"
import { schema } from "../../prop-types"
import {
useFn,
useConfig,
useComponent,
useIsExpandedDeeply,
} from "../../hooks"
import { useFn, useComponent, useIsExpandedDeeply } from "../../hooks"
import { JSONSchemaDeepExpansionContext } from "../../context"
const OneOf = ({ schema }) => {
const oneOf = schema?.oneOf || []
const fn = useFn()
const config = useConfig()
const isExpandedDeeply = useIsExpandedDeeply()
const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false)
@@ -58,7 +52,7 @@ const OneOf = ({ schema }) => {
"json-schema-2020-12-keyword__children--collapsed": !expanded,
})}
>
{!expanded && config.optimizeExpansion ? null : (
{expanded && (
<>
{oneOf.map((schema, index) => (
<li key={`#${index}`} className="json-schema-2020-12-property">

View File

@@ -5,18 +5,12 @@ import React, { useCallback, useState } from "react"
import classNames from "classnames"
import { schema } from "../../prop-types"
import {
useFn,
useConfig,
useComponent,
useIsExpandedDeeply,
} from "../../hooks"
import { useFn, useComponent, useIsExpandedDeeply } from "../../hooks"
import { JSONSchemaDeepExpansionContext } from "../../context"
const PrefixItems = ({ schema }) => {
const prefixItems = schema?.prefixItems || []
const fn = useFn()
const config = useConfig()
const isExpandedDeeply = useIsExpandedDeeply()
const [expanded, setExpanded] = useState(isExpandedDeeply)
const [expandedDeeply, setExpandedDeeply] = useState(false)
@@ -58,7 +52,7 @@ const PrefixItems = ({ schema }) => {
"json-schema-2020-12-keyword__children--collapsed": !expanded,
})}
>
{!expanded && config.optimizeExpansion ? null : (
{expanded && (
<>
{prefixItems.map((schema, index) => (
<li key={`#${index}`} className="json-schema-2020-12-property">

View File

@@ -97,14 +97,6 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
* 3 -> [0]...(3)
*/
defaultExpandedLevels: 0, // 2 = 0...2
/**
* Can be turned on for complex and extensive schemas.
* Child schemas are not rendered until parent schema is expanded.
*
* By default, entire schema tree is rendered and collapsed parts of the
* tree are hidden with css.
*/
optimizeExpansion: true,
...overrides.config,
},
fn: {