From 5fdf4adc6981e60169966e549e37c5611d7d420b Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Mon, 17 Sep 2018 10:32:52 +0200 Subject: [PATCH] Implement breadcrumbs for shared with me panel Feature #13751 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- .../ancestors-service/ancestors-service.ts | 22 +++++++++++-------- src/services/groups-service/groups-service.ts | 3 ++- src/store/breadcrumbs/breadcrumbs-actions.ts | 20 +++++++++++++++++ src/store/navigation/navigation-action.ts | 2 ++ .../side-panel-tree-actions.ts | 4 ++-- src/store/workbench/workbench-actions.ts | 18 ++++++++++----- 6 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/services/ancestors-service/ancestors-service.ts b/src/services/ancestors-service/ancestors-service.ts index f90b4a30..44e4eef5 100644 --- a/src/services/ancestors-service/ancestors-service.ts +++ b/src/services/ancestors-service/ancestors-service.ts @@ -14,17 +14,21 @@ export class AncestorService { private userService: UserService ) { } - async ancestors(uuid: string, rootUuid: string): Promise> { + async ancestors(uuid: string, rootUuid: string): Promise> { const service = this.getService(extractUuidObjectType(uuid)); if (service) { - const resource = await service.get(uuid); - if (uuid === rootUuid) { - return [resource]; - } else { - return [ - ...await this.ancestors(resource.ownerUuid, rootUuid), - resource - ]; + try { + const resource = await service.get(uuid); + if (uuid === rootUuid) { + return [resource]; + } else { + return [ + ...await this.ancestors(resource.ownerUuid, rootUuid), + resource + ]; + } + } catch (e) { + return []; } } else { return []; diff --git a/src/services/groups-service/groups-service.ts b/src/services/groups-service/groups-service.ts index 65ae705e..299e6808 100644 --- a/src/services/groups-service/groups-service.ts +++ b/src/services/groups-service/groups-service.ts @@ -10,6 +10,7 @@ import { ProjectResource } from "~/models/project"; import { ProcessResource } from "~/models/process"; import { TrashableResource } from "~/models/resource"; import { TrashableResourceService } from "~/services/common-service/trashable-resource-service"; +import { GroupResource } from '~/models/group'; export interface ContentsArguments { limit?: number; @@ -29,7 +30,7 @@ export type GroupContentsResource = ProjectResource | ProcessResource; -export class GroupsService extends TrashableResourceService { +export class GroupsService extends TrashableResourceService { constructor(serverApi: AxiosInstance) { super(serverApi, "groups"); diff --git a/src/store/breadcrumbs/breadcrumbs-actions.ts b/src/store/breadcrumbs/breadcrumbs-actions.ts index cc7bb1dd..dd35da3b 100644 --- a/src/store/breadcrumbs/breadcrumbs-actions.ts +++ b/src/store/breadcrumbs/breadcrumbs-actions.ts @@ -10,6 +10,10 @@ import { TreePicker } from '../tree-picker/tree-picker'; import { getSidePanelTreeBranch } from '../side-panel-tree/side-panel-tree-actions'; import { propertiesActions } from '../properties/properties-actions'; import { getProcess } from '~/store/processes/process'; +import { ServiceRepository } from '~/services/services'; +import { SidePanelTreeCategory } from '~/store/side-panel-tree/side-panel-tree-actions'; +import { updateResources } from '../resources/resources-actions'; +import { ResourceKind } from '~/models/resource'; export const BREADCRUMBS = 'breadcrumbs'; @@ -35,6 +39,22 @@ export const setSidePanelBreadcrumbs = (uuid: string) => dispatch(setBreadcrumbs(breadcrumbs)); }; +export const setSharedWithMeBreadcrumbs = (uuid: string) => + 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 } + ]; + const breadrumbs = ancestors.reduce((breadcrumbs, ancestor) => + ancestor.kind === ResourceKind.GROUP + ? [...breadcrumbs, { label: ancestor.name, uuid: ancestor.uuid }] + : breadcrumbs, + initialBreadcrumbs); + + dispatch(setBreadcrumbs(breadrumbs)); + }; + export const setProjectBreadcrumbs = setSidePanelBreadcrumbs; export const setCollectionBreadcrumbs = (collectionUuid: string) => diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index b65f6875..c68c5398 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -24,6 +24,8 @@ export const navigateTo = (uuid: string) => } if (uuid === SidePanelTreeCategory.FAVORITES) { dispatch(navigateToFavorites); + } else if(uuid === SidePanelTreeCategory.SHARED_WITH_ME){ + dispatch(navigateToSharedWithMe); } }; diff --git a/src/store/side-panel-tree/side-panel-tree-actions.ts b/src/store/side-panel-tree/side-panel-tree-actions.ts index 95e409f5..073de22c 100644 --- a/src/store/side-panel-tree/side-panel-tree-actions.ts +++ b/src/store/side-panel-tree/side-panel-tree-actions.ts @@ -147,14 +147,14 @@ export const expandSidePanelTreeItem = (nodeId: string) => } }; -const getSidePanelTreeNode = (nodeId: string) => (treePicker: TreePicker) => { +export const getSidePanelTreeNode = (nodeId: string) => (treePicker: TreePicker) => { const sidePanelTree = getTreePicker(SIDE_PANEL_TREE)(treePicker); return sidePanelTree ? getNodeValue(nodeId)(sidePanelTree) : undefined; }; -const getSidePanelTreeNodeAncestorsIds = (nodeId: string) => (treePicker: TreePicker) => { +export const getSidePanelTreeNodeAncestorsIds = (nodeId: string) => (treePicker: TreePicker) => { const sidePanelTree = getTreePicker(SIDE_PANEL_TREE)(treePicker); return sidePanelTree ? getNodeAncestorsIds(nodeId)(sidePanelTree) diff --git a/src/store/workbench/workbench-actions.ts b/src/store/workbench/workbench-actions.ts index bb41fa28..22b7b483 100644 --- a/src/store/workbench/workbench-actions.ts +++ b/src/store/workbench/workbench-actions.ts @@ -9,13 +9,13 @@ import { loadCollectionPanel } from '~/store/collection-panel/collection-panel-a import { snackbarActions } from '../snackbar/snackbar-actions'; import { loadFavoritePanel } from '../favorite-panel/favorite-panel-action'; import { openProjectPanel, projectPanelActions } from '~/store/project-panel/project-panel-action'; -import { activateSidePanelTreeItem, initSidePanelTree, SidePanelTreeCategory, loadSidePanelTreeProjects } from '../side-panel-tree/side-panel-tree-actions'; +import { activateSidePanelTreeItem, initSidePanelTree, SidePanelTreeCategory, loadSidePanelTreeProjects, getSidePanelTreeNodeAncestorsIds } from '../side-panel-tree/side-panel-tree-actions'; import { loadResource, updateResources } from '../resources/resources-actions'; import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action'; 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 } from '../breadcrumbs/breadcrumbs-actions'; +import { setCollectionBreadcrumbs, setProjectBreadcrumbs, setSidePanelBreadcrumbs, setProcessBreadcrumbs, setSharedWithMeBreadcrumbs } 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'; @@ -82,10 +82,16 @@ export const loadTrash = () => }; export const loadProject = (uuid: string) => - async (dispatch: Dispatch) => { - dispatch(openProjectPanel(uuid)); - await dispatch(activateSidePanelTreeItem(uuid)); - dispatch(setProjectBreadcrumbs(uuid)); + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(openProjectPanel(uuid)); + await dispatch(activateSidePanelTreeItem(uuid)); + const ancestors = getSidePanelTreeNodeAncestorsIds(uuid)(getState().treePicker); + if (ancestors.find(uuid => uuid === services.authService.getUuid())) { + dispatch(setProjectBreadcrumbs(uuid)); + } else { + dispatch(setSharedWithMeBreadcrumbs(uuid)); + dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME)); + } dispatch(loadDetailsPanel(uuid)); }; -- 2.30.2