[fix] Display correct entity when navigating from one entity to another
authorFrank Bessou <frank.bessou@logilab.fr>
Thu, 27 Apr 2017 10:56:56 +0200
changeset 150 85fec823255c
parent 149 ac11d4378e29
child 151 76bdef826f63
[fix] Display correct entity when navigating from one entity to another When navigating from '/some_etype/123' to '/some_etype/456', the Entity component was not loading the target resource.
src/components/Entity.js
--- a/src/components/Entity.js	Tue May 02 10:31:59 2017 +0200
+++ b/src/components/Entity.js	Thu Apr 27 10:56:56 2017 +0200
@@ -183,7 +183,18 @@
     }
 
     componentDidMount() {
-        Api.getEntity(this.getEType(), this.getEID())
+        this.initEntity(this.getEType(), this.getEID());
+    }
+
+    componentWillReceiveProps(nextProps) {
+        this.setState(this.getInitialState(nextProps));
+        const etype = nextProps.match.params.etype;
+        const eid = nextProps.match.params.eid;
+        this.initEntity(etype, eid);
+    }
+
+    initEntity(etype, eid) {
+        Api.getEntity(etype, eid)
             .then(
                 (entity) => {
                     this.setState({entity: entity});