1
- import React , { Component , Fragment } from " react" ;
2
- import { connect } from " react-redux" ;
3
- import { withStyles } from " @material-ui/core/styles" ;
4
- import FormControl from " @material-ui/core/FormControl" ;
5
- import Grid from " @material-ui/core/Grid" ;
6
- import TextField from " @material-ui/core/TextField" ;
7
- import Button from " @material-ui/core/Button" ;
8
- import Select from " @material-ui/core/Select" ;
9
- import Switch from " @material-ui/core/Switch" ;
10
- import InputLabel from " @material-ui/core/InputLabel" ;
11
- import { addProp , deleteProp } from " ../actions/components.ts" ;
12
- import DataTable from " ./DataTable.tsx" ;
13
- import { ComponentInt } from " ../utils/Interfaces.ts" ;
1
+ import React , { Component , Fragment } from ' react' ;
2
+ import { connect } from ' react-redux' ;
3
+ import { withStyles } from ' @material-ui/core/styles' ;
4
+ import FormControl from ' @material-ui/core/FormControl' ;
5
+ import Grid from ' @material-ui/core/Grid' ;
6
+ import TextField from ' @material-ui/core/TextField' ;
7
+ import Button from ' @material-ui/core/Button' ;
8
+ import Select from ' @material-ui/core/Select' ;
9
+ import Switch from ' @material-ui/core/Switch' ;
10
+ import InputLabel from ' @material-ui/core/InputLabel' ;
11
+ import { addProp , deleteProp } from ' ../actions/components.ts' ;
12
+ import DataTable from ' ./DataTable.tsx' ;
13
+ import { ComponentInt } from ' ../utils/Interfaces.ts' ;
14
14
15
15
const styles = theme => ( {
16
16
root : {
17
- display : " flex" ,
18
- justifyContent : " center" ,
19
- flexWrap : " wrap"
17
+ display : ' flex' ,
18
+ justifyContent : ' center' ,
19
+ flexWrap : ' wrap'
20
20
} ,
21
21
chip : {
22
- color : " #eee" ,
23
- backgroundColor : " #333333"
22
+ color : ' #eee' ,
23
+ backgroundColor : ' #333333'
24
24
} ,
25
25
column : {
26
- display : " inline-flex" ,
27
- alignItems : " baseline"
26
+ display : ' inline-flex' ,
27
+ alignItems : ' baseline'
28
28
} ,
29
29
icon : {
30
- fontSize : " 20px" ,
31
- color : " #eee" ,
32
- opacity : " 0.7" ,
33
- transition : " all .2s ease" ,
30
+ fontSize : ' 20px' ,
31
+ color : ' #eee' ,
32
+ opacity : ' 0.7' ,
33
+ transition : ' all .2s ease' ,
34
34
35
- " &:hover" : {
36
- color : " red"
35
+ ' &:hover' : {
36
+ color : ' red'
37
37
}
38
38
} ,
39
39
cssLabel : {
40
- color : " white" ,
40
+ color : ' white' ,
41
41
42
- " &$cssFocused" : {
43
- color : " green"
42
+ ' &$cssFocused' : {
43
+ color : ' green'
44
44
}
45
45
} ,
46
46
cssFocused : { } ,
47
47
input : {
48
- color : " #eee" ,
49
- marginBottom : " 10px" ,
50
- width : " 60%"
48
+ color : ' #eee' ,
49
+ marginBottom : ' 10px' ,
50
+ width : ' 60%'
51
51
} ,
52
52
light : {
53
- color : " #eee"
53
+ color : ' #eee'
54
54
} ,
55
55
avatar : {
56
- color : " #eee" ,
57
- fontSize : " 10px"
56
+ color : ' #eee' ,
57
+ fontSize : ' 10px'
58
58
}
59
59
} ) ;
60
60
@@ -86,39 +86,39 @@ const mapStateToProps = (store: any) => ({
86
86
} ) ;
87
87
88
88
const availablePropTypes = {
89
- string : " STR" ,
90
- number : " NUM" ,
91
- object : " OBJ" ,
92
- array : " ARR" ,
93
- boolean : " BOOL" ,
94
- function : " FUNC" ,
89
+ string : ' STR' ,
90
+ number : ' NUM' ,
91
+ object : ' OBJ' ,
92
+ array : ' ARR' ,
93
+ boolean : ' BOOL' ,
94
+ function : ' FUNC' ,
95
95
// symbol: 'SYM',
96
- node : " NODE" ,
97
- element : " ELEM" ,
98
- any : " ANY" ,
99
- tuple : " TUP" ,
100
- enum : " ENUM"
96
+ node : ' NODE' ,
97
+ element : ' ELEM' ,
98
+ any : ' ANY' ,
99
+ tuple : ' TUP' ,
100
+ enum : ' ENUM'
101
101
} ;
102
102
103
103
const typeOptions = [
104
104
< option value = "" key = "" /> ,
105
105
...Object . keys ( availablePropTypes ) . map ( type => (
106
- < option value = { type } key = { type } style = { { color : " #000" } } >
106
+ < option value = { type } key = { type } style = { { color : ' #000' } } >
107
107
{ type }
108
108
</ option >
109
109
) )
110
110
] ;
111
111
112
112
class Props extends Component {
113
113
state = {
114
- propKey : "" ,
115
- propValue : "" ,
114
+ propKey : '' ,
115
+ propValue : '' ,
116
116
propRequired : true ,
117
- propType : ""
117
+ propType : ''
118
118
} ;
119
119
120
120
handleChange = event => {
121
- if ( event . target . id === " propKey" ) {
121
+ if ( event . target . id === ' propKey' ) {
122
122
this . setState ( {
123
123
[ event . target . id ] : event . target . value . trim ( )
124
124
} ) ;
@@ -135,10 +135,15 @@ class Props extends Component {
135
135
} ) ;
136
136
} ;
137
137
138
+ // function that handles the addition of props to a given componnent
139
+ // added regex to strip usr input from non alpha numeric properties
140
+ // presence of these characters crashes the app and should not be a valid input anyways
138
141
handleAddProp = event => {
139
142
event . preventDefault ( ) ;
140
143
141
- const { propKey, propValue, propRequired, propType } = this . state ;
144
+ let { propKey, propValue, propRequired, propType } = this . state ;
145
+ propKey = propKey . replace ( / \W + / gi, '' ) ;
146
+ propValue = propKey . replace ( / \W + / gi, '' ) ;
142
147
143
148
// check if prop exists with same key. CANNOT have duplicates
144
149
const savedPropKeys = this . props . focusComponent . props . map ( p => p . key ) ;
@@ -149,7 +154,7 @@ class Props extends Component {
149
154
150
155
// check if prop starts with digits. Digits at string start breaks indexedDB
151
156
if ( / ^ \d / . test ( propKey ) ) {
152
- window . alert ( " Props are not allowed to begin with digits" ) ;
157
+ window . alert ( ' Props are not allowed to begin with digits' ) ;
153
158
return ;
154
159
}
155
160
@@ -161,17 +166,17 @@ class Props extends Component {
161
166
} ) ;
162
167
163
168
this . setState ( {
164
- propKey : "" ,
165
- propValue : "" ,
169
+ propKey : '' ,
170
+ propValue : '' ,
166
171
propRequired : true ,
167
- propType : ""
172
+ propType : ''
168
173
} ) ;
169
174
} ;
170
175
171
176
render ( ) {
172
177
const { focusComponent, classes, deleteProp, addProp } = this . props ;
173
178
174
- const rowHeader = [ " _Key" , " Value" , " Type" , " Required" ] ;
179
+ const rowHeader = [ ' _Key' , ' Value' , ' Type' , ' Required' ] ;
175
180
// prepare the saved Props in a nice way, so you can sent them to TableData
176
181
const propsRows = focusComponent . props . map ( prop => ( {
177
182
_Key : prop . key ,
@@ -182,17 +187,17 @@ class Props extends Component {
182
187
} ) ) ;
183
188
184
189
return (
185
- < div className = { " htmlattr" } >
186
- { " " }
190
+ < div className = { ' htmlattr' } >
191
+ { ' ' }
187
192
{ Object . keys ( focusComponent ) . length < 1 ? (
188
- < div style = { { marginTop : " 20px" , width : " 90%" } } >
193
+ < div style = { { marginTop : ' 20px' , width : ' 90%' } } >
189
194
Click a component to view its props.
190
195
</ div >
191
196
) : (
192
197
< Fragment >
193
198
< div
194
199
className = "props-container"
195
- style = { { marginTop : " 20px" , width : " 90%" , height : " 80%" } }
200
+ style = { { marginTop : ' 20px' , width : ' 90%' , height : ' 80%' } }
196
201
>
197
202
< Grid container spacing = { 8 } >
198
203
< Grid item xs = { 3 } >
@@ -232,10 +237,7 @@ class Props extends Component {
232
237
</ Grid >
233
238
< Grid item xs = { 6 } >
234
239
< FormControl required >
235
- < InputLabel
236
- className = { classes . light }
237
- htmlFor = "propType"
238
- >
240
+ < InputLabel className = { classes . light } htmlFor = "propType" >
239
241
Type
240
242
</ InputLabel >
241
243
< Select
@@ -253,10 +255,7 @@ class Props extends Component {
253
255
</ Grid >
254
256
< Grid item xs = { 6 } >
255
257
< div className = { classes . column } >
256
- < InputLabel
257
- className = { classes . light }
258
- htmlFor = "propRequired"
259
- >
258
+ < InputLabel className = { classes . light } htmlFor = "propRequired" >
260
259
Required?
261
260
</ InputLabel >
262
261
< Switch
@@ -300,7 +299,4 @@ class Props extends Component {
300
299
}
301
300
}
302
301
303
- export default connect (
304
- mapStateToProps ,
305
- mapDispatchToProps
306
- ) ( withStyles ( styles ) ( Props ) ) ;
302
+ export default connect ( mapStateToProps , mapDispatchToProps ) ( withStyles ( styles ) ( Props ) ) ;
0 commit comments