17782: Fixes almost all tests (4 left) mostly by fixing namespace-type imports.
[arvados-workbench2.git] / src / views-components / details-panel / collection-details.tsx
index 51b09b4faa48e43bf46f85088212b669bba9ce91..9f03f38a3b4d3bf8da3963faa478fbc2fd99c783 100644 (file)
@@ -2,28 +2,29 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { CollectionIcon } from '~/components/icon/icon';
-import { CollectionResource } from '~/models/collection';
+import React from 'react';
+import { CollectionIcon } from 'components/icon/icon';
+import { CollectionResource } from 'models/collection';
 import { DetailsData } from "./details-data";
-import { CollectionDetailsAttributes } from '~/views/collection-panel/collection-panel';
-import { RootState } from '~/store/store';
-import { filterResources, getResource } from '~/store/resources/resources';
+import { CollectionDetailsAttributes } from 'views/collection-panel/collection-panel';
+import { RootState } from 'store/store';
+import { filterResources, getResource } from 'store/resources/resources';
 import { connect } from 'react-redux';
 import { Grid, ListItem, StyleRulesCallback, Typography, withStyles, WithStyles } from '@material-ui/core';
-import { formatDate, formatFileSize } from '~/common/formatters';
+import { formatDate, formatFileSize } from 'common/formatters';
 import { Dispatch } from 'redux';
-import { navigateTo } from '~/store/navigation/navigation-action';
+import { navigateTo } from 'store/navigation/navigation-action';
+import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
 
-export type CssRules = 'versionBrowserHeader' | 'selectedVersion';
+export type CssRules = 'versionBrowserHeader' | 'versionBrowserItem';
 
 const styles: StyleRulesCallback<CssRules> = theme => ({
     versionBrowserHeader: {
         textAlign: 'center',
-        fontWeight: 'bold'
+        fontWeight: 'bold',
     },
-    selectedVersion: {
-        fontWeight: 'bold'
+    versionBrowserItem: {
+        textAlign: 'center',
     }
 });
 
@@ -64,6 +65,7 @@ interface CollectionVersionBrowserProps {
 
 interface CollectionVersionBrowserDispatchProps {
     showVersion: (c: CollectionResource) => void;
+    handleContextMenu: (event: React.MouseEvent<HTMLElement>, collection: CollectionResource) => void;
 }
 
 const mapStateToProps = (state: RootState): CollectionVersionBrowserProps => {
@@ -79,44 +81,68 @@ const mapStateToProps = (state: RootState): CollectionVersionBrowserProps => {
 const mapDispatchToProps = () =>
     (dispatch: Dispatch): CollectionVersionBrowserDispatchProps => ({
         showVersion: (collection) => dispatch<any>(navigateTo(collection.uuid)),
+        handleContextMenu: (event: React.MouseEvent<HTMLElement>, collection: CollectionResource) => {
+            const menuKind = dispatch<any>(resourceUuidToContextMenuKind(collection.uuid));
+            if (collection && menuKind) {
+                dispatch<any>(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<CssRules>) => {
-            return <>
-                <Grid container justify="space-between">
-                    <Typography variant="caption" className={classes.versionBrowserHeader}>
-                        Version
-                    </Typography>
-                    <Typography variant="caption" className={classes.versionBrowserHeader}>
-                        Size
-                    </Typography>
-                    <Typography variant="caption" className={classes.versionBrowserHeader}>
-                        Date
-                    </Typography>
-                </Grid>
+        ({ currentCollection, versions, showVersion, handleContextMenu, classes }: CollectionVersionBrowserProps & CollectionVersionBrowserDispatchProps & WithStyles<CssRules>) => {
+            return <div data-cy="collection-version-browser">
+                <Grid container>
+                    <Grid item xs={2}>
+                        <Typography variant="caption" className={classes.versionBrowserHeader}>
+                            Nr
+                        </Typography>
+                    </Grid>
+                    <Grid item xs={4}>
+                        <Typography variant="caption" className={classes.versionBrowserHeader}>
+                            Size
+                        </Typography>
+                    </Grid>
+                    <Grid item xs={6}>
+                        <Typography variant="caption" className={classes.versionBrowserHeader}>
+                            Date
+                        </Typography>
+                    </Grid>
                 { versions.map(item => {
                     const isSelectedVersion = !!(currentCollection && currentCollection.uuid === item.uuid);
                     return (
-                        <ListItem button
-                            className={isSelectedVersion ? 'selectedVersion' : ''}
+                        <ListItem button style={{padding: '4px'}}
+                            data-cy={`collection-version-browser-select-${item.version}`}
                             key={item.version}
                             onClick={e => showVersion(item)}
+                            onContextMenu={event => handleContextMenu(event, item)}
                             selected={isSelectedVersion}>
-                            <Grid container justify="space-between">
-                                <Typography variant="caption">
+                            <Grid item xs={2}>
+                                <Typography variant="caption" className={classes.versionBrowserItem}>
                                     {item.version}
                                 </Typography>
-                                <Typography variant="caption">
+                            </Grid>
+                            <Grid item xs={4}>
+                                <Typography variant="caption" className={classes.versionBrowserItem}>
                                     {formatFileSize(item.fileSizeTotal)}
                                 </Typography>
-                                <Typography variant="caption">
+                            </Grid>
+                            <Grid item xs={6}>
+                                <Typography variant="caption" className={classes.versionBrowserItem}>
                                     {formatDate(item.modifiedAt)}
                                 </Typography>
                             </Grid>
                         </ListItem>
                     );
                 })}
-            </>;
+                </Grid>
+            </div>;
         }));
\ No newline at end of file