Skip to content

Commit f232c62

Browse files
committed
chore: reorganize file structure
1 parent eff3288 commit f232c62

File tree

12 files changed

+68
-55
lines changed

12 files changed

+68
-55
lines changed

src/__stories__/JsonSchemaViewer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { State, Store } from '@sambego/storybook-state';
44
import { action } from '@storybook/addon-actions';
55
import { boolean, number, object, text, withKnobs } from '@storybook/addon-knobs';
66
import { storiesOf } from '@storybook/react';
7-
import { JsonSchemaViewer } from '../JsonSchemaViewer';
7+
import { JsonSchemaViewer } from '../components/JsonSchemaViewer';
88

99
import * as schema from '../__fixtures__/default-schema.json';
1010
import * as schemaWithRefs from '../__fixtures__/ref/original.json';
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import { TreeStore } from '@stoplight/tree-list';
22
import { Omit } from '@stoplight/types';
33
import { runInAction } from 'mobx';
44
import * as React from 'react';
5-
import { ErrorMessage } from './components/common/ErrorMessage';
6-
import { MutedText } from './components/common/MutedText';
7-
import { ISchemaView, SchemaView } from './SchemaView';
8-
import { ThemeZone } from './theme';
9-
import { isSchemaViewerEmpty } from './utils/isSchemaViewerEmpty';
10-
import { renderSchema } from './utils/renderSchema';
11-
12-
export interface IJsonSchemaViewer extends Omit<ISchemaView, 'emptyText' | 'treeStore'> {
5+
import { ThemeZone } from '../theme';
6+
import { isSchemaViewerEmpty, renderSchema } from '../utils';
7+
import { ErrorMessage } from './common/ErrorMessage';
8+
import { MutedText } from './common/MutedText';
9+
import { ISchemaTree, SchemaTree } from './SchemaTree';
10+
11+
export interface IJsonSchemaViewer extends Omit<ISchemaTree, 'emptyText' | 'treeStore'> {
1312
emptyText?: string;
1413
defaultExpandedDepth?: number;
1514
}
@@ -90,7 +89,7 @@ export class JsonSchemaViewer extends React.PureComponent<IJsonSchemaViewer, IJs
9089

9190
return (
9291
<ThemeZone name="json-schema-viewer">
93-
<SchemaView expanded={expanded} name={name} schema={schema} treeStore={this.treeStore} {...props} />
92+
<SchemaTree expanded={expanded} name={name} schema={schema} treeStore={this.treeStore} {...props} />
9493
</ThemeZone>
9594
);
9695
}

src/components/MaskedSchema.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Dialog } from '@stoplight/ui-kit';
22
import * as React from 'react';
3-
import { IJsonSchemaViewer, JsonSchemaViewer } from '../JsonSchemaViewer';
3+
import { IJsonSchemaViewer, JsonSchemaViewer } from './JsonSchemaViewer';
44

