merge changes
[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 { 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
11 const actions = 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 default actions;
18
19 export type DetailsPanelAction = UnionOf<typeof actions>;
20
21 export const loadDetails = (uuid: string, kind: ResourceKind) =>
22     (dispatch: Dispatch) => {
23         dispatch(actions.LOAD_DETAILS({ uuid, kind }));
24         if (kind === ResourceKind.Project) {
25             groupsService
26                 .get(uuid)
27                 .then(project => {
28                     dispatch(actions.LOAD_DETAILS_SUCCESS({ item: project }));
29                 });
30         }
31
32     };
33
34
35