@@ -20,10 +20,10 @@ export default class EditRowDialog extends React.Component {
20
20
super ( props ) ;
21
21
22
22
const { selectedObject } = this . props ;
23
- const { currentObject, openObjectPickers, expandedTextAreas } = this . initializeState (
23
+ const { currentObject, openObjectPickers } = this . initializeState (
24
24
selectedObject
25
25
) ;
26
- this . state = { currentObject, openObjectPickers, expandedTextAreas } ;
26
+ this . state = { currentObject, openObjectPickers } ;
27
27
28
28
this . updateCurrentObject = this . updateCurrentObject . bind ( this ) ;
29
29
this . handleChange = this . handleChange . bind ( this ) ;
@@ -37,46 +37,42 @@ export default class EditRowDialog extends React.Component {
37
37
const newSelectedObject = props . selectedObject ;
38
38
const previousSelectedObject = this . props . selectedObject ;
39
39
if ( newSelectedObject . id !== previousSelectedObject . id ) {
40
- const { currentObject, openObjectPickers, expandedTextAreas } = this . initializeState (
40
+ const { currentObject, openObjectPickers } = this . initializeState (
41
41
newSelectedObject
42
42
) ;
43
- this . setState ( { currentObject, openObjectPickers, expandedTextAreas } ) ;
44
- } else if ( newSelectedObject . updatedAt !== previousSelectedObject . updatedAt ) {
45
- this . updateCurrentObjectFromProps ( newSelectedObject ) ;
43
+ this . setState ( { currentObject, openObjectPickers } ) ;
46
44
}
47
45
}
48
46
49
47
initializeState ( newObject ) {
50
48
const { columns } = this . props ;
51
49
const currentObject = { ...newObject } ;
52
50
const openObjectPickers = { } ;
53
- const expandedTextAreas = { } ;
54
51
columns . forEach ( column => {
55
52
const { name, type } = column ;
56
53
if ( [ 'Array' , 'Object' ] . indexOf ( type ) >= 0 ) {
57
- const stringifyValue = JSON . stringify ( currentObject [ name ] , null , 4 ) ;
58
- currentObject [ name ] = stringifyValue ;
59
- const rows = stringifyValue ? stringifyValue . split ( '\n' ) . length : 1 ;
60
- expandedTextAreas [ name ] = { rows : rows , expanded : false } ;
54
+ currentObject [ name ] = JSON . stringify ( currentObject [ name ] , null , 2 ) ;
61
55
}
62
56
if ( type === 'Polygon' ) {
63
- const stringifyValue = JSON . stringify (
57
+ currentObject [ name ] = JSON . stringify (
64
58
( currentObject [ name ] && currentObject [ name ] . coordinates ) || [
65
59
[ 'lat' , 'lon' ]
66
60
] ,
67
61
null ,
68
- 4
62
+ 2
69
63
) ;
70
- currentObject [ name ] = stringifyValue ;
71
- const rows = stringifyValue ? stringifyValue . split ( '\n' ) . length : 1 ;
72
- expandedTextAreas [ name ] = { rows : rows , expanded : false } ;
73
64
}
74
- if ( [ 'Pointer' , 'Relation' ] . indexOf ( type ) >= 0 ) {
65
+ if ( type === 'Pointer' ) {
66
+ currentObject [ name ] =
67
+ ( currentObject [ name ] && currentObject [ name ] . id ) || '' ;
68
+ openObjectPickers [ name ] = false ;
69
+ }
70
+ if ( type === 'Relation' ) {
75
71
openObjectPickers [ name ] = false ;
76
72
}
77
73
} ) ;
78
74
79
- return { currentObject, openObjectPickers, expandedTextAreas } ;
75
+ return { currentObject, openObjectPickers } ;
80
76
}
81
77
82
78
updateCurrentObject ( newValue , name ) {
@@ -85,36 +81,6 @@ export default class EditRowDialog extends React.Component {
85
81
this . setState ( { currentObject } ) ;
86
82
}
87
83
88
- updateCurrentObjectFromProps ( newObject ) {
89
- const { columns } = this . props ;
90
- const { currentObject, expandedTextAreas } = this . state ;
91
- columns . forEach ( column => {
92
- const { name, type } = column ;
93
- if ( [ 'String' , 'Number' ] . indexOf ( type ) >= 0 ) {
94
- currentObject [ name ] = newObject [ name ] ;
95
- }
96
- if ( [ 'Array' , 'Object' ] . indexOf ( type ) >= 0 ) {
97
- const stringifyValue = JSON . stringify ( newObject [ name ] , null , 4 ) ;
98
- currentObject [ name ] = stringifyValue ;
99
- const rows = stringifyValue ? stringifyValue . split ( '\n' ) . length : 1 ;
100
- expandedTextAreas [ name ] . rows = rows ;
101
- }
102
- if ( type === 'Polygon' ) {
103
- const stringifyValue = JSON . stringify (
104
- ( newObject [ name ] && newObject [ name ] . coordinates ) || [
105
- [ 'lat' , 'lon' ]
106
- ] ,
107
- null ,
108
- 4
109
- ) ;
110
- currentObject [ name ] = stringifyValue ;
111
- const rows = stringifyValue ? stringifyValue . split ( '\n' ) . length : 1 ;
112
- expandedTextAreas [ name ] . rows = rows ;
113
- }
114
- } ) ;
115
- this . setState ( { currentObject, expandedTextAreas } ) ;
116
- }
117
-
118
84
handleChange ( newValue , name , type , targetClass , toDelete ) {
119
85
if ( name == 'password' ) {
120
86
if ( newValue === '' ) {
@@ -148,22 +114,8 @@ export default class EditRowDialog extends React.Component {
148
114
this . toggleObjectPicker ( name , false ) ;
149
115
} else {
150
116
if ( [ 'Array' , 'Object' , 'Polygon' ] . indexOf ( type ) >= 0 ) {
151
- const { selectedObject } = this . props ;
152
- const { currentObject, expandedTextAreas } = this . state ;
153
- const oldStringifyValue = JSON . stringify (
154
- type === 'Polygon'
155
- ? selectedObject [ name ] . coordinates
156
- : selectedObject [ name ] ,
157
- null ,
158
- 4
159
- ) ;
160
- const stringifyValue = JSON . stringify ( newValue , null , 4 ) ;
161
- if ( oldStringifyValue === stringifyValue ) {
162
- return ;
163
- }
164
- currentObject [ name ] = stringifyValue ;
165
- const rows = stringifyValue ? stringifyValue . split ( '\n' ) . length : 1 ;
166
- expandedTextAreas [ name ] . rows = rows ;
117
+ const { currentObject } = this . state ;
118
+ currentObject [ name ] = JSON . stringify ( newValue , null , 2 ) ;
167
119
if ( type === 'Polygon' ) {
168
120
newValue = {
169
121
__type : type ,
@@ -211,15 +163,9 @@ export default class EditRowDialog extends React.Component {
211
163
this . setState ( { openObjectPickers } ) ;
212
164
}
213
165
214
- toggleExpandTextArea ( name ) {
215
- const { expandedTextAreas } = this . state ;
216
- expandedTextAreas [ name ] . expanded = ! expandedTextAreas [ name ] . expanded ;
217
- this . setState ( { expandedTextAreas } ) ;
218
- }
219
-
220
166
render ( ) {
221
167
const { selectedObject, className, columns, onClose, schema, useMasterKey } = this . props ;
222
- const { currentObject, openObjectPickers, expandedTextAreas } = this . state ;
168
+ const { currentObject, openObjectPickers } = this . state ;
223
169
224
170
const fields = columns . map ( column => {
225
171
const { name, type, targetClass } = column ;
@@ -281,11 +227,6 @@ export default class EditRowDialog extends React.Component {
281
227
inputComponent = (
282
228
< TextInput
283
229
multiline = { true }
284
- rows = {
285
- expandedTextAreas [ name ] &&
286
- expandedTextAreas [ name ] . expanded &&
287
- expandedTextAreas [ name ] . rows
288
- }
289
230
disabled = { isDisabled }
290
231
value = { currentObject [ name ] }
291
232
onChange = { newValue => this . updateCurrentObject ( newValue , name ) }
@@ -416,29 +357,13 @@ export default class EditRowDialog extends React.Component {
416
357
inputComponent = < div /> ;
417
358
}
418
359
419
- const description = (
420
- < span >
421
- { targetClass ? `${ type } <${ targetClass } >` : type }
422
- < div style = { { marginTop : '2px' } } >
423
- { expandedTextAreas [ name ] && expandedTextAreas [ name ] . rows > 3 && (
424
- < a
425
- style = { { color : '#169cee' } }
426
- onClick = { ( ) => this . toggleExpandTextArea ( name ) }
427
- >
428
- { expandedTextAreas [ name ] . expanded ? 'collapse' : 'expand' }
429
- </ a >
430
- ) }
431
- </ div >
432
- </ span >
433
- ) ;
434
-
435
360
return (
436
361
< Field
437
362
key = { name }
438
363
label = {
439
364
< Label
440
365
text = { name }
441
- description = { description }
366
+ description = { targetClass ? ` ${ type } < ${ targetClass } >` : type }
442
367
/>
443
368
}
444
369
labelWidth = { 33 }
0 commit comments