From fb3eb6e4d15395b6080a23c24b46517b466ec842 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Tue, 25 Sep 2018 00:14:57 +0200 Subject: [PATCH] Handle trashed and shared items in loadProject action Feature #14221 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/store/breadcrumbs/breadcrumbs-actions.ts | 10 ++- src/store/workbench/workbench-actions.ts | 72 ++++++++++++++++++-- 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/store/breadcrumbs/breadcrumbs-actions.ts b/src/store/breadcrumbs/breadcrumbs-actions.ts index 4ac07b3b..a5ded34e 100644 --- a/src/store/breadcrumbs/breadcrumbs-actions.ts +++ b/src/store/breadcrumbs/breadcrumbs-actions.ts @@ -40,11 +40,17 @@ export const setSidePanelBreadcrumbs = (uuid: string) => }; export const setSharedWithMeBreadcrumbs = (uuid: string) => + setCategoryBreadcrumbs(uuid, SidePanelTreeCategory.SHARED_WITH_ME); + +export const setTrashBreadcrumbs = (uuid: string) => + setCategoryBreadcrumbs(uuid, SidePanelTreeCategory.TRASH); + +export const setCategoryBreadcrumbs = (uuid: string, category: SidePanelTreeCategory) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const ancestors = await services.ancestorsService.ancestors(uuid, ''); dispatch(updateResources(ancestors)); const initialBreadcrumbs: ResourceBreadcrumb[] = [ - { label: SidePanelTreeCategory.SHARED_WITH_ME, uuid: SidePanelTreeCategory.SHARED_WITH_ME } + { label: category, uuid: category } ]; const breadrumbs = ancestors.reduce((breadcrumbs, ancestor) => ancestor.kind === ResourceKind.GROUP @@ -59,7 +65,7 @@ export const setProjectBreadcrumbs = (uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const ancestors = getSidePanelTreeNodeAncestorsIds(uuid)(getState().treePicker); const rootUuid = services.authService.getUuid(); - if (uuid === rootUuid ||ancestors.find(uuid => uuid === rootUuid)) { + if (uuid === rootUuid || ancestors.find(uuid => uuid === rootUuid)) { dispatch(setSidePanelBreadcrumbs(uuid)); } else { dispatch(setSharedWithMeBreadcrumbs(uuid)); diff --git a/src/store/workbench/workbench-actions.ts b/src/store/workbench/workbench-actions.ts index 99f5bc70..d56b6c36 100644 --- a/src/store/workbench/workbench-actions.ts +++ b/src/store/workbench/workbench-actions.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { Dispatch, AnyAction } from 'redux'; +import { Dispatch } from 'redux'; import { RootState } from "../store"; import { loadDetailsPanel } from '~/store/details-panel/details-panel-action'; import { loadCollectionPanel } from '~/store/collection-panel/collection-panel-action'; @@ -15,7 +15,7 @@ import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-acti import { projectPanelColumns } from '~/views/project-panel/project-panel'; import { favoritePanelColumns } from '~/views/favorite-panel/favorite-panel'; import { matchRootRoute } from '~/routes/routes'; -import { setCollectionBreadcrumbs, setProjectBreadcrumbs, setSidePanelBreadcrumbs, setProcessBreadcrumbs, setSharedWithMeBreadcrumbs } from '../breadcrumbs/breadcrumbs-actions'; +import { setCollectionBreadcrumbs, setSidePanelBreadcrumbs, setProcessBreadcrumbs, setSharedWithMeBreadcrumbs, setTrashBreadcrumbs } from '../breadcrumbs/breadcrumbs-actions'; import { navigateToProject } from '../navigation/navigation-action'; import { MoveToFormDialogData } from '~/store/move-to-dialog/move-to-dialog'; import { ServiceRepository } from '~/services/services'; @@ -41,6 +41,10 @@ import { loadSharedWithMePanel } from '../shared-with-me-panel/shared-with-me-pa import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog'; import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions'; import { getProgressIndicator } from '../progress-indicator/progress-indicator-reducer'; +import { ResourceKind } from '~/models/resource'; +import { FilterBuilder } from '~/services/api/filter-builder'; +import { ProjectResource } from '~/models/project'; + export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen'; @@ -107,10 +111,50 @@ export const loadTrash = () => export const loadProject = (uuid: string) => handleFirstTimeLoad( async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(openProjectPanel(uuid)); - await dispatch(activateSidePanelTreeItem(uuid)); - dispatch(setProjectBreadcrumbs(uuid)); - dispatch(loadDetailsPanel(uuid)); + const userUuid = services.authService.getUuid(); + if (userUuid) { + let project: ProjectResource | null = null; + if (userUuid !== uuid) { + /** + * Use of /group/contents API is the only way to get trashed item + * A get method of a service will throw an exception with 404 status for resources that are trashed + */ + const resource = await loadGroupContentsResource(uuid, userUuid, services); + if (resource) { + if (resource.kind === ResourceKind.PROJECT) { + project = resource; + if (project.isTrashed) { + dispatch(setTrashBreadcrumbs(uuid)); + dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH)); + } else { + await dispatch(activateSidePanelTreeItem(uuid)); + dispatch(setSidePanelBreadcrumbs(uuid)); + } + } + } else { + /** + * If item is not accesible using loadGroupContentsResource, + * but it can be obtained using the get method of the service + * then it is shared with the user + */ + project = await services.projectService.get(uuid); + if (project) { + dispatch(setSharedWithMeBreadcrumbs(uuid)); + dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME)); + } + } + if (project) { + dispatch(updateResources([project])); + } + } else { + await dispatch(activateSidePanelTreeItem(userUuid)); + dispatch(setSidePanelBreadcrumbs(userUuid)); + } + if (project) { + dispatch(openProjectPanel(uuid)); + dispatch(loadDetailsPanel(uuid)); + } + } }); export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => @@ -302,3 +346,19 @@ export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) = await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME)); await dispatch(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME)); }); + +const loadGroupContentsResource = async (uuid: string, ownerUuid: string, services: ServiceRepository) => { + + const filters = new FilterBuilder() + .addEqual('uuid', uuid) + .getFilters(); + + const { items } = await services.groupsService.contents(ownerUuid, { + filters, + recursive: true, + includeTrash: true, + }); + + return items.shift(); + +}; -- 2.39.5