-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-schema-2020-12): add support for defs keyword
Refs #8513
- Loading branch information
Showing
11 changed files
with
117 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/core/plugins/json-schema-2020-12/components/keywords/$defs/$defs.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React, { useCallback, useState } from "react" | ||
|
||
import { schema } from "../../../prop-types" | ||
import { useComponent, useIsExpandedDeeply } from "../../../hooks" | ||
|
||
const $defs = ({ schema }) => { | ||
const $defs = schema?.$defs || {} | ||
|
||
if (Object.keys($defs).length === 0) { | ||
return null | ||
} | ||
|
||
const isExpandedDeeply = useIsExpandedDeeply() | ||
const [expanded, setExpanded] = useState(isExpandedDeeply) | ||
const Accordion = useComponent("Accordion") | ||
const JSONSchema = useComponent("JSONSchema") | ||
|
||
const handleExpansion = useCallback(() => { | ||
setExpanded((prev) => !prev) | ||
}, []) | ||
|
||
return ( | ||
<div className="json-schema-2020-12__$defs"> | ||
<Accordion expanded={expanded} onChange={handleExpansion}> | ||
<span className="json-schema-2020-12-core-keyword">$defs</span> | ||
<span className="json-schema-2020-12__type">object</span> | ||
</Accordion> | ||
{expanded && ( | ||
<ul> | ||
{Object.entries($defs).map(([schemaName, schema]) => ( | ||
<li key={schemaName} className="json-schema-2020-12-$def"> | ||
<JSONSchema name={schemaName} schema={schema} /> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
$defs.propTypes = { | ||
schema: schema.isRequired, | ||
} | ||
|
||
export default $defs |
13 changes: 13 additions & 0 deletions
13
src/core/plugins/json-schema-2020-12/components/keywords/$defs/_$defs.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.json-schema-2020-12 { | ||
&__\$defs { | ||
& ul { | ||
padding: 0; | ||
margin: 0 0 0 20px; | ||
border-left: 1px dashed rgba($section-models-model-container-background-color, 0.1); | ||
} | ||
} | ||
|
||
&-\$def { | ||
@extend .json-schema-2020-12-property; | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
src/core/plugins/json-schema-2020-12/components/keywords/Properties.jsx
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/core/plugins/json-schema-2020-12/components/keywords/Properties/Properties.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React from "react" | ||
|
||
import { schema } from "../../../prop-types" | ||
import { useComponent } from "../../../hooks" | ||
|
||
const Properties = ({ schema }) => { | ||
const properties = schema?.properties || {} | ||
|
||
if (Object.keys(properties).length === 0) { | ||
return null | ||
} | ||
|
||
const JSONSchema = useComponent("JSONSchema") | ||
|
||
return ( | ||
<ul className="json-schema-2020-12__properties"> | ||
{Object.entries(properties).map(([propertyName, schema]) => ( | ||
<li key={propertyName} className="json-schema-2020-12-property"> | ||
<JSONSchema name={propertyName} schema={schema} /> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} | ||
|
||
Properties.propTypes = { | ||
schema: schema.isRequired, | ||
} | ||
|
||
export default Properties |
10 changes: 10 additions & 0 deletions
10
src/core/plugins/json-schema-2020-12/components/keywords/Properties/_properties.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.json-schema-2020-12 { | ||
&__properties { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
&-property { | ||
list-style-type: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters