Skip to content

Commit ad7127e

Browse files
committed
fix: show caret for top-level array with $ref items
1 parent d191c63 commit ad7127e

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/components/SchemaRow.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as React from 'react';
55
import { getNodeMetadata, getSchemaNodeMetadata } from '../tree/metadata';
66
import { GoToRefHandler, SchemaKind, SchemaTreeListNode } from '../types';
77
import { getPrimaryType } from '../utils/getPrimaryType';
8-
import { isRefNode } from '../utils/guards';
8+
import { hasRefItems, isRefNode } from '../utils/guards';
99
import { Caret, Description, Divider, Property, Validations } from './shared';
1010

1111
export interface ISchemaRow {
@@ -47,15 +47,17 @@ export const SchemaPropertyRow: typeof SchemaRow = ({ node, onGoToRef, rowOption
4747
(node.parent !== null && Tree.getLevel(node.parent) >= 0 && getSchemaNodeMetadata(node.parent)?.schemaNode) || null;
4848
const description = 'annotations' in schemaNode ? schemaNode.annotations.description : null;
4949

50+
const has$Ref = isRefNode(schemaNode) || (getPrimaryType(schemaNode) === SchemaKind.Array && hasRefItems(schemaNode));
51+
5052
return (
5153
<>
52-
{isRefNode(schemaNode) || (isParentNode(node) && Tree.getLevel(node) > 0) ? (
54+
{has$Ref || (isParentNode(node) && Tree.getLevel(node) > 0) ? (
5355
<Caret
5456
isExpanded={!!rowOptions.isExpanded}
5557
style={{
5658
width: ICON_DIMENSION,
5759
height: ICON_DIMENSION,
58-
...(isRefNode(schemaNode) && Tree.getLevel(node) === 0
60+
...(has$Ref && Tree.getLevel(node) === 0
5961
? {
6062
position: 'relative',
6163
}

src/components/__tests__/SchemaRow.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,34 @@ describe('SchemaRow component', () => {
8282
});
8383
});
8484

85+
test('should render caret for top-level array with $ref items', () => {
86+
const schema: JSONSchema4 = {
87+
type: 'array',
88+
items: {
89+
$ref: '#/foo',
90+
},
91+
};
92+
93+
const tree = new SchemaTree(schema, new TreeState(), {
94+
expandedDepth: Infinity,
95+
mergeAllOf: false,
96+
resolveRef: void 0,
97+
});
98+
99+
tree.populate();
100+
101+
const wrapper = shallow(<SchemaRow node={tree.itemAt(0)!} rowOptions={{}} />)
102+
.find(SchemaPropertyRow)
103+
.shallow();
104+
105+
expect(wrapper.find(Caret)).toExist();
106+
expect(wrapper.find(Caret)).toHaveProp('style', {
107+
height: 20,
108+
position: 'relative',
109+
width: 20,
110+
});
111+
});
112+
85113
describe('expanding errors', () => {
86114
describe('$refs', () => {
87115
let tree: SchemaTree;

0 commit comments

Comments
 (0)