From f2f103eb551de0b6df28413c0c77b440dc67eb18 Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 3 Nov 2021 18:59:40 -0500 Subject: [PATCH 1/7] chore(anyof oneof styles): show anyof/oneof near dropdowns of schemas --- src/components/SchemaRow/SchemaRow.tsx | 15 +++++++++++++++ .../SchemaRow/TopLevelSchemaRow.tsx | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index 587372d2..b4485cd2 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -9,6 +9,7 @@ import { } from '@stoplight/json-schema-tree'; import { Icon, Select } from '@stoplight/mosaic'; import cn from 'classnames'; +import { first } from 'lodash'; import last from 'lodash/last.js'; import * as React from 'react'; @@ -55,6 +56,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, const isBrokenRef = typeof refNode?.error === 'string'; const childNodes = React.useMemo(() => calculateChildrenToShow(typeToShow), [typeToShow]); + const combiner = anyOfOrOneOf(schemaNode); return (
@@ -70,6 +72,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, {schemaNode.subpath.length > 0 && shouldShowPropertyName(schemaNode) && (
{last(schemaNode.subpath)}
)} + {schemaNode.subpath.length > 0 && combiner !== undefined &&
{combiner}
} {choices.length === 1 && ( <> @@ -149,3 +152,15 @@ function shouldShowPropertyName(schemaNode: SchemaNode) { (schemaNode.subpath[0] === 'properties' || schemaNode.subpath[0] === 'patternProperties') ); } + +function anyOfOrOneOf(schemaNode: SchemaNode) { + if (schemaNode.fragment.anyOf !== undefined) { + return '(Any of)'; + } + + if (schemaNode.fragment.oneOf !== undefined) { + return '(One of)'; + } + + return undefined; +} diff --git a/src/components/SchemaRow/TopLevelSchemaRow.tsx b/src/components/SchemaRow/TopLevelSchemaRow.tsx index c5583d5d..ba9a55c5 100644 --- a/src/components/SchemaRow/TopLevelSchemaRow.tsx +++ b/src/components/SchemaRow/TopLevelSchemaRow.tsx @@ -23,6 +23,14 @@ export const TopLevelSchemaRow: React.FC = ({ schemaNode, nestin } if (isRegularNode(schemaNode) && choices.length > 1) { + let combinerType = ''; + if (selectedChoice.type.subpath[0] === 'oneOf') { + combinerType = ' (One of)'; + } + if (selectedChoice.type.subpath[0] === 'anyOf') { + combinerType = ' (Any of)'; + } + return (
@@ -37,11 +45,14 @@ export const TopLevelSchemaRow: React.FC = ({ schemaNode, nestin }))} renderTrigger={props => ( -
- {selectedChoice.title} -
- +
+
+ {selectedChoice.title} +
+ +
+
{combinerType}
)} From 2e4947b61a63923b420b57895676c487cb5b3c16 Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 3 Nov 2021 19:07:10 -0500 Subject: [PATCH 2/7] chore(styling feedback): apply Nauman's suggestions --- src/components/SchemaRow/SchemaRow.tsx | 5 ++++- src/components/SchemaRow/TopLevelSchemaRow.tsx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index b4485cd2..0de073d7 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -72,7 +72,6 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, {schemaNode.subpath.length > 0 && shouldShowPropertyName(schemaNode) && (
{last(schemaNode.subpath)}
)} - {schemaNode.subpath.length > 0 && combiner !== undefined &&
{combiner}
} {choices.length === 1 && ( <> @@ -112,6 +111,10 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, onChange={selectedIndex => setSelectedChoice(choices[selectedIndex as number])} /> )} + + {schemaNode.subpath.length > 0 && combiner !== undefined && ( +
{combiner}
+ )}
= ({ schemaNode, nestin
-
{combinerType}
+
{combinerType}
)} From 2b4f7fe30cff873c240a1aaa68370eed1d1e56f8 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 4 Nov 2021 10:36:33 -0500 Subject: [PATCH 3/7] chore(lint): remove unused import --- src/components/SchemaRow/SchemaRow.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index 0de073d7..2985a6ad 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -9,7 +9,6 @@ import { } from '@stoplight/json-schema-tree'; import { Icon, Select } from '@stoplight/mosaic'; import cn from 'classnames'; -import { first } from 'lodash'; import last from 'lodash/last.js'; import * as React from 'react'; From e10f2c1f477984b3193ac941a95f54f645e48003 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 4 Nov 2021 10:42:04 -0500 Subject: [PATCH 4/7] chore(styles): style tweaks with margins --- src/components/SchemaRow/SchemaRow.tsx | 2 +- src/components/SchemaRow/TopLevelSchemaRow.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index 2985a6ad..5976559d 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -112,7 +112,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, )} {schemaNode.subpath.length > 0 && combiner !== undefined && ( -
{combiner}
+
{combiner}
)}
= ({ schemaNode, nestin if (isRegularNode(schemaNode) && choices.length > 1) { let combinerType = ''; if (selectedChoice.type.subpath[0] === 'oneOf') { - combinerType = ' (One of)'; + combinerType = '(One of)'; } if (selectedChoice.type.subpath[0] === 'anyOf') { - combinerType = ' (Any of)'; + combinerType = '(Any of)'; } return ( From 13a22f66b2e038bac0ffd121c1980556d3b87aa7 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 4 Nov 2021 11:49:34 -0500 Subject: [PATCH 5/7] chore(nodes): apply jakub's suggestions --- src/components/SchemaRow/SchemaRow.tsx | 6 ++---- src/components/SchemaRow/TopLevelSchemaRow.tsx | 10 ++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index 5976559d..aa539086 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -55,7 +55,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, const isBrokenRef = typeof refNode?.error === 'string'; const childNodes = React.useMemo(() => calculateChildrenToShow(typeToShow), [typeToShow]); - const combiner = anyOfOrOneOf(schemaNode); + const combiner = isRegularNode(schemaNode) && schemaNode.combiners?.length ? schemaNode.combiners[0] : null; return (
@@ -111,9 +111,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, /> )} - {schemaNode.subpath.length > 0 && combiner !== undefined && ( -
{combiner}
- )} + {combiner !== null ?
{combiner}
: null}
= ({ schemaNode, nestin } if (isRegularNode(schemaNode) && choices.length > 1) { - let combinerType = ''; - if (selectedChoice.type.subpath[0] === 'oneOf') { - combinerType = '(One of)'; - } - if (selectedChoice.type.subpath[0] === 'anyOf') { - combinerType = '(Any of)'; - } + const combiner = isRegularNode(schemaNode) && schemaNode.combiners?.length ? schemaNode.combiners[0] : null; return ( @@ -52,7 +46,7 @@ export const TopLevelSchemaRow: React.FC = ({ schemaNode, nestin
-
{combinerType}
+ {combiner !== null ?
{combiner}
: null} )} From ddedbdad347ba2061f8bc57a4552a63f38777dd0 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 4 Nov 2021 12:05:42 -0500 Subject: [PATCH 6/7] chore(dead code): remove dead code --- src/components/SchemaRow/SchemaRow.tsx | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index aa539086..4cc74ec0 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -152,15 +152,3 @@ function shouldShowPropertyName(schemaNode: SchemaNode) { (schemaNode.subpath[0] === 'properties' || schemaNode.subpath[0] === 'patternProperties') ); } - -function anyOfOrOneOf(schemaNode: SchemaNode) { - if (schemaNode.fragment.anyOf !== undefined) { - return '(Any of)'; - } - - if (schemaNode.fragment.oneOf !== undefined) { - return '(One of)'; - } - - return undefined; -} From 76d08675a0a7f451b34fcac2b8b117c0e27d6640 Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 5 Nov 2021 13:43:59 -0500 Subject: [PATCH 7/7] chore(tests): update snapshots --- .../__snapshots__/index.spec.tsx.snap | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/__tests__/__snapshots__/index.spec.tsx.snap b/src/__tests__/__snapshots__/index.spec.tsx.snap index af4f9e83..af09a013 100644 --- a/src/__tests__/__snapshots__/index.spec.tsx.snap +++ b/src/__tests__/__snapshots__/index.spec.tsx.snap @@ -331,8 +331,11 @@ exports[`HTML Output given anyOf combiner placed next to allOf given allOf mergi
- Admin -
+
+ Admin +
+
+
anyOf
@@ -439,8 +442,11 @@ exports[`HTML Output given array with oneOf containing items, should merge it co
- array[string] -
+
+ array[string] +
+
+
oneOf
@@ -544,8 +550,11 @@ exports[`HTML Output given oneOf combiner placed next to allOf given allOf mergi
- Admin -
+
+ Admin +
+
+
oneOf
@@ -1185,6 +1194,7 @@ exports[`HTML Output should match arrays/of-complex-objects.json 1`] = `
+
anyOf
@@ -1899,6 +1909,7 @@ exports[`HTML Output should match combiners/allOfs/complex.json 1`] = `
user
allOf +
allOf
@@ -1997,6 +2008,7 @@ exports[`HTML Output should match combiners/allOfs/complex.json 1`] = `
user
allOf +
allOf
@@ -2107,6 +2119,7 @@ exports[`HTML Output should match combiners/allOfs/complex.json 1`] = `
user
allOf +
allOf
@@ -2443,8 +2456,11 @@ exports[`HTML Output should match combiners/allOfs/with-type.json 1`] = `
- BugExample -
+
+ BugExample +
+
+
oneOf
@@ -2572,8 +2588,11 @@ exports[`HTML Output should match combiners/oneof-with-array-type.json 1`] = `
- array[object] -
+
+ array[object] +
+
+
oneOf
@@ -2627,8 +2646,10 @@ exports[`HTML Output should match combiners/oneof-within-array-item.json 1`] = `
- array[A] -
+
+ array[A] +
+
@@ -2869,6 +2890,7 @@ exports[`HTML Output should match default-schema.json 1`] = `
+
anyOf