Skip to content

Commit 37b219f

Browse files
author
Jakub Jankowski
authored
Merge branch 'beta' into feat/validations
2 parents 910c72b + 39fd8ba commit 37b219f

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

src/__stories__/JsonSchemaViewer.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ storiesOf('JsonSchemaViewer', module)
2121
<JsonSchemaViewer
2222
schema={schema as JSONSchema4}
2323
defaultExpandedDepth={number('defaultExpandedDepth', 0)}
24-
expanded={boolean('expanded', true)}
2524
onGoToRef={action('onGoToRef')}
2625
viewMode={select(
2726
'viewMode',
@@ -38,7 +37,6 @@ storiesOf('JsonSchemaViewer', module)
3837
<JsonSchemaViewer
3938
schema={object('schema', {})}
4039
defaultExpandedDepth={number('defaultExpandedDepth', 0)}
41-
expanded={boolean('expanded', false)}
4240
onGoToRef={action('onGoToRef')}
4341
maxRows={number('maxRows', 5)}
4442
mergeAllOf={boolean('mergeAllOf', true)}
@@ -60,7 +58,6 @@ storiesOf('JsonSchemaViewer', module)
6058
return (
6159
<JsonSchemaViewer
6260
schema={object('schema', schema as JSONSchema4)}
63-
expanded={boolean('expanded', true)}
6461
onGoToRef={action('onGoToRef')}
6562
maxRows={number('maxRows', 5)}
6663
mergeAllOf={boolean('mergeAllOf', true)}
@@ -74,7 +71,6 @@ storiesOf('JsonSchemaViewer', module)
7471
<JsonSchemaViewer
7572
schema={stressSchema as JSONSchema4}
7673
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
77-
expanded={boolean('expanded', false)}
7874
onGoToRef={action('onGoToRef')}
7975
maxRows={number('maxRows', 10)}
8076
mergeAllOf={boolean('mergeAllOf', true)}
@@ -84,7 +80,6 @@ storiesOf('JsonSchemaViewer', module)
8480
<JsonSchemaViewer
8581
schema={stressSchema as JSONSchema4}
8682
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
87-
expanded={boolean('expanded', false)}
8883
onGoToRef={action('onGoToRef')}
8984
maxRows={number('maxRows', 10)}
9085
mergeAllOf={boolean('mergeAllOf', true)}
@@ -96,7 +91,6 @@ storiesOf('JsonSchemaViewer', module)
9691
<JsonSchemaViewer
9792
schema={allOfSchema as JSONSchema4}
9893
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
99-
expanded={boolean('expanded', false)}
10094
mergeAllOf={boolean('mergeAllOf', true)}
10195
onGoToRef={action('onGoToRef')}
10296
/>
@@ -112,7 +106,6 @@ storiesOf('JsonSchemaViewer', module)
112106
},
113107
null,
114108
)}
115-
expanded={boolean('expanded', false)}
116109
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
117110
onGoToRef={action('onGoToRef')}
118111
mergeAllOf={boolean('mergeAllOf', true)}
@@ -145,7 +138,6 @@ storiesOf('JsonSchemaViewer', module)
145138
},
146139
},
147140
}}
148-
expanded={boolean('expanded', false)}
149141
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
150142
onGoToRef={action('onGoToRef')}
151143
mergeAllOf={boolean('mergeAllOf', true)}
@@ -158,7 +150,6 @@ storiesOf('JsonSchemaViewer', module)
158150
<JsonSchemaViewer
159151
schema={schema as JSONSchema4}
160152
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
161-
expanded={boolean('expanded', false)}
162153
onGoToRef={action('onGoToRef')}
163154
mergeAllOf={boolean('mergeAllOf', true)}
164155
/>

src/__tests__/index.spec.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('HTML Output', () => {
2121
)('should match %s', filename => {
2222
const schema = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../__fixtures__/', filename), 'utf8'));
2323

24-
expect(dumpDom(<JsonSchemaViewer schema={schema} expanded={true} mergeAllOf />)).toMatchSnapshot();
24+
expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} mergeAllOf />)).toMatchSnapshot();
2525
});
2626

2727
describe.each(['anyOf', 'oneOf'])('given %s combiner placed next to allOf', combiner => {
@@ -80,11 +80,15 @@ describe('HTML Output', () => {
8080
});
8181

8282
it('given allOf merging disabled, should preserve both combiners', () => {
83-
expect(dumpDom(<JsonSchemaViewer schema={schema} expanded={true} mergeAllOf={false} />)).toMatchSnapshot();
83+
expect(
84+
dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} mergeAllOf={false} />),
85+
).toMatchSnapshot();
8486
});
8587

