refs # Merge branch 'origin/remove-default-exports'
[arvados-workbench2.git] / src / store / details-panel / details-panel-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { unionize, ofType, UnionOf } from "unionize";
6 import { CommonResourceService } from "../../common/api/common-resource-service";
7 import { Dispatch } from "redux";
8 import { serverApi } from "../../common/api/server-api";
9 import { Resource, ResourceKind } from "../../models/resource";
10
11 export const detailsPanelActions = unionize({
12     TOGGLE_DETAILS_PANEL: ofType<{}>(),
13     LOAD_DETAILS: ofType<{ uuid: string, kind: ResourceKind }>(),
14     LOAD_DETAILS_SUCCESS: ofType<{ item: Resource }>(),
15 }, { tag: 'type', value: 'payload' });
16
17 export type DetailsPanelAction = UnionOf<typeof detailsPanelActions>;
18
19 export const loadDetails = (uuid: string, kind: ResourceKind) =>
20     (dispatch: Dispatch) => {
21         dispatch(detailsPanelActions.LOAD_DETAILS({ uuid, kind }));
22         getService(kind)
23             .get(uuid)
24             .then(project => {
25                 dispatch(detailsPanelActions.LOAD_DETAILS_SUCCESS({ item: project }));
26             });
27     };
28
29 const getService = (kind: ResourceKind) => {
30     switch (kind) {
31         case ResourceKind.Project:
32             return new CommonResourceService(serverApi, "groups");
33         case ResourceKind.Collection:
34             return new CommonResourceService(serverApi, "collections");
35         default:
36             return new CommonResourceService(serverApi, "");
37     }
38 };
39
40
41