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, ProjectResource } from "../../models/project";
7 import { projectService } from "../../services/services";
8 import { Dispatch } from "redux";
9 import { getResourceKind } from "../../models/resource";
10 import FilterBuilder from "../../common/api/filter-builder";
12 const actions = unionize({
13 CREATE_PROJECT: ofType<Project>(),
14 REMOVE_PROJECT: ofType<string>(),
15 PROJECTS_REQUEST: ofType<string>(),
16 PROJECTS_SUCCESS: ofType<{ projects: Project[], parentItemId?: string }>(),
17 TOGGLE_PROJECT_TREE_ITEM_OPEN: ofType<string>(),
18 TOGGLE_PROJECT_TREE_ITEM_ACTIVE: ofType<string>(),
19 RESET_PROJECT_TREE_ACTIVITY: ofType<string>()
25 export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch) => {
26 dispatch(actions.PROJECTS_REQUEST(parentUuid));
27 return projectService.list({
28 filters: FilterBuilder
29 .create<ProjectResource>()
30 .addEqual("ownerUuid", parentUuid)
31 }).then(listResults => {
32 const projects = listResults.items.map(item => ({
34 kind: getResourceKind(item.kind)
36 dispatch(actions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
41 export type ProjectAction = UnionOf<typeof actions>;
42 export default actions;