8688
it('given allOf merging enabled, should merge contents of allOf combiners', () => {
87-
expect(dumpDom(<JsonSchemaViewer schema={schema} expanded={true} mergeAllOf />)).toMatchSnapshot();
89+
expect(
90+
dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} mergeAllOf />),
91+
).toMatchSnapshot();
8892
});
8993
});
9094

@@ -105,7 +109,7 @@ describe('HTML Output', () => {
105109
type: 'array',
106110
};
107111

108-
expect(dumpDom(<JsonSchemaViewer schema={schema} expanded={true} />)).toMatchSnapshot();
112+
expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} />)).toMatchSnapshot();
109113
});
110114

111115
it.each<ViewMode>(['standalone', 'read', 'write'])('given %s mode, should populate proper nodes', mode => {
@@ -123,7 +127,9 @@ describe('HTML Output', () => {
123127
},
124128
};
125129

126-
expect(dumpDom(<JsonSchemaViewer schema={schema} expanded={true} mergeAllOf viewMode={mode} />)).toMatchSnapshot();
130+
expect(
131+
dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} mergeAllOf viewMode={mode} />),
132+
).toMatchSnapshot();
127133
});
128134

129135
it('given multiple object and string type, should process properties', () => {
@@ -139,7 +145,7 @@ describe('HTML Output', () => {
139145
},
140146
};
141147

142-
expect(dumpDom(<JsonSchemaViewer schema={schema} expanded={true} mergeAllOf />)).toMatchSnapshot();
148+
expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} mergeAllOf />)).toMatchSnapshot();
143149
});
144150

145151
it('given complex type that includes array and complex array subtype, should not ignore subtype', () => {
@@ -157,7 +163,7 @@ describe('HTML Output', () => {
157163
},
158164
};
159165

160-
expect(dumpDom(<JsonSchemaViewer schema={schema} expanded={true} mergeAllOf />)).toMatchSnapshot();
166+
expect(dumpDom(<JsonSchemaViewer schema={schema} defaultExpandedDepth={Infinity} mergeAllOf />)).toMatchSnapshot();
161167
});
162168

163169
it('given visible $ref node, should try to inject the title immediately', () => {

src/components/JsonSchemaViewer.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export interface IJsonSchemaViewer {
1717
schema: JSONSchema4;
1818
emptyText?: string;
1919
defaultExpandedDepth?: number;
20-
expanded?: boolean;
2120
className?: string;
2221
maxRows?: number;
2322
onGoToRef?: GoToRefHandler;
@@ -64,15 +63,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<
6463
}
6564

6665
protected get expandedDepth(): number {
67-
if (this.props.expanded) {
68-
return Infinity; // tree-list kind of equivalent of expanded: all
69-
}
70-
71-
if (this.props.defaultExpandedDepth !== void 0) {
72-
return this.props.defaultExpandedDepth;
73-
}
74-
75-
return 1;
66+
return this.props.defaultExpandedDepth ?? 1;
7667
}
7768

7869
protected renderSchema() {
@@ -111,7 +102,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<
111102

112103
public render() {
113104
const {
114-
props: { emptyText = 'No schema defined', schema, expanded, defaultExpandedDepth, className, ...props },
105+
props: { emptyText = 'No schema defined', schema, defaultExpandedDepth, className, ...props },
115106
} = this;
116107

117108
if (this.state.isEmpty) {
@@ -122,7 +113,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<
122113
<Flex pos="relative" h="full" className={cn(className, 'JsonSchemaViewer')}>
123114
<SchemaTreeContext.Provider value={this.tree}>
124115
<ViewModeContext.Provider value={this.props.viewMode ?? 'standalone'}>
125-
<SchemaTreeComponent expanded={expanded} schema={schema} treeStore={this.treeStore} {...props} />
116+
<SchemaTreeComponent schema={schema} treeStore={this.treeStore} {...props} />
126117
</ViewModeContext.Provider>
127118
</SchemaTreeContext.Provider>
128119
</Flex>

src/components/SchemaTree.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { validationCount } from './shared/Validations';
1010
export interface ISchemaTree {
1111
treeStore: TreeStore;
1212
schema: JSONSchema4;
13-
expanded?: boolean;
1413
maxRows?: number;
1514
onGoToRef?: GoToRefHandler;
1615
rowRenderer?: RowRenderer;

0 commit comments

Comments
 (0)