// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import { unionize, ofType, UnionOf } from '~/common/unionize'; import { ProjectResource } from "~/models/project"; import { Dispatch } from "redux"; import { FilterBuilder } from "~/common/api/filter-builder"; import { RootState } from "../store"; import { updateFavorites } from "../favorites/favorites-actions"; import { ServiceRepository } from "~/services/services"; import { resourcesActions } from '~/store/resources/resources-actions'; export const projectActions = unionize({ REMOVE_PROJECT: ofType(), PROJECTS_REQUEST: ofType(), PROJECTS_SUCCESS: ofType<{ projects: ProjectResource[], parentItemId?: string }>(), TOGGLE_PROJECT_TREE_ITEM_OPEN: ofType(), TOGGLE_PROJECT_TREE_ITEM_ACTIVE: ofType(), RESET_PROJECT_TREE_ACTIVITY: ofType() }); export const getProjectList = (parentUuid: string = '') => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { dispatch(projectActions.PROJECTS_REQUEST(parentUuid)); return services.projectService.list({ filters: new FilterBuilder() .addEqual("ownerUuid", parentUuid) .getFilters() }).then(({ items: projects }) => { dispatch(projectActions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid })); dispatch(updateFavorites(projects.map(project => project.uuid))); dispatch(resourcesActions.SET_RESOURCES(projects)); return projects; }); }; export type ProjectAction = UnionOf;