Skip to content

Commit 512383d

Browse files
author
Marcell Toth
authored
refactor: simplify JSV (#109)
* refactor: rebuild JSV vol 1 * feat: don't expand mirrored nodes by default * feat: implement array flattening * chore: cleanup * feat: max-width * feat: broken $ref handling * chore: remove unnecessary context usage * fix: visual nesting problem * chore: simplify SchemaRow * fix: default expanded level * chore: remove nesting level context * fix: padding * chore: get rid of tree-list * feat: add oneOf story * chore: remove maxRows * chore: clean up FallbackComponent * chore: one less context * feat: onGoToRef support * fix: don't make props required * test: remove mergeAllOf from stories * chore: undo unintended fixture modification * feat: add row addon feature (formerly rowRenderer) * test: update snapshots * test: update some * test: fix SchemaRow tests * test: update Format tests * test: update Property tests * test: remove expansion checks To be added back with RTL * chore: lint * chore: no ui-kit styles in storybook
1 parent 80d2350 commit 512383d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4202
-4051
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
moduleNameMapper: {
66
'\\.css$': '<rootDir>/__mocks__/styleMock.js'
77
},
8-
testMatch: ['<rootDir>/src/**/__tests__/*.(ts|js)?(x)'],
8+
testMatch: ['<rootDir>/src/**/__tests__/*.(spec|test).(ts|js)?(x)'],
99
transform: {
1010
'\\.tsx?$': 'ts-jest'
1111
},

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"peerDependencies": {
3838
"@stoplight/markdown-viewer": "^4",
3939
"@stoplight/ui-kit": "^3",
40-
"mobx": "^5",
4140
"react": ">=16.8",
4241
"react-dom": ">=16.8"
4342
},
@@ -47,7 +46,6 @@
4746
"@stoplight/json-schema-tree": "^1.1.0",
4847
"@stoplight/mosaic": "^1.0.0-beta.22",
4948
"@stoplight/react-error-boundary": "^1.0.0",
50-
"@stoplight/tree-list": "^5.0.3",
5149
"classnames": "^2.2.6",
5250
"lodash": "^4.17.19"
5351
},
@@ -87,7 +85,6 @@
8785
"fast-glob": "^3.2.4",
8886
"jest": "^26.6.2",
8987
"jest-enzyme": "^7.1.2",
90-
"mobx": "^5.13.0",
9188
"prettier": "^2.2.1",
9289
"react": "^16.14.0",
9390
"react-dom": "^16.14.0",

src/__stories__/JsonSchemaViewer.tsx

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import { Button, Flex, InvertTheme, subscribeTheme } from '@stoplight/mosaic';
22
import { action } from '@storybook/addon-actions';
3-
import { boolean, number, object, select, withKnobs } from '@storybook/addon-knobs';
3+
import { number, object, select, withKnobs } from '@storybook/addon-knobs';
44
import { storiesOf } from '@storybook/react';
55
import { JSONSchema4 } from 'json-schema';
66
import * as React from 'react';
77

8-
import { JsonSchemaViewer, RowRenderer, SchemaRow } from '../';
8+
import { JsonSchemaViewer, RowAddonRenderer } from '../';
99
import { Wrapper } from './utils/Wrapper';
1010

1111
const allOfSchema = require('../__fixtures__/combiners/allOfs/base.json');
1212
const schema = require('../__fixtures__/default-schema.json');
1313
const stressSchema = require('../__fixtures__/stress-schema.json');
14+
const refSchema = require('../__fixtures__/references/base.json');
15+
const nullRefSchema = require('../__fixtures__/references/nullish.json');
16+
const brokenRefArraySchema = require('../__fixtures__/arrays/of-refs.json');
17+
const oneOfWithArraySchema = require('../__fixtures__/combiners/oneof-with-array-type.json');
1418

1519
subscribeTheme({ mode: 'light' });
1620

