Use getResource to retrieve Entities model
authorFrank Bessou <frank.bessou@logilab.fr>
Wed, 05 Apr 2017 15:10:15 +0200
changeset 73 a366599c0e9a
parent 72 dec42889e222
child 74 0cd81011cef3
Use getResource to retrieve Entities model
src/Api.js
src/components/Entities.js
--- a/src/Api.js	Tue Apr 04 15:24:01 2017 +0200
+++ b/src/Api.js	Wed Apr 05 15:10:15 2017 +0200
@@ -96,12 +96,14 @@
     }
 
 
-    getEntities(etype, attrs = []) {
-        let url = `/${etype}/`;
-        if (attrs.length) {
-            url = `${url}?attrs=${attrs.join(',')}`;
-        }
-        return this.jsonFetchCollection(url);
+    getEntities(etype) {
+        const route = `/${etype}/`;
+        const url = route;
+        return this.getResource(url).then( resource => {
+            resource.etype = etype;
+            resource.route = route;
+            return resource;
+        });
     }
 
     getRelated(etype, eid, rtype, params = {}) {
--- a/src/components/Entities.js	Tue Apr 04 15:24:01 2017 +0200
+++ b/src/components/Entities.js	Wed Apr 05 15:10:15 2017 +0200
@@ -13,7 +13,7 @@
     componentDidMount() {
         const {etype} = this.props.params;
         Api.getEntities(etype)
-            .then(data => this.setState({entities: data}));
+            .then(entities => this.setState({entities: entities.data.value()}));
     }
 
     render() {