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 { ProjectResource } from "../../models/project";
7 import { projectService } from "../../services/services";
8 import { Dispatch } from "redux";
9 import { FilterBuilder } from "../../common/api/filter-builder";
10 import { RootState } from "../store";
11 import { checkPresenceInFavorites } from "../favorites/favorites-actions";
13 export const projectActions = unionize({
14 OPEN_PROJECT_CREATOR: ofType<{ ownerUuid: string }>(),
15 CLOSE_PROJECT_CREATOR: ofType<{}>(),
16 CREATE_PROJECT: ofType<Partial<ProjectResource>>(),
17 CREATE_PROJECT_SUCCESS: ofType<ProjectResource>(),
18 REMOVE_PROJECT: ofType<string>(),
19 PROJECTS_REQUEST: ofType<string>(),
20 PROJECTS_SUCCESS: ofType<{ projects: ProjectResource[], parentItemId?: string }>(),
21 TOGGLE_PROJECT_TREE_ITEM_OPEN: ofType<string>(),
22 TOGGLE_PROJECT_TREE_ITEM_ACTIVE: ofType<string>(),
23 RESET_PROJECT_TREE_ACTIVITY: ofType<string>()
29 export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch, getState: () => RootState) => {
30 dispatch(projectActions.PROJECTS_REQUEST(parentUuid));
31 return projectService.list({
32 filters: FilterBuilder
33 .create<ProjectResource>()
34 .addEqual("ownerUuid", parentUuid)
35 }).then(({ items: projects }) => {
36 dispatch(projectActions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
37 dispatch<any>(checkPresenceInFavorites(projects.map(project => project.uuid)));
42 export const createProject = (project: Partial<ProjectResource>) =>
43 (dispatch: Dispatch, getState: () => RootState) => {
44 const { ownerUuid } = getState().projects.creator;
45 const projectData = { ownerUuid, ...project };
46 dispatch(projectActions.CREATE_PROJECT(projectData));
49 .then(project => dispatch(projectActions.CREATE_PROJECT_SUCCESS(project)));
52 export type ProjectAction = UnionOf<typeof projectActions>;