55
export interface IMaskedSchema extends IJsonSchemaViewer {
66
onClose(): void;
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { Omit } from '@stoplight/types';
22
import { Box, Button, Checkbox, Flex, IBox } from '@stoplight/ui-kit';
33
import * as React from 'react';
44
import { IMasking, SchemaNodeWithMeta } from '../types';
5-
import { formatRef } from '../utils/formatRef';
6-
import { isCombiner } from '../utils/isCombiner';
7-
import { isRef } from '../utils/isRef';
8-
import { pathToString } from '../utils/pathToString';
5+
import { formatRef, isCombiner, isRef, pathToString } from '../utils';
96
import { Additional } from './Additional';
107
import { MutedText } from './common/MutedText';
118
import { Divider } from './Divider';
@@ -14,12 +11,12 @@ import { Type } from './Type';
1411
import { Types } from './Types';
1512
import { Validations } from './Validations';
1613

17-
export interface IProperty extends Omit<IBox, 'onClick'>, IMasking {
14+
export interface ISchemaRow extends Omit<IBox, 'onClick'>, IMasking {
1815
node: SchemaNodeWithMeta;
1916
onMaskEdit(node: SchemaNodeWithMeta): void;
2017
}
2118

22-
export const Property: React.FunctionComponent<IProperty> = ({
19+
export const SchemaRow: React.FunctionComponent<ISchemaRow> = ({
2320
node,
2421
canSelect,
2522
onSelect,
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { Box, IBox, ThemeZone } from '@stoplight/ui-kit';
44
import { JSONSchema4 } from 'json-schema';
55
import _isEmpty = require('lodash/isEmpty');
66
import * as React from 'react';
7-
import { MaskedSchema } from './components/MaskedSchema';
8-
import { IProperty, Property } from './components/Property';
9-
import { TopBar } from './components/TopBar';
10-
import { useMetadata } from './hooks/useMetadata';
7+
import { useMetadata } from '../hooks';
8+
import { useTheme } from '../theme';
9+
import { IMasking, SchemaNodeWithMeta } from '../types';
10+
import { lookupRef } from '../utils';
1111
import { IJsonSchemaViewer } from './JsonSchemaViewer';
12-
import { useTheme } from './theme';
13-
import { IMasking, SchemaNodeWithMeta } from './types';
14-
import { lookupRef } from './utils/lookupRef';
12+
import { MaskedSchema } from './MaskedSchema';
13+
import { ISchemaRow, SchemaRow } from './SchemaRow';
14+
import { TopBar } from './TopBar';
1515

1616
const canDrag = () => false;
1717

18-
export interface ISchemaView extends Omit<IBox, 'onSelect'>, IMasking {
18+
export interface ISchemaTree extends Omit<IBox, 'onSelect'>, IMasking {
1919
name?: string;
2020
dereferencedSchema?: JSONSchema4;
2121
schema: JSONSchema4;
@@ -24,7 +24,7 @@ export interface ISchemaView extends Omit<IBox, 'onSelect'>, IMasking {
2424
treeStore: TreeStore;
2525
}
2626

27-
export const SchemaView: React.FunctionComponent<ISchemaView> = props => {
27+
export const SchemaTree: React.FunctionComponent<ISchemaTree> = props => {
2828
const {
2929
emptyText,
3030
expanded = false,
@@ -44,7 +44,7 @@ export const SchemaView: React.FunctionComponent<ISchemaView> = props => {
4444

4545
const metadata = useMetadata(schema);
4646

47-
const handleMaskEdit = React.useCallback<IProperty['onMaskEdit']>(
47+
const handleMaskEdit = React.useCallback<ISchemaRow['onMaskEdit']>(
4848
node => {
4949
setMaskedSchema(lookupRef(node.path, dereferencedSchema));
5050
},
@@ -84,7 +84,7 @@ export const SchemaView: React.FunctionComponent<ISchemaView> = props => {
8484
canDrag={canDrag}
8585
store={treeStore}
8686
onNodeClick={handleNodeClick}
87-
rowRenderer={node => <Property node={node.metadata as SchemaNodeWithMeta} {...itemData} />}
87+
rowRenderer={node => <SchemaRow node={node.metadata as SchemaNodeWithMeta} {...itemData} />}
8888
/>
8989
</ThemeZone>
9090
</Box>

src/__tests__/JsonSchemaViewer.spec.tsx renamed to src/components/__tests__/JsonSchemaViewer.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { shallow } from 'enzyme';
22
import 'jest-enzyme';
33
import * as React from 'react';
4-
import { MutedText } from '../components/common/MutedText';
4+
import { isSchemaViewerEmpty } from '../../utils';
5+
import { MutedText } from '../common/MutedText';
56
import { JsonSchemaViewer } from '../JsonSchemaViewer';
6-
import { SchemaView } from '../SchemaView';
7-
import { isSchemaViewerEmpty } from '../utils/isSchemaViewerEmpty';
7+
import { SchemaTree } from '../SchemaTree';
88

9-
jest.mock('../theme');
10-
jest.mock('../utils/isSchemaViewerEmpty');
9+
jest.mock('../../theme');
10+
jest.mock('../../utils/isSchemaViewerEmpty');
1111

1212
const schema = {
1313
properties: {
@@ -32,14 +32,14 @@ describe('JSON Schema Viewer component', () => {
3232
const wrapper = shallow(<JsonSchemaViewer schema={{}} />);
3333
expect(isSchemaViewerEmpty).toHaveBeenCalledWith({});
3434
expect(wrapper.find(MutedText)).toExist();
35-
expect(wrapper.find(SchemaView)).not.toExist();
35+
expect(wrapper.find(SchemaTree)).not.toExist();
3636
});
3737

3838
test('should render SchemaView if schema is provided', () => {
3939
(isSchemaViewerEmpty as jest.Mock).mockReturnValue(false);
4040
const wrapper = shallow(<JsonSchemaViewer schema={schema} />);
4141
expect(isSchemaViewerEmpty).toHaveBeenCalledWith(schema);
4242
expect(wrapper.find(MutedText)).not.toExist();
43-
expect(wrapper.find(SchemaView)).toExist();
43+
expect(wrapper.find(SchemaTree)).toExist();
4444
});
4545
});

src/__tests__/SchemaView.spec.tsx renamed to src/components/__tests__/SchemaTree.spec.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import 'jest-enzyme';
44
import { JSONSchema4 } from 'json-schema';
55
import * as React from 'react';
66
import { ReactElement } from 'react';
7-
import { Property } from '../components/Property';
8-
import { TopBar } from '../components/TopBar';
9-
import { useMetadata } from '../hooks/useMetadata';
10-
import { SchemaView } from '../SchemaView';
11-
import { ITreeNodeMeta } from '../types';
7+
import { SchemaRow, SchemaTree, TopBar } from '../../components';
8+
import { useMetadata } from '../../hooks';
9+
import { ITreeNodeMeta } from '../../types';
1210

13-
jest.mock('../theme');
14-
jest.mock('../hooks/useMetadata');
11+
jest.mock('../../theme');
12+
jest.mock('../../hooks');
1513

1614
const schema: JSONSchema4 = {
1715
type: 'object',
@@ -31,7 +29,7 @@ const schema: JSONSchema4 = {
3129
},
3230
};
3331

34-
describe('SchemaView component', () => {
32+
describe('SchemaTree component', () => {
3533
let useStateSpy: jest.SpyInstance;
3634
let setStateActionSpy: jest.Mock;
3735
let store: TreeStore;
@@ -52,12 +50,12 @@ describe('SchemaView component', () => {
5250

5351
describe('top bar', () => {
5452
test('should not be rendered if hideTopBar is truthy', () => {
55-
const wrapper = shallow(<SchemaView schema={schema} treeStore={store} hideTopBar />);
53+
const wrapper = shallow(<SchemaTree schema={schema} treeStore={store} hideTopBar />);
5654
expect(wrapper.find(TopBar)).not.toExist();
5755
});
5856

5957
test('should be rendered if name is given', () => {
60-
const wrapper = shallow(<SchemaView schema={schema} treeStore={store} name="test" />);
58+
const wrapper = shallow(<SchemaTree schema={schema} treeStore={store} name="test" />);
6159
expect(wrapper.find(TopBar)).toExist();
6260
expect(wrapper.find(TopBar)).toHaveProp('name', 'test');
6361
});
@@ -68,7 +66,7 @@ describe('SchemaView component', () => {
6866
$schema: 'schema',
6967
});
7068

71-
const wrapper = shallow(<SchemaView schema={schema} treeStore={store} name="test" />);
69+
const wrapper = shallow(<SchemaTree schema={schema} treeStore={store} name="test" />);
7270
expect(wrapper.find(TopBar)).toExist();
7371
expect(wrapper.find(TopBar)).toHaveProp('name', 'test');
7472
});
@@ -79,14 +77,14 @@ describe('SchemaView component', () => {
7977
$schema: 'schema',
8078
});
8179

82-
const wrapper = shallow(<SchemaView schema={schema} treeStore={store} name="test" hideTopBar />);
80+
const wrapper = shallow(<SchemaTree schema={schema} treeStore={store} name="test" hideTopBar />);
8381
expect(wrapper.find(TopBar)).not.toExist();
8482
});
8583
});
8684

8785
describe('tree-list', () => {
8886
test('should be rendered', () => {
89-
const wrapper = shallow(<SchemaView schema={schema} treeStore={store} />);
87+
const wrapper = shallow(<SchemaTree schema={schema} treeStore={store} />);
9088

9189
expect(wrapper.find(TreeList)).toExist();
9290
expect(wrapper.find(TreeList)).toHaveProp({
@@ -97,20 +95,20 @@ describe('SchemaView component', () => {
9795
});
9896

9997
test('should be not draggable', () => {
100-
const treeList = shallow(<SchemaView schema={schema} treeStore={store} />).find(TreeList);
98+
const treeList = shallow(<SchemaTree schema={schema} treeStore={store} />).find(TreeList);
10199

102100
expect(treeList.prop('canDrag')).toHaveLength(0);
103101
expect(treeList.prop('canDrag')!({} as any)).toBe(false);
104102
});
105103

106104
test('should have extra padding if top bar is rendered', () => {
107-
const treeList = shallow(<SchemaView schema={schema} treeStore={store} name="my-schema" />).find(TreeList);
105+
const treeList = shallow(<SchemaTree schema={schema} treeStore={store} name="my-schema" />).find(TreeList);
108106

109107
expect(treeList).toHaveProp('top', '40px');
110108
});
111109

112110
test('should render property for each row', () => {
113-
const treeList = shallow(<SchemaView schema={schema} treeStore={store} />).find(TreeList);
111+
const treeList = shallow(<SchemaTree schema={schema} treeStore={store} />).find(TreeList);
114112
const node: TreeListNode<ITreeNodeMeta> = {
115113
id: 'random-id',
116114
level: 0,
@@ -123,7 +121,7 @@ describe('SchemaView component', () => {
123121
const rendered = treeList.prop('rowRenderer')!(node) as ReactElement<any>;
124122

125123
expect(rendered).toMatchObject({
126-
type: Property,
124+
type: SchemaRow,
127125
props: expect.objectContaining({
128126
node: node.metadata,
129127
}),

src/components/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export * from './Divider';
2+
export * from './JsonSchemaViewer';
3+
export * from './MaskedSchema';
4+
export * from './SchemaRow';
5+
export * from './SchemaTree';
6+
export * from './TopBar';
7+
export * from './Type';
8+
export * from './Types';

src/consts.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useMetadata';

0 commit comments

Comments
 (0)