Let Api.getSchema take a resource URL as first argument
authorFrank Bessou <frank.bessou@logilab.fr>
Tue, 04 Apr 2017 14:10:49 +0200
changeset 71 407e49c80ec2
parent 70 2d72f308d3c3
child 72 dec42889e222
Let Api.getSchema take a resource URL as first argument
src/Api.js
src/components/Entity.js
--- a/src/Api.js	Tue Apr 04 14:09:22 2017 +0200
+++ b/src/Api.js	Tue Apr 04 14:10:49 2017 +0200
@@ -61,12 +61,8 @@
             });
     }
 
-    getSchema(etype, eid=null, role=null) {
-        var url = `/${etype}`;
-        if (eid !== null) {
-            url += `/${eid}`;
-        }
-        url += '/schema';
+    getSchema(resourceUrl, role=null) {
+        let url = resourceUrl + '/schema';
         if (role !== null) {
             url += `?role=${role}`;
         }
@@ -106,7 +102,7 @@
         const route = `/${etype}/${eid}`;
         const url = route;
 
-        const schemaPromise = this.getSchema(etype, eid);
+        const schemaPromise = this.getSchema(url);
         const fetchPromise = this.jsonFetchResponse(url);
         const dataPromise = fetchPromise.then( response => response.json() );
         const allowedActionsPromise = fetchPromise.then( response => this.extractAllowedActions(response) );
--- a/src/components/Entity.js	Tue Apr 04 14:09:22 2017 +0200
+++ b/src/components/Entity.js	Tue Apr 04 14:10:49 2017 +0200
@@ -201,7 +201,7 @@
     }
 
     getEditionSchema() {
-        return Api.getSchema(this.etype, this.eid, 'edition');
+        return Api.getSchema(this.state.entity.url, 'edition');
     }
 
     render() {
@@ -369,7 +369,7 @@
 
     componentDidMount() {
         const {etype} = this.props.params;
-        Api.getSchema(etype, null, 'creation')
+        Api.getSchema(`/${etype}`, 'creation')
             .then(schema => this.setState({schema: schema}));
     }