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 { Dispatch } from "redux";
8 import { FilterBuilder } from "~/common/api/filter-builder";
9 import { RootState } from "../store";
10 import { checkPresenceInFavorites } from "../favorites/favorites-actions";
11 import { ServiceRepository } from "~/services/services";
13 export const projectActions = unionize({
14 REMOVE_PROJECT: ofType<string>(),
15 PROJECTS_REQUEST: ofType<string>(),
16 PROJECTS_SUCCESS: ofType<{ projects: ProjectResource[], 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 = '') =>
26 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
27 dispatch(projectActions.PROJECTS_REQUEST(parentUuid));
28 return services.projectService.list({
29 filters: new FilterBuilder()
30 .addEqual("ownerUuid", parentUuid)
32 }).then(({ items: projects }) => {
33 dispatch(projectActions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
34 dispatch<any>(checkPresenceInFavorites(projects.map(project => project.uuid)));
39 export type ProjectAction = UnionOf<typeof projectActions>;