From 9efef4484a8c28b97dae64e785e2dd7c38687cca Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Tue, 25 Sep 2018 11:06:05 +0200 Subject: [PATCH] Update loadCollection action to handle trashed and shared collections Feature #14244 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/store/workbench/workbench-actions.ts | 50 ++++++-- .../collection-panel/collection-panel.tsx | 114 +++++++++--------- 2 files changed, 100 insertions(+), 64 deletions(-) diff --git a/src/store/workbench/workbench-actions.ts b/src/store/workbench/workbench-actions.ts index d56b6c36bf..4dd416972b 100644 --- a/src/store/workbench/workbench-actions.ts +++ b/src/store/workbench/workbench-actions.ts @@ -41,10 +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 { ResourceKind, extractUuidKind } from '~/models/resource'; import { FilterBuilder } from '~/services/api/filter-builder'; import { ProjectResource } from '~/models/project'; - +import { CollectionResource } from '~/models/collection'; export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen'; @@ -189,7 +189,7 @@ export const moveProject = (data: MoveToFormDialogData) => }; export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + async (dispatch: Dispatch) => { const updatedProject = await dispatch(projectUpdateActions.updateProject(data)); if (updatedProject) { dispatch(snackbarActions.OPEN_SNACKBAR({ @@ -203,11 +203,45 @@ export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialog export const loadCollection = (uuid: string) => handleFirstTimeLoad( - async (dispatch: Dispatch) => { - const collection = await dispatch(loadCollectionPanel(uuid)); - await dispatch(activateSidePanelTreeItem(collection.ownerUuid)); - dispatch(setCollectionBreadcrumbs(collection.uuid)); - dispatch(loadDetailsPanel(uuid)); + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const userUuid = services.authService.getUuid(); + if (userUuid) { + let collection: CollectionResource | null = null; + + if (extractUuidKind(uuid) === ResourceKind.COLLECTION) { + /** + * 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.COLLECTION) { + collection = resource; + if (collection.isTrashed) { + dispatch(setTrashBreadcrumbs('')); + dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH)); + } else { + await dispatch(activateSidePanelTreeItem(collection.ownerUuid)); + dispatch(setSidePanelBreadcrumbs(collection.ownerUuid)); + } + } + } 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 + */ + collection = await services.collectionService.get(uuid); + if (collection) { + dispatch(setSharedWithMeBreadcrumbs(collection.ownerUuid)); + dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME)); + } + } + if (collection) { + dispatch(updateResources([collection])); + } + } + } }); export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx index 0b264b6bab..672493769d 100644 --- a/src/views/collection-panel/collection-panel.tsx +++ b/src/views/collection-panel/collection-panel.tsx @@ -70,65 +70,67 @@ export const CollectionPanel = withStyles(styles)( class extends React.Component { render() { const { classes, item } = this.props; - return
- - } - action={ - - - - - - } - title={item && item.name} - subheader={item && item.description} /> - - - - - - this.onCopy()}> - - - - - - - + return item + ? <> + + } + action={ + + + + + + } + title={item && item.name} + subheader={item && item.description} /> + + + + + + this.onCopy()}> + + + + + + + + - - - + + - - - - - - - { - Object.keys(item.properties).map( key => { - return ; - }) - } + + + + + + + { + Object.keys(item.properties).map(key => { + return ; + }) + } + - - - -
- -
-
; + + +
+ +
+ + : null; } handleContextMenu = (event: React.MouseEvent) => { -- 2.30.2