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' ;
10
3
import type { ChangeType } from '@stoplight/types' ;
11
4
import { Atom } from 'jotai' ;
12
5
import { useAtomValue , useUpdateAtom } from 'jotai/utils' ;
@@ -16,9 +9,10 @@ import * as React from 'react';
16
9
import { COMBINER_NAME_MAP } from '../../consts' ;
17
10
import { useJSVOptionsContext } from '../../contexts' ;
18
11
import { 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' ;
21
14
import { ChildStack } from '../shared/ChildStack' ;
15
+ import { Error } from '../shared/Error' ;
22
16
import { Properties , useHasProperties } from '../shared/Properties' ;
23
17
import { hoveredNodeAtom , isNodeHoveredAtom } from './state' ;
24
18
import { useChoices } from './useChoices' ;
@@ -60,24 +54,6 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(
60
54
const typeToShow = selectedChoice . type ;
61
55
const description = isRegularNode ( typeToShow ) ? typeToShow . annotations . description : null ;
62
56
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
-
81
57
const rootLevel = renderRootTreeLines ? 1 : 2 ;
82
58
const childNodes = React . useMemo ( ( ) => calculateChildrenToShow ( typeToShow ) , [ typeToShow ] ) ;
83
59
const combiner = isRegularNode ( schemaNode ) && schemaNode . combiners ?. length ? schemaNode . combiners [ 0 ] : null ;
@@ -89,8 +65,6 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(
89
65
const validations = isRegularNode ( schemaNode ) ? schemaNode . validations : { } ;
90
66
const hasProperties = useHasProperties ( { required, deprecated, validations } ) ;
91
67
92
- const internalSchemaError = getInternalSchemaError ( schemaNode ) ;
93
-
94
68
const annotationRootOffset = renderRootTreeLines ? 0 : 8 ;
95
69
let annotationLeftOffset = - 20 - annotationRootOffset ;
96
70
if ( nestingLevel > 1 ) {
@@ -199,20 +173,12 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(
199
173
validations = { isRegularNode ( schemaNode ) ? getValidationsFromSchema ( schemaNode ) : { } }
200
174
hideExamples = { hideExamples }
201
175
/>
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
- ) }
211
176
</ VStack >
212
177
178
+ < Error schemaNode = { schemaNode } />
179
+
213
180
{ renderRowAddon ? < Box > { renderRowAddon ( { schemaNode, nestingLevel } ) } </ Box > : null }
214
181
</ Flex >
215
-
216
182
{ isCollapsible && isExpanded ? (
217
183
< ChildStack
218
184
schemaNode = { schemaNode }
0 commit comments