modify common resource service, clean code
authorJanicki Artur <artur.janicki@contractors.roche.com>
Thu, 4 Oct 2018 12:35:18 +0000 (14:35 +0200)
committerJanicki Artur <artur.janicki@contractors.roche.com>
Thu, 4 Oct 2018 12:35:18 +0000 (14:35 +0200)
Feature #14278

Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki@contractors.roche.com>

src/services/collection-service/collection-service.ts
src/services/common-service/common-resource-service.ts
src/services/groups-service/groups-service.ts
src/views/collection-panel/collection-panel.tsx

index eb48e9dcb02a5e504ee061e9aa66c3854ed636a8..407290147082a7378046ba52aab94186cd28a8a5 100644 (file)
@@ -70,8 +70,6 @@ export class CollectionService extends TrashableResourceService<CollectionResour
 
     }
 
-    // ToDo: add get method
-
     update(uuid: string, data: Partial<CollectionResource>) {
         if (uuid && data) {
             const { properties } = data;
@@ -84,7 +82,8 @@ export class CollectionService extends TrashableResourceService<CollectionResour
                     .defaultResponse(
                         this.serverApi
                             .put<CollectionResource>(this.resourceType + uuid, mappedData),
-                        this.actions
+                        this.actions,
+                        false
                     );
             }
         }
index 90677b05b602e280851c98a0d72ae33c632dea2f..70c1df0e2bc5e665a3c62c05b39b7a50a6705c62 100644 (file)
@@ -62,7 +62,7 @@ export class CommonResourceService<T extends Resource> {
             }
         }
 
-    static defaultResponse<R>(promise: AxiosPromise<R>, actions: ApiActions): Promise<R> {
+    static defaultResponse<R>(promise: AxiosPromise<R>, actions: ApiActions, mapKeys = true): Promise<R> {
         const reqId = uuid();
         actions.progressFn(reqId, true);
         return promise
@@ -70,7 +70,9 @@ export class CommonResourceService<T extends Resource> {
                 actions.progressFn(reqId, false);
                 return data;
             })
-            .then(CommonResourceService.mapResponseKeys)
+            .then((response: { data: any }) => {
+                return mapKeys ? CommonResourceService.mapResponseKeys(response) : response.data;
+            })
             .catch(({ response }) => {
                 actions.progressFn(reqId, false);
                 const errors = CommonResourceService.mapResponseKeys(response) as Errors;
@@ -79,18 +81,6 @@ export class CommonResourceService<T extends Resource> {
             });
     }
 
-    static customResponse<R>(promise: AxiosPromise<R>, actions: ApiActions): Promise<R> {
-        const reqId = uuid();
-        actions.progressFn(reqId, true);
-        return promise
-            .then(data => {
-                actions.progressFn(reqId, false);
-                return data;
-            })
-            .then((response: { data: any }) => response.data);
-    }
-
-
     protected serverApi: AxiosInstance;
     protected resourceType: string;
     protected actions: ApiActions;
index ec80851d318c14245caa2c84770beed0b2598a00..bf92836097a71caea6cca6295bcbe589ef769d8e 100644 (file)
@@ -45,12 +45,13 @@ export class GroupsService<T extends GroupResource = GroupResource> extends Tras
             order: order ? order : undefined
         };
 
-        const response = await CommonResourceService.customResponse(
+        const response = await CommonResourceService.defaultResponse(
             this.serverApi
                 .get(this.resourceType + `${uuid}/contents`, {
                     params: CommonResourceService.mapKeys(_.camelCase)(params)
                 }),
-            this.actions
+            this.actions, 
+            false
         );
         const { items, ...res } = response;
         const mappedItems = items.map((item: any) => {
index 379a2eb8402f2d9aaf791cc31fa66af47ae38a79..96c2fc96f06d9a80f4ee454fd24e932c71ea40f8 100644 (file)
@@ -119,7 +119,6 @@ export const CollectionPanel = withStyles(styles)(
                                     <Grid item xs={12}>
                                         {
                                             Object.keys(item.properties).map(k => {
-                                                console.log('k: ', k);
                                                 return <Chip key={k} className={classes.tag}
                                                     onDelete={this.handleDelete(k)}
                                                     label={`${k}: ${item.properties[k]}`} />;