Skip to content

Commit

Permalink
refactor(json-schema-2020-12): drop optimizeExpansion config option (#…
Browse files Browse the repository at this point in the history
…8612)

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

Refs #8513
  • Loading branch information
char0n authored May 2, 2023
1 parent 71554a7 commit 7bfee4e
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as propTypes from "../../prop-types"
import {
useComponent,
useLevel,
useConfig,
useFn,
useIsEmbedded,
useIsExpandedDeeply,
Expand All @@ -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)
Expand Down Expand Up @@ -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 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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">
Expand Down
8 changes: 0 additions & 8 deletions src/core/plugins/json-schema-2020-12/hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 7bfee4e

Please sign in to comment.