X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/4bbaf2a0cede89ea50d63d210c6631adc1970620..5627bf1a83323d2b0364cb069564998eb8c6ca7a:/src/store/project/project-action.ts diff --git a/src/store/project/project-action.ts b/src/store/project/project-action.ts index 2856de66..4f03ae1c 100644 --- a/src/store/project/project-action.ts +++ b/src/store/project/project-action.ts @@ -2,19 +2,37 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { Project } from "../../models/project"; -import { default as unionize, ofType, UnionOf } from "unionize"; +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'; -const actions = unionize({ - CREATE_PROJECT: ofType(), +export const projectActions = unionize({ REMOVE_PROJECT: ofType(), - PROJECTS_REQUEST: ofType(), - PROJECTS_SUCCESS: ofType<{ projects: Project[], parentItemId?: string }>(), - TOGGLE_PROJECT_TREE_ITEM: ofType() -}, { - tag: 'type', - value: 'payload' + 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 type ProjectAction = UnionOf; -export default actions; +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;