1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
4 import { default as unionize, ofType, UnionOf } from "unionize";
6 import { Project } from "../../models/project";
7 import { groupsService } from "../../services/services";
8 import { Dispatch } from "redux";
9 import { getResourceKind } from "../../models/resource";
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>()
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 => ({
29 kind: getResourceKind(item.kind)
31 dispatch(actions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
36 export type ProjectAction = UnionOf<typeof actions>;
37 export default actions;