1- import {
2- isMirroredNode ,
3- isReferenceNode ,
4- isRegularNode ,
5- ReferenceNode ,
6- SchemaNode ,
7- SchemaNodeKind ,
8- } from '@stoplight/json-schema-tree' ;
9- import { Box , Flex , Icon , NodeAnnotation , Select , SpaceVals , VStack } from '@stoplight/mosaic' ;
1+ import { isMirroredNode , isReferenceNode , isRegularNode , SchemaNode } from '@stoplight/json-schema-tree' ;
2+ import { Box , Flex , NodeAnnotation , Select , SpaceVals , VStack } from '@stoplight/mosaic' ;
103import type { ChangeType } from '@stoplight/types' ;
114import { Atom } from 'jotai' ;
125import { useAtomValue , useUpdateAtom } from 'jotai/utils' ;
@@ -16,9 +9,10 @@ import * as React from 'react';
169import { COMBINER_NAME_MAP } from '../../consts' ;
1710import { useJSVOptionsContext } from '../../contexts' ;
1811import { getNodeId , getOriginalNodeId } from '../../hash' ;
19- import { calculateChildrenToShow , isFlattenableNode , isPropertyRequired } from '../../tree' ;
20- import { Caret , Description , getInternalSchemaError , getValidationsFromSchema , Types , Validations } from '../shared' ;
12+ import { calculateChildrenToShow , isPropertyRequired } from '../../tree' ;
13+ import { Caret , Description , getValidationsFromSchema , Types , Validations } from '../shared' ;
2114import { ChildStack } from '../shared/ChildStack' ;
15+ import { Error } from '../shared/Error' ;
2216import { Properties , useHasProperties } from '../shared/Properties' ;
2317import { hoveredNodeAtom , isNodeHoveredAtom } from './state' ;
2418import { useChoices } from './useChoices' ;
@@ -60,24 +54,6 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(
6054 const typeToShow = selectedChoice . type ;
6155 const description = isRegularNode ( typeToShow ) ? typeToShow . annotations . description : null ;
6256
63- const refNode = React . useMemo < ReferenceNode | null > ( ( ) => {
64- if ( isReferenceNode ( schemaNode ) ) {
65- return schemaNode ;
66- }
67-
68- if (
69- isRegularNode ( schemaNode ) &&
70- ( isFlattenableNode ( schemaNode ) ||
71- ( schemaNode . primaryType === SchemaNodeKind . Array && schemaNode . children ?. length === 1 ) )
72- ) {
73- return ( schemaNode . children ?. find ( isReferenceNode ) as ReferenceNode | undefined ) ?? null ;
74- }
75-
76- return null ;
77- } , [ schemaNode ] ) ;
78-
79- const isBrokenRef = typeof refNode ?. error === 'string' ;
80-
8157 const rootLevel = renderRootTreeLines ? 1 : 2 ;
8258 const childNodes = React . useMemo ( ( ) => calculateChildrenToShow ( typeToShow ) , [ typeToShow ] ) ;
8359 const combiner = isRegularNode ( schemaNode ) && schemaNode . combiners ?. length ? schemaNode . combiners [ 0 ] : null ;
@@ -89,8 +65,6 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(
8965 const validations = isRegularNode ( schemaNode ) ? schemaNode . validations : { } ;
9066 const hasProperties = useHasProperties ( { required, deprecated, validations } ) ;
9167
92- const internalSchemaError = getInternalSchemaError ( schemaNode ) ;
93-
9468 const annotationRootOffset = renderRootTreeLines ? 0 : 8 ;
9569 let annotationLeftOffset = - 20 - annotationRootOffset ;
9670 if ( nestingLevel > 1 ) {
@@ -199,20 +173,12 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(
199173 validations = { isRegularNode ( schemaNode ) ? getValidationsFromSchema ( schemaNode ) : { } }
200174 hideExamples = { hideExamples }
201175 />
202-
203- { ( isBrokenRef || internalSchemaError . hasError ) && (
204- < Icon
205- title = { refNode ?. error ! || internalSchemaError . error }
206- color = "danger"
207- icon = { [ 'fas' , 'exclamation-triangle' ] }
208- size = "sm"
209- />
210- ) }
211176 </ VStack >
212177
178+ < Error schemaNode = { schemaNode } />
179+
213180 { renderRowAddon ? < Box > { renderRowAddon ( { schemaNode, nestingLevel } ) } </ Box > : null }
214181 </ Flex >
215-
216182 { isCollapsible && isExpanded ? (
217183 < ChildStack
218184 schemaNode = { schemaNode }
0 commit comments