Skip to content

Commit 8043e17

Browse files
authored
feat: remove top bar (#96)
BREAKING CHANGE: top bar has been removed
1 parent cce4009 commit 8043e17

File tree

6 files changed

+18
-55
lines changed

6 files changed

+18
-55
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
"@stoplight/react-error-boundary": "^1.0.0",
4848
"@stoplight/tree-list": "^5.0.3",
4949
"classnames": "^2.2.6",
50-
"lodash": "^4.17.15",
51-
"mobx-react-lite": "^1.4.1"
50+
"lodash": "^4.17.15"
5251
},
5352
"devDependencies": {
5453
"@rollup/plugin-commonjs": "^11.1.0",

src/__stories__/JsonSchemaViewer.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Button, Checkbox, Icon } from '@stoplight/ui-kit';
22
import { action } from '@storybook/addon-actions';
3-
import { boolean, number, object, select, text, withKnobs } from '@storybook/addon-knobs';
3+
import { boolean, 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';
@@ -17,11 +17,9 @@ storiesOf('JsonSchemaViewer', module)
1717
.addDecorator(storyFn => <Wrapper>{storyFn()}</Wrapper>)
1818
.add('default', () => (
1919
<JsonSchemaViewer
20-
name={text('name', 'my schema')}
2120
schema={schema as JSONSchema4}
2221
defaultExpandedDepth={number('defaultExpandedDepth', 0)}
2322
expanded={boolean('expanded', true)}
24-
hideTopBar={boolean('hideTopBar', false)}
2523
shouldResolveEagerly={boolean('shouldResolveEagerly', false)}
2624
onGoToRef={action('onGoToRef')}
2725
viewMode={select(
@@ -37,10 +35,8 @@ storiesOf('JsonSchemaViewer', module)
3735
))
3836
.add('custom schema', () => (
3937
<JsonSchemaViewer
40-
name={text('name', 'my schema')}
4138
schema={object('schema', {})}
4239
expanded={boolean('expanded', true)}
43-
hideTopBar={boolean('hideTopBar', false)}
4440
onGoToRef={action('onGoToRef')}
4541
maxRows={number('maxRows', 5)}
4642
mergeAllOf={boolean('mergeAllOf', true)}
@@ -62,10 +58,8 @@ storiesOf('JsonSchemaViewer', module)
6258

6359
return (
6460
<JsonSchemaViewer
65-
name={text('name', 'my schema')}
6661
schema={object('schema', schema as JSONSchema4)}
6762
expanded={boolean('expanded', true)}
68-
hideTopBar={boolean('hideTopBar', false)}
6963
onGoToRef={action('onGoToRef')}
7064
maxRows={number('maxRows', 5)}
7165
mergeAllOf={boolean('mergeAllOf', true)}
@@ -77,23 +71,19 @@ storiesOf('JsonSchemaViewer', module)
7771
<>
7872
<div style={{ height: 345 }}>
7973
<JsonSchemaViewer
80-
name={text('name', 'my stress schema')}
8174
schema={stressSchema as JSONSchema4}
8275
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
8376
expanded={boolean('expanded', false)}
84-
hideTopBar={boolean('hideTopBar', false)}
8577
onGoToRef={action('onGoToRef')}
8678
maxRows={number('maxRows', 10)}
8779
mergeAllOf={boolean('mergeAllOf', true)}
8880
/>
8981
</div>
9082
<div style={{ height: 345 }}>
9183
<JsonSchemaViewer
92-
name={text('name', 'my stress schema 2')}
9384
schema={stressSchema as JSONSchema4}
9485
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
9586
expanded={boolean('expanded', false)}
96-
hideTopBar={boolean('hideTopBar', false)}
9787
onGoToRef={action('onGoToRef')}
9888
maxRows={number('maxRows', 10)}
9989
mergeAllOf={boolean('mergeAllOf', true)}
@@ -106,14 +96,12 @@ storiesOf('JsonSchemaViewer', module)
10696
schema={allOfSchemaResolved as JSONSchema4}
10797
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
10898
expanded={boolean('expanded', false)}
109-
hideTopBar={boolean('hideTopBar', false)}
11099
mergeAllOf={boolean('mergeAllOf', true)}
111100
onGoToRef={action('onGoToRef')}
112101
/>
113102
))
114103
.add('error boundary', () => (
115104
<JsonSchemaViewer
116-
name={text('name', 'throw me an error!')}
117105
// @ts-ignore
118106
schema={select(
119107
'schema',
@@ -125,7 +113,6 @@ storiesOf('JsonSchemaViewer', module)
125113
)}
126114
expanded={boolean('expanded', false)}
127115
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
128-
hideTopBar={boolean('hideTopBar', false)}
129116
onGoToRef={action('onGoToRef')}
130117
mergeAllOf={boolean('mergeAllOf', true)}
131118
/>
@@ -159,19 +146,16 @@ storiesOf('JsonSchemaViewer', module)
159146
}}
160147
expanded={boolean('expanded', false)}
161148
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
162-
hideTopBar={boolean('hideTopBar', false)}
163149
onGoToRef={action('onGoToRef')}
164150
mergeAllOf={boolean('mergeAllOf', true)}
165151
/>
166152
))
167153
.add('dark', () => (
168154
<div style={{ height: '100vh' }} className="bp3-dark bg-gray-8">
169155
<JsonSchemaViewer
170-
name={text('name', 'my stress schema')}
171156
schema={schema as JSONSchema4}
172157
defaultExpandedDepth={number('defaultExpandedDepth', 2)}
173158
expanded={boolean('expanded', false)}
174-
hideTopBar={boolean('hideTopBar', false)}
175159
onGoToRef={action('onGoToRef')}
176160
mergeAllOf={boolean('mergeAllOf', true)}
177161
/>

src/components/JsonSchemaViewer.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ import { SchemaTree as SchemaTreeComponent } from './SchemaTree';
1212

1313
export interface IJsonSchemaViewer {
1414
schema: JSONSchema4;
15-
style?: object;
1615
emptyText?: string;
1716
defaultExpandedDepth?: number;
1817
expanded?: boolean;
1918
className?: string;
20-
name?: string;
21-
hideTopBar?: boolean;
2219
maxRows?: number;
2320
onGoToRef?: GoToRefHandler;
2421
mergeAllOf?: boolean;
@@ -113,7 +110,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
113110

114111
public render() {
115112
const {
116-
props: { emptyText = 'No schema defined', name, schema, expanded, defaultExpandedDepth, className, ...props },
113+
props: { emptyText = 'No schema defined', schema, expanded, defaultExpandedDepth, className, ...props },
117114
} = this;
118115

119116
// an empty array or object is still a valid response, schema is ONLY really empty when a combiner type has no information
@@ -124,7 +121,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
124121
return (
125122
<div className={cn(className, 'JsonSchemaViewer flex flex-col relative')}>
126123
<ViewModeContext.Provider value={this.props.viewMode ?? 'standalone'}>
127-
<SchemaTreeComponent expanded={expanded} name={name} schema={schema} treeStore={this.treeStore} {...props} />
124+
<SchemaTreeComponent expanded={expanded} schema={schema} treeStore={this.treeStore} {...props} />
128125
</ViewModeContext.Provider>
129126
</div>
130127
);

src/components/SchemaTree.tsx

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { TreeList, TreeListEvents, TreeStore } from '@stoplight/tree-list';
1+
import { isParentNode, TreeList, TreeListEvents, TreeStore } from '@stoplight/tree-list';
22
import { JSONSchema4 } from 'json-schema';
3-
import { observer } from 'mobx-react-lite';
43
import * as React from 'react';
54

65
import { GoToRefHandler, RowRenderer } from '../types';
@@ -9,22 +8,18 @@ import { SchemaRow } from './SchemaRow';
98
export interface ISchemaTree {
109
treeStore: TreeStore;
1110
schema: JSONSchema4;
12-
name?: string;
13-
hideTopBar?: boolean;
1411
expanded?: boolean;
1512
maxRows?: number;
1613
onGoToRef?: GoToRefHandler;
1714
rowRenderer?: RowRenderer;
1815
}
1916

20-
const canDrag = () => false;
21-
22-
export const SchemaTree = observer<ISchemaTree>(props => {
23-
const { hideTopBar, name, treeStore, maxRows, onGoToRef, rowRenderer: customRowRenderer } = props;
17+
export const SchemaTree: React.FC<ISchemaTree> = props => {
18+
const { treeStore, maxRows, onGoToRef, rowRenderer: customRowRenderer } = props;
2419

2520
React.useEffect(() => {
2621
treeStore.events.on(TreeListEvents.NodeClick, (e, node) => {
27-
if ('children' in node) {
22+
if (isParentNode(node)) {
2823
treeStore.toggleExpand(node);
2924
}
3025
});
@@ -46,21 +41,13 @@ export const SchemaTree = observer<ISchemaTree>(props => {
4641
);
4742

4843
return (
49-
<>
50-
{name && !hideTopBar && (
51-
<div className="flex items-center text-sm px-2 font-semibold" style={{ height: 30 }}>
52-
{name}
53-
</div>
54-
)}
55-
56-
<TreeList
57-
striped
58-
maxRows={maxRows !== undefined ? maxRows + 0.5 : maxRows}
59-
store={treeStore}
60-
rowRenderer={rowRenderer}
61-
canDrag={canDrag}
62-
/>
63-
</>
44+
<TreeList
45+
draggable={false}
46+
striped
47+
maxRows={maxRows !== undefined ? maxRows + 0.5 : maxRows}
48+
store={treeStore}
49+
rowRenderer={rowRenderer}
50+
/>
6451
);
65-
});
52+
};
6653
SchemaTree.displayName = 'JsonSchemaViewer.SchemaTree';

src/components/__tests__/SchemaTree.spec.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import * as React from 'react';
88
import { useMetadata } from '../../hooks/useMetadata';
99
import { SchemaTree } from '../index';
1010

11-
jest.mock('mobx-react-lite', () => ({
12-
observer: (children: any) => children,
13-
}));
1411
jest.mock('../../hooks/useMetadata');
1512

1613
const schema: JSONSchema4 = {
@@ -64,8 +61,7 @@ describe('SchemaTree component', () => {
6461
it('should be not draggable', () => {
6562
const treeList = shallow(<SchemaTree schema={schema} treeStore={store} />).find(TreeList);
6663

67-
expect(treeList.prop('canDrag')).toHaveLength(0);
68-
expect(treeList.prop('canDrag')!({} as any)).toBe(false);
64+
expect(treeList.prop('draggable')).toBe(false);
6965
});
7066
});
7167
});

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10966,7 +10966,7 @@ [email protected], mkdirp@^1.0.4:
1096610966
dependencies:
1096710967
minimist "0.0.8"
1096810968

10969-
mobx-react-lite@^1.4.1, mobx-react-lite@^1.5.2:
10969+
mobx-react-lite@^1.5.2:
1097010970
version "1.5.2"
1097110971
resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-1.5.2.tgz#c4395b0568b9cb16f07669d8869cc4efa1b8656d"
1097210972
integrity sha512-PyZmARqqWtpuQaAoHF5pKX7h6TKNLwq6vtovm4zZvG6sEbMRHHSqioGXSeQbpRmG8Kw8uln3q/W1yMO5IfL5Sg==

0 commit comments

Comments
 (0)