@@ -3,9 +3,13 @@ import {hot} from 'react-hot-loader';
3
3
import plotly from 'plotly.js/dist/plotly' ;
4
4
import '../src/styles/main.scss' ;
5
5
import 'react-select/dist/react-select.css' ;
6
- import ReactJson from 'react-json-view' ;
6
+ import brace from 'brace' ; // eslint-disable-line no-unused-vars
7
+ import AceEditor from 'react-ace' ;
7
8
import Select from 'react-select' ;
8
9
import PlotlyEditor , { DefaultEditor , Panel } from '../src' ;
10
+ import Inspector from 'react-inspector' ;
11
+ import 'brace/mode/json' ;
12
+ import 'brace/theme/textmate' ;
9
13
10
14
// https://github.com/plotly/react-chart-editor#mapbox-access-tokens
11
15
import ACCESS_TOKENS from '../accessTokens' ;
@@ -39,6 +43,8 @@ class App extends Component {
39
43
} ;
40
44
41
45
this . loadMock = this . loadMock . bind ( this ) ;
46
+ this . loadJSON = this . loadJSON . bind ( this ) ;
47
+ this . updateState = this . updateState . bind ( this ) ;
42
48
}
43
49
44
50
componentWillMount ( ) {
@@ -59,15 +65,32 @@ class App extends Component {
59
65
)
60
66
. then ( response => response . json ( ) )
61
67
. then ( figure => {
62
- this . setState ( {
63
- currentMockIndex : mockIndex ,
64
- data : figure . data ,
65
- layout : figure . layout ,
66
- frames : figure . frames ,
67
- } ) ;
68
+ const { data, layout, frames} = figure ;
69
+ this . updateState ( data , layout , frames , mockIndex ) ;
68
70
} ) ;
69
71
}
70
72
73
+ updateState ( data , layout , frames , currentMockIndex ) {
74
+ this . setState ( {
75
+ data,
76
+ layout,
77
+ frames,
78
+ currentMockIndex,
79
+ full : 'hit refresh' ,
80
+ json_error : false ,
81
+ json_string : JSON . stringify ( { data, layout, frames} , null , 2 ) ,
82
+ } ) ;
83
+ }
84
+
85
+ loadJSON ( ) {
86
+ try {
87
+ const { data, layout, frames} = JSON . parse ( this . state . json_string ) ;
88
+ this . updateState ( data , layout , frames ) ;
89
+ } catch ( e ) {
90
+ this . setState ( { json_error : true } ) ;
91
+ }
92
+ }
93
+
71
94
render ( ) {
72
95
return (
73
96
< div className = "app" >
@@ -79,47 +102,81 @@ class App extends Component {
79
102
dataSources = { dataSources }
80
103
dataSourceOptions = { dataSourceOptions }
81
104
plotly = { plotly }
82
- onUpdate = { ( data , layout , frames ) =>
83
- this . setState ( { data, layout, frames} )
84
- }
105
+ onUpdate = { this . updateState }
106
+ divId = "gd"
85
107
useResizeHandler
86
108
debug
87
109
advancedTraceTypeSelector
88
110
>
89
- { ' ' }
90
111
< DefaultEditor >
91
112
< Panel group = "Dev" name = "JSON" >
92
- < Select
93
- clearable = { true }
94
- value = { this . state . currentMockIndex }
95
- name = "mock-dropdown"
96
- options = { this . state . mocks . map ( ( item , i ) => ( {
97
- label : item ,
98
- value : i ,
99
- } ) ) }
100
- searchable = { true }
101
- searchPromptText = "Search for a mock"
102
- onChange = { option => this . loadMock ( option . value ) }
103
- noResultsText = { 'No Results' }
104
- placeholder = { 'Search for a mock' }
105
- />
113
+ < div className = "mocks" >
114
+ < Select
115
+ clearable = { false }
116
+ value = { this . state . currentMockIndex }
117
+ name = "mock-dropdown"
118
+ options = { this . state . mocks . map ( ( item , i ) => ( {
119
+ label : item ,
120
+ value : i ,
121
+ } ) ) }
122
+ searchable = { true }
123
+ searchPromptText = "Search for a mock"
124
+ onChange = { option => this . loadMock ( option . value ) }
125
+ noResultsText = { 'No Results' }
126
+ placeholder = { 'Search for a mock' }
127
+ />
128
+ </ div >
106
129
< br />
107
- < ReactJson
108
- enableClipboard = { false }
109
- name = { false }
110
- displayDataTypes = { false }
111
- displayObjectSize = { false }
112
- indentWidth = { 2 }
113
- onAdd = { ( { updated_src} ) => this . setState ( updated_src ) }
114
- onEdit = { ( { updated_src} ) => this . setState ( updated_src ) }
115
- onDelete = { ( { updated_src} ) => this . setState ( updated_src ) }
116
- src = { {
117
- data : this . state . data ,
118
- layout : this . state . layout ,
119
- frames : this . state . frames ,
130
+ < button
131
+ onClick = { this . loadJSON }
132
+ style = { { background : this . state . json_error ? 'pink' : 'white' } }
133
+ >
134
+ Save
135
+ </ button >
136
+ < br />
137
+ < AceEditor
138
+ mode = "json"
139
+ theme = "textmate"
140
+ onChange = { json_string => this . setState ( { json_string} ) }
141
+ value = { this . state . json_string }
142
+ name = "UNIQUE_ID_OF_DIV"
143
+ style = { { height : '80vh' } }
144
+ setOptions = { {
145
+ showLineNumbers : false ,
146
+ tabSize : 2 ,
120
147
} }
148
+ commands = { [
149
+ {
150
+ name : 'save' ,
151
+ bindKey : { win : 'Ctrl-s' , mac : 'Command-s' } ,
152
+ exec : this . loadJSON ,
153
+ } ,
154
+ ] }
121
155
/>
122
156
</ Panel >
157
+ < Panel group = "Dev" name = "Inspector" >
158
+ < button
159
+ onClick = { ( ) => {
160
+ const gd = document . getElementById ( 'gd' ) || { } ;
161
+ this . setState ( {
162
+ full : {
163
+ _fullData : gd . _fullData || [ ] ,
164
+ _fullLayout : gd . _fullLayout || { } ,
165
+ } ,
166
+ } ) ;
167
+ } }
168
+ >
169
+ Refresh
170
+ </ button >
171
+ < br />
172
+ < div style = { { height : '80vh' } } >
173
+ < Inspector
174
+ data = { { _full : this . state . full } }
175
+ expandLevel = { 2 }
176
+ sortObjectKeys = { true }
177
+ />
178
+ </ div >
179
+ </ Panel >
123
180
</ DefaultEditor >
124
181
</ PlotlyEditor >
125
182
</ div >
0 commit comments