Skip to content

Commit 0694cc3

Browse files
dev tools for JSON (#411)
1 parent 852d649 commit 0694cc3

File tree

8 files changed

+55
-88
lines changed

8 files changed

+55
-88
lines changed

dev/App.js

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import React, {Component} from 'react';
22
import {hot} from 'react-hot-loader';
33
import plotly from 'plotly.js/dist/plotly';
44
import '../src/styles/main.scss';
5-
import Nav from './Nav';
6-
import PlotlyEditor from '../src';
5+
import 'react-select/dist/react-select.css';
6+
import ReactJson from 'react-json-view';
7+
import Select from 'react-select';
8+
import PlotlyEditor, {DefaultEditor, Panel} from '../src';
79

810
// https://github.com/plotly/react-chart-editor#mapbox-access-tokens
911
import ACCESS_TOKENS from '../accessTokens';
@@ -82,12 +84,43 @@ class App extends Component {
8284
useResizeHandler
8385
debug
8486
advancedTraceTypeSelector
85-
/>
86-
<Nav
87-
currentMockIndex={this.state.currentMockIndex}
88-
loadMock={this.loadMock}
89-
mocks={this.state.mocks}
90-
/>
87+
>
88+
{' '}
89+
<DefaultEditor>
90+
<Panel group="Dev" name="JSON">
91+
<Select
92+
clearable={true}
93+
value={this.state.currentMockIndex}
94+
name="mock-dropdown"
95+
options={this.state.mocks.map((item, i) => ({
96+
label: item,
97+
value: i,
98+
}))}
99+
searchable={true}
100+
searchPromptText="Search for a mock"
101+
onChange={option => this.loadMock(option.value)}
102+
noResultsText={'No Results'}
103+
placeholder={'Search for a mock'}
104+
/>
105+
<br />
106+
<ReactJson
107+
enableClipboard={false}
108+
name={false}
109+
displayDataTypes={false}
110+
displayObjectSize={false}
111+
indentWidth={2}
112+
onAdd={({updated_src}) => this.setState(updated_src)}
113+
onEdit={({updated_src}) => this.setState(updated_src)}
114+
onDelete={({updated_src}) => this.setState(updated_src)}
115+
src={{
116+
data: this.state.data,
117+
layout: this.state.layout,
118+
frames: this.state.frames,
119+
}}
120+
/>
121+
</Panel>
122+
</DefaultEditor>
123+
</PlotlyEditor>
91124
</div>
92125
);
93126
}

dev/Nav.js

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

dev/styles.css

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,7 @@ body {
55
}
66

77
.app {
8-
height: calc(100vh - 50px);
9-
max-height: calc(100vh - 50px);
8+
height: 100vh;
9+
max-height: 100vh;
1010
}
1111

12-
.mock-nav {
13-
height: 50px;
14-
width: 100%;
15-
background-color: #506784;
16-
display: inline-flex;
17-
color: white;
18-
}
19-
20-
.mock-nav__label {
21-
line-height: 50px;
22-
padding-left: 10px;
23-
}
24-
25-
.mock-nav__select {
26-
width: 300px;
27-
margin-left: 20px;
28-
margin-right: 20px;
29-
margin-top: 7px;
30-
}
31-
32-
.Select.open-top .Select-menu-outer {
33-
top: auto;
34-
bottom: 100%;
35-
border-top-right-radius: 4px;
36-
border-top-left-radius: 4px;
37-
border-bottom-right-radius: unset;
38-
border-bottom-left-radius: unset;
39-
}
40-
.Select.open-top .Select-option:first-child {
41-
border-top-right-radius: 4px;
42-
border-top-left-radius: 4px;
43-
}
44-
.Select.open-top .Select-option:last-child {
45-
border-bottom-right-radius: unset;
46-
border-bottom-left-radius: unset;
47-
}
48-
.Select.open-top .Select.is-open > .Select-control {
49-
border-top-right-radius: unset;
50-
border-top-left-radius: unset;
51-
border-bottom-right-radius: 4px;
52-
border-bottom-left-radius: 4px;
53-
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"react": "^16.0.0",
6464
"react-dom": "^16.0.0",
6565
"react-hot-loader": "^4.0.0-beta.21",
66+
"react-json-view": "^1.16.1",
6667
"react-test-renderer": "^16.2.0",
6768
"sass-loader": "^6.0.6",
6869
"style-loader": "^0.19.1",

src/DefaultEditor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
StyleUpdateMenusPanel,
1717
} from './default_panels';
1818

19-
const DefaultEditor = ({localize: _}) => (
19+
const DefaultEditor = ({children, localize: _}) => (
2020
<Fragment>
2121
<PanelMenuWrapper>
2222
<GraphCreatePanel group={_('Graph')} name={_('Create')} />
@@ -30,12 +30,14 @@ const DefaultEditor = ({localize: _}) => (
3030
<StyleImagesPanel group={_('Style')} name={_('Images')} />
3131
<StyleSlidersPanel group={_('Style')} name={_('Sliders')} />
3232
<StyleUpdateMenusPanel group={_('Style')} name={_('Update Menus')} />
33+
{children ? children : null}
3334
</PanelMenuWrapper>
3435
</Fragment>
3536
);
3637

3738
DefaultEditor.propTypes = {
3839
localize: PropTypes.func,
40+
children: PropTypes.node,
3941
};
4042

4143
export default localize(DefaultEditor);

src/components/PanelMenuWrapper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class PanelsWithSidebar extends Component {
4848
let groupIndex;
4949

5050
React.Children.forEach(children, child => {
51+
if (!child) {
52+
return;
53+
}
5154
const group = child.props.group;
5255
const name = child.props.name;
5356

@@ -81,6 +84,7 @@ class PanelsWithSidebar extends Component {
8184
{React.Children.map(
8285
this.props.children,
8386
(child, i) =>
87+
child === null ||
8488
this.state.group !== child.props.group ||
8589
this.state.panel !== child.props.name
8690
? null

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import PlotlyEditor from './PlotlyEditor';
2+
import DefaultEditor from './DefaultEditor';
23
import EditorControls from './EditorControls';
34
import {
45
connectAnnotationToLayout,
@@ -143,6 +144,7 @@ export {
143144
localizeString,
144145
walkObject,
145146
EditorControls,
147+
DefaultEditor,
146148
};
147149

148150
export default PlotlyEditor;

webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module.exports = {
3838
},
3939
],
4040
},
41+
42+
plugins: [new webpack.IgnorePlugin(/vertx/)],
4143
devServer: {
4244
open: true,
4345
contentBase: './dev',

0 commit comments

Comments
 (0)