From 1a90c384645ab8880d68abb5dbee1d1193f80538 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Mon, 27 Aug 2018 19:21:36 +0200 Subject: [PATCH] Reuse openContextMenu action Feature #14102 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- .../context-menu/context-menu-actions.ts | 14 +++++++++ .../collection-panel-files.ts | 15 ++++------ .../collection-panel/collection-panel.tsx | 10 ++----- src/views/favorite-panel/favorite-panel.tsx | 13 ++++---- src/views/project-panel/project-panel.tsx | 30 +++---------------- 5 files changed, 30 insertions(+), 52 deletions(-) diff --git a/src/store/context-menu/context-menu-actions.ts b/src/store/context-menu/context-menu-actions.ts index 26e25c3d..40623999 100644 --- a/src/store/context-menu/context-menu-actions.ts +++ b/src/store/context-menu/context-menu-actions.ts @@ -66,3 +66,17 @@ export const openSidePanelContextMenu = (event: React.MouseEvent, i } } }; + +export const resourceKindToContextMenuKind = (uuid: string) => { + const kind = extractUuidKind(uuid); + switch (kind) { + case ResourceKind.PROJECT: + return ContextMenuKind.PROJECT; + case ResourceKind.COLLECTION: + return ContextMenuKind.COLLECTION_RESOURCE; + case ResourceKind.USER: + return ContextMenuKind.ROOT_PROJECT; + default: + return; + } +}; diff --git a/src/views-components/collection-panel-files/collection-panel-files.ts b/src/views-components/collection-panel-files/collection-panel-files.ts index 3e99e10a..10469957 100644 --- a/src/views-components/collection-panel-files/collection-panel-files.ts +++ b/src/views-components/collection-panel-files/collection-panel-files.ts @@ -15,6 +15,7 @@ import { ContextMenuKind } from "../context-menu/context-menu"; import { Tree, getNodeChildrenIds, getNode } from "~/models/tree"; import { CollectionFileType } from "~/models/collection-file"; import { openUploadCollectionFilesDialog } from '~/store/collections/uploader/collection-uploader-actions'; +import { openContextMenu } from '../../store/context-menu/context-menu-actions'; const memoizedMapStateToProps = () => { let prevState: CollectionPanelFilesState; @@ -43,17 +44,11 @@ const mapDispatchToProps = (dispatch: Dispatch): Pick { - event.preventDefault(); - dispatch(contextMenuActions.OPEN_CONTEXT_MENU({ - position: { x: event.clientX, y: event.clientY }, - resource: { kind: ContextMenuKind.COLLECTION_FILES_ITEM, name: item.data.name, uuid: item.id } - })); + dispatch(openContextMenu(event, { kind: ContextMenuKind.COLLECTION_FILES_ITEM, name: item.data.name, uuid: item.id })); + }, + onOptionsMenuOpen: (event) => { + dispatch(openContextMenu(event, { kind: ContextMenuKind.COLLECTION_FILES, name: '', uuid: '' })); }, - onOptionsMenuOpen: (event) => - dispatch(contextMenuActions.OPEN_CONTEXT_MENU({ - position: { x: event.clientX, y: event.clientY }, - resource: { kind: ContextMenuKind.COLLECTION_FILES, name: '', uuid: '' } - })) }); diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx index d22dd0de..348b548b 100644 --- a/src/views/collection-panel/collection-panel.tsx +++ b/src/views/collection-panel/collection-panel.tsx @@ -21,7 +21,7 @@ import { CollectionTagForm } from './collection-tag-form'; import { deleteCollectionTag } from '~/store/collection-panel/collection-panel-action'; import { snackbarActions } from '~/store/snackbar/snackbar-actions'; import { getResource } from '~/store/resources/resources'; -import { contextMenuActions } from '~/store/context-menu/context-menu-actions'; +import { contextMenuActions, openContextMenu } from '~/store/context-menu/context-menu-actions'; import { ContextMenuKind } from '~/views-components/context-menu/context-menu'; type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'label' | 'value'; @@ -134,7 +134,6 @@ export const CollectionPanel = withStyles(styles)( } handleContextMenu = (event: React.MouseEvent) => { - event.preventDefault(); const { uuid, name, description } = this.props.item; const resource = { uuid, @@ -142,12 +141,7 @@ export const CollectionPanel = withStyles(styles)( description, kind: ContextMenuKind.COLLECTION }; - this.props.dispatch( - contextMenuActions.OPEN_CONTEXT_MENU({ - position: { x: event.clientX, y: event.clientY }, - resource - }) - ); + this.props.dispatch(openContextMenu(event, resource)); } handleDelete = (uuid: string) => () => { diff --git a/src/views/favorite-panel/favorite-panel.tsx b/src/views/favorite-panel/favorite-panel.tsx index f02c906a..9fbae5ce 100644 --- a/src/views/favorite-panel/favorite-panel.tsx +++ b/src/views/favorite-panel/favorite-panel.tsx @@ -18,7 +18,7 @@ import { FAVORITE_PANEL_ID } from "~/store/favorite-panel/favorite-panel-action" import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner, ResourceName } from '~/views-components/data-explorer/renderers'; import { FavoriteIcon } from '~/components/icon/icon'; import { Dispatch } from 'redux'; -import { contextMenuActions } from '~/store/context-menu/context-menu-actions'; +import { contextMenuActions, openContextMenu, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions'; import { ContextMenuKind } from '~/views-components/context-menu/context-menu'; import { loadDetailsPanel } from '../../store/details-panel/details-panel-action'; import { navigateTo } from '~/store/navigation/navigation-action'; @@ -150,13 +150,10 @@ interface FavoritePanelActionProps { const mapDispatchToProps = (dispatch: Dispatch): FavoritePanelActionProps => ({ onContextMenu: (event, resourceUuid) => { - event.preventDefault(); - dispatch( - contextMenuActions.OPEN_CONTEXT_MENU({ - position: { x: event.clientX, y: event.clientY }, - resource: { name: '', uuid: resourceUuid, kind: ContextMenuKind.RESOURCE } - }) - ); + const kind = resourceKindToContextMenuKind(resourceUuid); + if (kind) { + dispatch(openContextMenu(event, { name: '', uuid: resourceUuid, kind })); + } }, onDialogOpen: (ownerUuid: string) => { return; }, onItemClick: (resourceUuid: string) => { diff --git a/src/views/project-panel/project-panel.tsx b/src/views/project-panel/project-panel.tsx index 01c2602e..06946430 100644 --- a/src/views/project-panel/project-panel.tsx +++ b/src/views/project-panel/project-panel.tsx @@ -21,7 +21,7 @@ import { ResourceName } from '~/views-components/data-explorer/renderers'; import { ResourcesState, getResource } from '~/store/resources/resources'; import { loadDetailsPanel } from '~/store/details-panel/details-panel-action'; import { ContextMenuKind } from '~/views-components/context-menu/context-menu'; -import { contextMenuActions } from '~/store/context-menu/context-menu-actions'; +import { contextMenuActions, resourceKindToContextMenuKind, openContextMenu } from '~/store/context-menu/context-menu-actions'; import { CollectionResource } from '~/models/collection'; import { ProjectResource } from '~/models/project'; import { navigateTo } from '~/store/navigation/navigation-action'; @@ -198,31 +198,9 @@ export const ProjectPanel = withStyles(styles)( } handleContextMenu = (event: React.MouseEvent, resourceUuid: string) => { - event.preventDefault(); - const resource = getResource(resourceUuid)(this.props.resources) as CollectionResource | ProjectResource | undefined; - if (resource) { - let kind: ContextMenuKind; - - if (resource.kind === ResourceKind.PROJECT) { - kind = ContextMenuKind.PROJECT; - } else if (resource.kind === ResourceKind.COLLECTION) { - kind = ContextMenuKind.COLLECTION_RESOURCE; - } else { - kind = ContextMenuKind.RESOURCE; - } - if (kind !== ContextMenuKind.RESOURCE) { - this.props.dispatch( - contextMenuActions.OPEN_CONTEXT_MENU({ - position: { x: event.clientX, y: event.clientY }, - resource: { - uuid: resource.uuid, - name: resource.name || '', - description: resource.description, - kind, - } - }) - ); - } + const kind = resourceKindToContextMenuKind(resourceUuid); + if (kind) { + this.props.dispatch(openContextMenu(event, { name: '', uuid: resourceUuid, kind })); } } -- 2.30.2