From: Lucas Di Pentima Date: Tue, 24 Nov 2020 20:02:54 +0000 (-0300) Subject: 13494: Adds context menu support to collection versions browser. X-Git-Tag: 2.1.2~26^2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/306d28fed8af239094ca8eaf956d3410fafc031b?hp=-c 13494: Adds context menu support to collection versions browser. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- 306d28fed8af239094ca8eaf956d3410fafc031b diff --git a/cypress/integration/collection-panel.spec.js b/cypress/integration/collection-panel.spec.js index 2b9957a3..377f11d9 100644 --- a/cypress/integration/collection-panel.spec.js +++ b/cypress/integration/collection-panel.spec.js @@ -381,6 +381,21 @@ describe('Collection panel tests', function() { .should('not.contain', 'foo').and('contain', 'bar'); cy.get('[data-cy=collection-version-browser-select-3]') .should('contain', '3').and('contain', '3 B'); + + // Check context menus on version browser + cy.get('[data-cy=collection-version-browser-select-3]').rightclick() + cy.get('[data-cy=context-menu]') + .should('contain', 'Add to favorites') + .and('contain', 'Make a copy') + .and('contain', 'Edit collection'); + cy.get('body').click(); + // (and now an old version...) + cy.get('[data-cy=collection-version-browser-select-1]').rightclick() + cy.get('[data-cy=context-menu]') + .should('contain', 'Add to favorites') + .and('contain', 'Make a copy') + .and('not.contain', 'Edit collection'); + cy.get('body').click(); }); }); }) diff --git a/src/views-components/details-panel/collection-details.tsx b/src/views-components/details-panel/collection-details.tsx index b0449bff..6066a588 100644 --- a/src/views-components/details-panel/collection-details.tsx +++ b/src/views-components/details-panel/collection-details.tsx @@ -14,6 +14,8 @@ import { Grid, ListItem, StyleRulesCallback, Typography, withStyles, WithStyles import { formatDate, formatFileSize } from '~/common/formatters'; import { Dispatch } from 'redux'; import { navigateTo } from '~/store/navigation/navigation-action'; +import { resourceKindToContextMenuKind, openContextMenu } from '~/store/context-menu/context-menu-actions'; +import { ContextMenuKind } from '../context-menu/context-menu'; export type CssRules = 'versionBrowserHeader' | 'versionBrowserItem'; @@ -60,30 +62,45 @@ export class CollectionDetails extends DetailsData { interface CollectionVersionBrowserProps { currentCollection: CollectionResource | undefined; versions: CollectionResource[]; + isAdmin: boolean; } interface CollectionVersionBrowserDispatchProps { showVersion: (c: CollectionResource) => void; + handleContextMenu: (event: React.MouseEvent, collection: CollectionResource, menuKind: ContextMenuKind | undefined) => void; } const mapStateToProps = (state: RootState): CollectionVersionBrowserProps => { const currentCollection = getResource(state.detailsPanel.resourceUuid)(state.resources); + const isAdmin = state.auth.user!.isAdmin; const versions = currentCollection && filterResources(rsc => (rsc as CollectionResource).currentVersionUuid === currentCollection.currentVersionUuid)(state.resources) .sort((a: CollectionResource, b: CollectionResource) => b.version - a.version) as CollectionResource[] || []; - return { currentCollection, versions }; + return { currentCollection, versions, isAdmin }; }; const mapDispatchToProps = () => (dispatch: Dispatch): CollectionVersionBrowserDispatchProps => ({ showVersion: (collection) => dispatch(navigateTo(collection.uuid)), + handleContextMenu: (event: React.MouseEvent, collection: CollectionResource, menuKind: ContextMenuKind) => { + if (collection && menuKind) { + dispatch(openContextMenu(event, { + name: collection.name, + uuid: collection.uuid, + ownerUuid: collection.ownerUuid, + isTrashed: collection.isTrashed, + kind: collection.kind, + menuKind + })); + } + }, }); const CollectionVersionBrowser = withStyles(styles)( connect(mapStateToProps, mapDispatchToProps)( - ({ currentCollection, versions, showVersion, classes }: CollectionVersionBrowserProps & CollectionVersionBrowserDispatchProps & WithStyles) => { + ({ currentCollection, versions, isAdmin, showVersion, handleContextMenu, classes }: CollectionVersionBrowserProps & CollectionVersionBrowserDispatchProps & WithStyles) => { return
@@ -108,6 +125,14 @@ const CollectionVersionBrowser = withStyles(styles)( data-cy={`collection-version-browser-select-${item.version}`} key={item.version} onClick={e => showVersion(item)} + onContextMenu={event => handleContextMenu( + event, + item, + resourceKindToContextMenuKind( + item.uuid, + isAdmin, + (item.uuid === item.currentVersionUuid)) + )} selected={isSelectedVersion}>