load item to panelDetails and display data
[arvados-workbench2.git] / src / store / project / project-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4 import { default as unionize, ofType, UnionOf } from "unionize";
5
6 import { Project } from "../../models/project";
7 import { groupsService } from "../../services/services";
8 import { Dispatch } from "redux";
9 import { getResourceKind } from "../../models/resource";
10
11 const actions = unionize({
12     CREATE_PROJECT: ofType<Project>(),
13     REMOVE_PROJECT: ofType<string>(),
14     PROJECTS_REQUEST: ofType<string>(),
15     PROJECTS_SUCCESS: ofType<{ projects: Project[], parentItemId?: string }>(),
16     TOGGLE_PROJECT_TREE_ITEM_OPEN: ofType<string>(),
17     TOGGLE_PROJECT_TREE_ITEM_ACTIVE: ofType<string>(),
18     RESET_PROJECT_TREE_ACTIVITY: ofType<string>()
19 }, {
20         tag: 'type',
21         value: 'payload'
22     });
23  
24 export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch) => {
25         dispatch(actions.PROJECTS_REQUEST(parentUuid));
26         return groupsService.list().then(listResults => {
27             const projects = listResults.items.map(item => ({
28                 ...item,
29                 kind: getResourceKind(item.kind)
30             }));
31             dispatch(actions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
32             return projects;
33         });
34 };
35
36 export type ProjectAction = UnionOf<typeof actions>;
37 export default actions;