Skip to content

Commit f6420bd

Browse files
committed
feat: drop expanded prop
1 parent 775ad72 commit f6420bd

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
@@ -19,7 +19,6 @@ storiesOf('JsonSchemaViewer', module)
1919
<JsonSchemaViewer
2020
schema={schema as JSONSchema4}
2121
defaultExpandedDepth={number('defaultExpandedDepth', 0)}
22-
expanded={boolean('expanded', true)}
2322
onGoToRef={action('onGoToRef')}
2423
viewMode={select(
2524
'viewMode',
@@ -36,7 +35,6 @@ storiesOf('JsonSchemaViewer', module)
3635
<JsonSchemaViewer
3736
schema={object('schema', {})}
3837
defaultExpandedDepth={number('defaultExpandedDepth', 0)}
39-
expanded={boolean('expanded', false)}
4038
onGoToRef={action('onGoToRef')}
4139
maxRows={number('maxRows', 5)}
4240
mergeAllOf={boolean('mergeAllOf', true)}
@@ -58,7 +56,6 @@ storiesOf('JsonSchemaViewer', module)
5856
return (
5957
<JsonSchemaViewer
6058
schema={object('schema', schema as JSONSchema4)}
61-
expanded={boolean('expanded', true)}
6259
onGoToRef={action('onGoToRef')}
6360
maxRows={number('maxRows', 5)}
6461
mergeAllOf={boolean('mergeAllOf', true)}
@@ -72,7 +69,6 @@ storiesOf('JsonSchemaViewer', module)
7269
<JsonSchemaViewer
7370
schema={stressSchema as JSONSchema4}
7471
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
75-
expanded={boolean('expanded', false)}
7672
onGoToRef={action('onGoToRef')}
7773
maxRows={number('maxRows', 10)}
7874
mergeAllOf={boolean('mergeAllOf', true)}
@@ -82,7 +78,6 @@ storiesOf('JsonSchemaViewer', module)
8278
<JsonSchemaViewer
8379
schema={stressSchema as JSONSchema4}
8480
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
85-
expanded={boolean('expanded', false)}
8681
onGoToRef={action('onGoToRef')}
8782
maxRows={number('maxRows', 10)}
8883
mergeAllOf={boolean('mergeAllOf', true)}
@@ -94,7 +89,6 @@ storiesOf('JsonSchemaViewer', module)
9489
<JsonSchemaViewer
9590
schema={allOfSchema as JSONSchema4}
9691
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
97-
expanded={boolean('expanded', false)}
9892
mergeAllOf={boolean('mergeAllOf', true)}
9993
onGoToRef={action('onGoToRef')}
10094
/>
@@ -110,7 +104,6 @@ storiesOf('JsonSchemaViewer', module)
110104
},
111105
null,
112106
)}
113-
expanded={boolean('expanded', false)}
114107
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
115108
onGoToRef={action('onGoToRef')}
116109
mergeAllOf={boolean('mergeAllOf', true)}
@@ -143,7 +136,6 @@ storiesOf('JsonSchemaViewer', module)
143136
},
144137
},
145138
}}
146-
expanded={boolean('expanded', false)}
147139
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
148140
onGoToRef={action('onGoToRef')}
149141
mergeAllOf={boolean('mergeAllOf', true)}
@@ -154,7 +146,6 @@ storiesOf('JsonSchemaViewer', module)
154146
<JsonSchemaViewer
155147
schema={schema as JSONSchema4}
156148
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
157-
expanded={boolean('expanded', false)}
158149
onGoToRef={action('onGoToRef')}
159150
mergeAllOf={boolean('mergeAllOf', true)}
160151
/>

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
@@ -16,7 +16,6 @@ export interface IJsonSchemaViewer {
1616
schema: JSONSchema4;
1717
emptyText?: string;
1818
defaultExpandedDepth?: number;
19-
expanded?: boolean;
2019
className?: string;
2120
maxRows?: number;
2221
onGoToRef?: GoToRefHandler;
@@ -63,15 +62,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<
6362
}
6463

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

7768
protected renderSchema() {
@@ -110,7 +101,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<
110101

111102
public render() {
112103
const {
113-
props: { emptyText = 'No schema defined', schema, expanded, defaultExpandedDepth, className, ...props },
104+
props: { emptyText = 'No schema defined', schema, defaultExpandedDepth, className, ...props },
114105
} = this;
115106

116107
if (this.state.isEmpty) {
@@ -121,7 +112,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<
121112
<div className={cn(className, 'JsonSchemaViewer flex flex-col relative')}>
122113
<SchemaTreeContext.Provider value={this.tree}>
123114
<ViewModeContext.Provider value={this.props.viewMode ?? 'standalone'}>
124-
<SchemaTreeComponent expanded={expanded} schema={schema} treeStore={this.treeStore} {...props} />
115+
<SchemaTreeComponent schema={schema} treeStore={this.treeStore} {...props} />
125116
</ViewModeContext.Provider>
126117
</SchemaTreeContext.Provider>
127118
</div>

src/components/SchemaTree.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { SchemaRow } from './SchemaRow';
88
export interface ISchemaTree {
99
treeStore: TreeStore;
1010
schema: JSONSchema4;
11-
expanded?: boolean;
1211
maxRows?: number;
1312
onGoToRef?: GoToRefHandler;
1413
rowRenderer?: RowRenderer;

0 commit comments

Comments
 (0)