Merge branch 'master' into 13765-information-inside-details-panel
[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, { Resource } from "../../common/api/common-resource-service";
7 import { ResourceKind } from "../../models/kinds";
8 import { Dispatch } from "redux";
9 import { groupsService } from "../../services/services";
10 import { serverApi } from "../../common/api/server-api";
11
12 const actions = unionize({
13     TOGGLE_DETAILS_PANEL: ofType<{}>(),
14     LOAD_DETAILS: ofType<{ uuid: string, kind: ResourceKind }>(),
15     LOAD_DETAILS_SUCCESS: ofType<{ item: Resource }>(),
16 }, { tag: 'type', value: 'payload' });
17
18 export default actions;
19
20 export type DetailsPanelAction = UnionOf<typeof actions>;
21
22 export const loadDetails = (uuid: string, kind: ResourceKind) =>
23     (dispatch: Dispatch) => {
24         dispatch(actions.LOAD_DETAILS({ uuid, kind }));
25         getService(kind)
26             .get(uuid)
27             .then(project => {
28                 dispatch(actions.LOAD_DETAILS_SUCCESS({ item: project }));
29             });
30     };
31
32 const getService = (kind: ResourceKind) => {
33     switch (kind) {
34         case ResourceKind.Project:
35             return new CommonResourceService(serverApi, "groups");
36         case ResourceKind.Collection:
37             return new CommonResourceService(serverApi, "collections");
38         default:
39             return new CommonResourceService(serverApi, "");
40     }
41 };
42
43
44