From: Lucas Di Pentima Date: Wed, 25 Nov 2020 17:53:29 +0000 (-0300) Subject: 17098: Merge branch 'master' into 17098-old-version-as-head X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/eda7767bc88b7a2a3dc582af47417937ff4de38a?hp=673bf2ac4b09da2d868fdb99123d72f23d2f88cf 17098: Merge branch 'master' into 17098-old-version-as-head Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/cypress/integration/collection-panel.spec.js b/cypress/integration/collection-panel.spec.js index 59b80e6770..9c5c656a06 100644 --- a/cypress/integration/collection-panel.spec.js +++ b/cypress/integration/collection-panel.spec.js @@ -394,6 +394,21 @@ describe('Collection panel tests', function() { 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('not.contain', 'Add to favorites') + .and('contain', 'Make a copy') + .and('not.contain', 'Edit collection'); + cy.get('body').click(); + // Recover first version cy.get('[data-cy=collection-version-browser]').within(() => { cy.get('[data-cy=collection-version-browser-select-1]').click(); diff --git a/src/views-components/details-panel/collection-details.tsx b/src/views-components/details-panel/collection-details.tsx index b0449bffeb..6066a5889f 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}>