Fix broken state after entity edition
authorFrank Bessou <frank.bessou@logilab.fr>
Mon, 10 Apr 2017 15:40:44 +0200
changeset 101 80b3bcb94070
parent 100 13ff8842ff33
child 102 02ed873453e8
Fix broken state after entity edition The setState function merge the current state and the state given as argument but it does not merge nested properties. Using lodash's merge permits to ensure we don't lose data (like etype, eid, etc. ).
src/components/Entity.js
--- a/src/components/Entity.js	Fri Apr 07 16:55:03 2017 +0200
+++ b/src/components/Entity.js	Mon Apr 10 15:40:44 2017 +0200
@@ -3,6 +3,7 @@
 import {Link} from 'react-router';
 
 import {isEmpty} from 'lodash/lang';
+import {merge} from 'lodash/object';
 
 import Api from '../Api';
 import {wrapEntityData, PropTypeJsonaryWrapper} from '../jsonaryutils'
@@ -197,7 +198,7 @@
 
     updateEntity(entity) {
         const wrappedData = wrapEntityData(entity, this.state.entity.data.schemas()[0].data.value());
-        this.setState({entity: {data: wrappedData}});
+        this.setState(merge({}, this.state, {entity: {data: wrappedData}}));
     }
 
     getEditionSchema() {