@@ -20,10 +20,10 @@ export default class EditRowDialog extends React.Component {
2020 super ( props ) ;
2121
2222 const { selectedObject } = this . props ;
23- const { currentObject, openObjectPickers, expandedTextAreas } = this . initializeState (
23+ const { currentObject, openObjectPickers } = this . initializeState (
2424 selectedObject
2525 ) ;
26- this . state = { currentObject, openObjectPickers, expandedTextAreas } ;
26+ this . state = { currentObject, openObjectPickers } ;
2727
2828 this . updateCurrentObject = this . updateCurrentObject . bind ( this ) ;
2929 this . handleChange = this . handleChange . bind ( this ) ;
@@ -37,46 +37,42 @@ export default class EditRowDialog extends React.Component {
3737 const newSelectedObject = props . selectedObject ;
3838 const previousSelectedObject = this . props . selectedObject ;
3939 if ( newSelectedObject . id !== previousSelectedObject . id ) {
40- const { currentObject, openObjectPickers, expandedTextAreas } = this . initializeState (
40+ const { currentObject, openObjectPickers } = this . initializeState (
4141 newSelectedObject
4242 ) ;
43- this . setState ( { currentObject, openObjectPickers, expandedTextAreas } ) ;
44- } else if ( newSelectedObject . updatedAt !== previousSelectedObject . updatedAt ) {
45- this . updateCurrentObjectFromProps ( newSelectedObject ) ;
43+ this . setState ( { currentObject, openObjectPickers } ) ;
4644 }
4745 }
4846
4947 initializeState ( newObject ) {
5048 const { columns } = this . props ;
5149 const currentObject = { ...newObject } ;
5250 const openObjectPickers = { } ;
53- const expandedTextAreas = { } ;
5451 columns . forEach ( column => {
5552 const { name, type } = column ;
5653 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 ) ;
6155 }
6256 if ( type === 'Polygon' ) {
63- const stringifyValue = JSON . stringify (
57+ currentObject [ name ] = JSON . stringify (
6458 ( currentObject [ name ] && currentObject [ name ] . coordinates ) || [
6559 [ 'lat' , 'lon' ]
6660 ] ,
6761 null ,
68- 4
62+ 2
6963 ) ;
70- currentObject [ name ] = stringifyValue ;
71- const rows = stringifyValue ? stringifyValue . split ( '\n' ) . length : 1 ;
72- expandedTextAreas [ name ] = { rows : rows , expanded : false } ;
7364 }
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' ) {
7571 openObjectPickers [ name ] = false ;
7672 }
7773 } ) ;
7874
79- return { currentObject, openObjectPickers, expandedTextAreas } ;
75+ return { currentObject, openObjectPickers } ;
8076 }
8177
8278 updateCurrentObject ( newValue , name ) {
@@ -85,36 +81,6 @@ export default class EditRowDialog extends React.Component {
8581 this . setState ( { currentObject } ) ;
8682 }
8783
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-
11884 handleChange ( newValue , name , type , targetClass , toDelete ) {
11985 if ( name == 'password' ) {
12086 if ( newValue === '' ) {
@@ -148,22 +114,8 @@ export default class EditRowDialog extends React.Component {
148114 this . toggleObjectPicker ( name , false ) ;
149115 } else {
150116 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 ) ;
167119 if ( type === 'Polygon' ) {
168120 newValue = {
169121 __type : type ,
@@ -211,15 +163,9 @@ export default class EditRowDialog extends React.Component {
211163 this . setState ( { openObjectPickers } ) ;
212164 }
213165
214- toggleExpandTextArea ( name ) {
215- const { expandedTextAreas } = this . state ;
216- expandedTextAreas [ name ] . expanded = ! expandedTextAreas [ name ] . expanded ;
217- this . setState ( { expandedTextAreas } ) ;
218- }
219-
220166 render ( ) {
221167 const { selectedObject, className, columns, onClose, schema, useMasterKey } = this . props ;
222- const { currentObject, openObjectPickers, expandedTextAreas } = this . state ;
168+ const { currentObject, openObjectPickers } = this . state ;
223169
224170 const fields = columns . map ( column => {
225171 const { name, type, targetClass } = column ;
@@ -281,11 +227,6 @@ export default class EditRowDialog extends React.Component {
281227 inputComponent = (
282228 < TextInput
283229 multiline = { true }
284- rows = {
285- expandedTextAreas [ name ] &&
286- expandedTextAreas [ name ] . expanded &&
287- expandedTextAreas [ name ] . rows
288- }
289230 disabled = { isDisabled }
290231 value = { currentObject [ name ] }
291232 onChange = { newValue => this . updateCurrentObject ( newValue , name ) }
@@ -416,29 +357,13 @@ export default class EditRowDialog extends React.Component {
416357 inputComponent = < div /> ;
417358 }
418359
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-
435360 return (
436361 < Field
437362 key = { name }
438363 label = {
439364 < Label
440365 text = { name }
441- description = { description }
366+ description = { targetClass ? ` ${ type } < ${ targetClass } >` : type }
442367 />
443368 }
444369 labelWidth = { 33 }
0 commit comments