@@ -21,7 +25,6 @@ storiesOf('JsonSchemaViewer', module)
2125
<JsonSchemaViewer
2226
schema={schema as JSONSchema4}
2327
defaultExpandedDepth={number('defaultExpandedDepth', 0)}
24-
onGoToRef={action('onGoToRef')}
2528
viewMode={select(
2629
'viewMode',
2730
{
@@ -31,58 +34,48 @@ storiesOf('JsonSchemaViewer', module)
3134
},
3235
'standalone',
3336
)}
37+
onGoToRef={action('onGoToRef')}
3438
/>
3539
))
3640
.add('custom schema', () => (
3741
<JsonSchemaViewer
3842
schema={object('schema', {})}
3943
defaultExpandedDepth={number('defaultExpandedDepth', 0)}
4044
onGoToRef={action('onGoToRef')}
41-
maxRows={number('maxRows', 5)}
42-
mergeAllOf={boolean('mergeAllOf', true)}
4345
/>
4446
))
45-
.add('custom row renderer', () => {
46-
const customRowRenderer: RowRenderer = (node, rowOptions) => {
47+
.add('custom row addon', () => {
48+
const customRowAddonRenderer: RowAddonRenderer = () => {
4749
return (
48-
<>
49-
<SchemaRow treeListNode={node} rowOptions={rowOptions} />
50-
<Flex h="full" alignItems="center">
51-
<Button pl={1} mr={1} size="sm" appearance="minimal" icon="issue" />
52-
<input type="checkbox" />
53-
</Flex>
54-
</>
50+
<Flex h="full" alignItems="center">
51+
<Button pl={1} mr={1} size="sm" appearance="minimal" icon="issue" />
52+
<input type="checkbox" />
53+
</Flex>
5554
);
5655
};
5756

5857
return (
5958
<JsonSchemaViewer
6059
schema={object('schema', schema as JSONSchema4)}
6160
onGoToRef={action('onGoToRef')}
62-
maxRows={number('maxRows', 5)}
63-
mergeAllOf={boolean('mergeAllOf', true)}
64-
rowRenderer={customRowRenderer}
61+
renderRowAddon={customRowAddonRenderer}
6562
/>
6663
);
6764
})
6865
.add('stress-test schema', () => (
6966
<>
70-
<div style={{ height: 345 }}>
67+
<div style={{ height: 345, overflowY: 'scroll' }}>
7168
<JsonSchemaViewer
7269
schema={stressSchema as JSONSchema4}
7370
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
7471
onGoToRef={action('onGoToRef')}
75-
maxRows={number('maxRows', 10)}
76-
mergeAllOf={boolean('mergeAllOf', true)}
7772
/>
7873
</div>
79-
<div style={{ height: 345 }}>
74+
<div style={{ height: 345, overflowY: 'scroll' }}>
8075
<JsonSchemaViewer
8176
schema={stressSchema as JSONSchema4}
8277
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
8378
onGoToRef={action('onGoToRef')}
84-
maxRows={number('maxRows', 10)}
85-
mergeAllOf={boolean('mergeAllOf', true)}
8679
/>
8780
</div>
8881
</>
@@ -91,7 +84,13 @@ storiesOf('JsonSchemaViewer', module)
9184
<JsonSchemaViewer
9285
schema={allOfSchema as JSONSchema4}
9386
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
94-
mergeAllOf={boolean('mergeAllOf', true)}
87+
onGoToRef={action('onGoToRef')}
88+
/>
89+
))
90+
.add('anyOf-array-schema', () => (
91+
<JsonSchemaViewer
92+
schema={oneOfWithArraySchema as JSONSchema4}
93+
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
9594
onGoToRef={action('onGoToRef')}
9695
/>
9796
))
@@ -108,7 +107,6 @@ storiesOf('JsonSchemaViewer', module)
108107
)}
109108
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
110109
onGoToRef={action('onGoToRef')}
111-
mergeAllOf={boolean('mergeAllOf', true)}
112110
/>
113111
))
114112
.add('invalid types property pretty error message', () => (
@@ -140,7 +138,6 @@ storiesOf('JsonSchemaViewer', module)
140138
}}
141139
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
142140
onGoToRef={action('onGoToRef')}
143-
mergeAllOf={boolean('mergeAllOf', true)}
144141
/>
145142
))
146143
.add('dark', () => {
@@ -151,9 +148,29 @@ storiesOf('JsonSchemaViewer', module)
151148
schema={schema as JSONSchema4}
152149
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
153150
onGoToRef={action('onGoToRef')}
154-
mergeAllOf={boolean('mergeAllOf', true)}
155151
/>
156152
</div>
157153
</InvertTheme>
158154
);
159-
});
155+
})
156+
.add('refs/normal', () => (
157+
<JsonSchemaViewer
158+
schema={refSchema as JSONSchema4}
159+
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
160+
onGoToRef={action('onGoToRef')}
161+
/>
162+
))
163+
.add('refs/nullish', () => (
164+
<JsonSchemaViewer
165+
schema={nullRefSchema as JSONSchema4}
166+
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
167+
onGoToRef={action('onGoToRef')}
168+
/>
169+
))
170+
.add('refs/broken', () => (
171+
<JsonSchemaViewer
172+
schema={brokenRefArraySchema as JSONSchema4}
173+
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
174+
onGoToRef={action('onGoToRef')}
175+
/>
176+
));

src/__stories__/_styles.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@import "~@stoplight/tree-list/styles/_tree-list.scss";
2-
@import "~@stoplight/ui-kit/styles/_ui-kit.scss";
31
@import "~@stoplight/mosaic/styles.css";
42
@import "~@stoplight/mosaic/themes/default.css";
53

0 commit comments

Comments
 (0)