Reorganiza service to make use of dynamic config
[arvados-workbench2.git] / src / store / details-panel / details-panel-action.ts
index e2d2479b35d2d55f3b62afa227bc7c17a6362d37..974346e6e0c0cc79aacf7af242f0cfc925257c48 100644 (file)
@@ -3,33 +3,39 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { unionize, ofType, UnionOf } from "unionize";
-import { Resource } from "../../common/api/common-resource-service";
-import { ResourceKind } from "../../models/kinds";
+import { CommonResourceService } from "../../common/api/common-resource-service";
 import { Dispatch } from "redux";
-import { groupsService } from "../../services/services";
+import { apiClient } from "../../common/api/server-api";
+import { Resource, ResourceKind } from "../../models/resource";
 
-const actions = unionize({
+export const detailsPanelActions = unionize({
     TOGGLE_DETAILS_PANEL: ofType<{}>(),
     LOAD_DETAILS: ofType<{ uuid: string, kind: ResourceKind }>(),
     LOAD_DETAILS_SUCCESS: ofType<{ item: Resource }>(),
 }, { tag: 'type', value: 'payload' });
 
-export default actions;
-
-export type DetailsPanelAction = UnionOf<typeof actions>;
+export type DetailsPanelAction = UnionOf<typeof detailsPanelActions>;
 
 export const loadDetails = (uuid: string, kind: ResourceKind) =>
     (dispatch: Dispatch) => {
-        dispatch(actions.LOAD_DETAILS({ uuid, kind }));
-        if (kind === ResourceKind.Project) {
-            groupsService
-                .get(uuid)
-                .then(project => {
-                    dispatch(actions.LOAD_DETAILS_SUCCESS({ item: project }));
-                });
-        }
-
+        dispatch(detailsPanelActions.LOAD_DETAILS({ uuid, kind }));
+        getService(kind)
+            .get(uuid)
+            .then(project => {
+                dispatch(detailsPanelActions.LOAD_DETAILS_SUCCESS({ item: project }));
+            });
     };
 
+const getService = (kind: ResourceKind) => {
+    switch (kind) {
+        case ResourceKind.Project:
+            return new CommonResourceService(apiClient, "groups");
+        case ResourceKind.Collection:
+            return new CommonResourceService(apiClient, "collections");
+        default:
+            return new CommonResourceService(apiClient, "");
+    }
+};
+