X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/4541e7e78a5fbbad1e34cf215fa7f2fa4d40e88d..1e771e8083df71d11da85dae8bfd0a0cdfb1737f:/src/views-components/details-panel/collection-details.tsx

diff --git a/src/views-components/details-panel/collection-details.tsx b/src/views-components/details-panel/collection-details.tsx
index 0d4fce51..5edfbc37 100644
--- a/src/views-components/details-panel/collection-details.tsx
+++ b/src/views-components/details-panel/collection-details.tsx
@@ -3,21 +3,27 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import React from 'react';
-import { CollectionIcon } from 'components/icon/icon';
+import { CollectionIcon, RenameIcon } 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 { connect } from 'react-redux';
-import { Grid, ListItem, StyleRulesCallback, Typography, withStyles, WithStyles } from '@material-ui/core';
+import { Button, Grid, ListItem, StyleRulesCallback, Typography, withStyles, WithStyles } from '@material-ui/core';
 import { formatDate, formatFileSize } from 'common/formatters';
 import { UserNameFromID } from '../data-explorer/renderers';
 import { Dispatch } from 'redux';
 import { navigateTo } from 'store/navigation/navigation-action';
 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
+import { openCollectionUpdateDialog } from 'store/collections/collection-update-actions';
 
-export type CssRules = 'versionBrowserHeader' | 'versionBrowserItem';
+export type CssRules = 'versionBrowserHeader'
+    | 'versionBrowserItem'
+    | 'versionBrowserField'
+    | 'editButton'
+    | 'editIcon'
+    | 'tag';
 
 const styles: StyleRulesCallback<CssRules> = theme => ({
     versionBrowserHeader: {
@@ -25,8 +31,24 @@ const styles: StyleRulesCallback<CssRules> = theme => ({
         fontWeight: 'bold',
     },
     versionBrowserItem: {
+        flexWrap: 'wrap',
+    },
+    versionBrowserField: {
         textAlign: 'center',
-    }
+    },
+    editIcon: {
+        paddingRight: theme.spacing.unit/2,
+        fontSize: '1.125rem',
+    },
+    editButton: {
+        boxShadow: 'none',
+        padding: '2px 10px 2px 5px',
+        fontSize: '0.75rem'
+    },
+    tag: {
+        marginRight: theme.spacing.unit / 2,
+        marginBottom: theme.spacing.unit / 2
+    },
 });
 
 export class CollectionDetails extends DetailsData<CollectionResource> {
@@ -39,8 +61,8 @@ export class CollectionDetails extends DetailsData<CollectionResource> {
         return ['Details', 'Versions'];
     }
 
-    getDetails(tabNumber: number) {
-        switch (tabNumber) {
+    getDetails({tabNr}) {
+        switch (tabNr) {
             case 0:
                 return this.getCollectionInfo();
             case 1:
@@ -51,7 +73,7 @@ export class CollectionDetails extends DetailsData<CollectionResource> {
     }
 
     private getCollectionInfo() {
-        return <CollectionDetailsAttributes twoCol={false} item={this.item} />;
+        return <CollectionInfo />;
     }
 
     private getVersionBrowser() {
@@ -59,6 +81,50 @@ export class CollectionDetails extends DetailsData<CollectionResource> {
     }
 }
 
+interface CollectionInfoDataProps {
+    currentCollection: CollectionResource | undefined;
+}
+
+interface CollectionInfoDispatchProps {
+    editCollection: (collection: CollectionResource | undefined) => void;
+}
+
+const ciMapStateToProps = (state: RootState): CollectionInfoDataProps => {
+    return {
+        currentCollection: getResource<CollectionResource>(state.detailsPanel.resourceUuid)(state.resources),
+    };
+};
+
+const ciMapDispatchToProps = (dispatch: Dispatch): CollectionInfoDispatchProps => ({
+    editCollection: (collection: CollectionResource) =>
+        dispatch<any>(openCollectionUpdateDialog({
+            uuid: collection.uuid,
+            name: collection.name,
+            description: collection.description,
+            properties: collection.properties,
+            storageClassesDesired: collection.storageClassesDesired,
+        })),
+});
+
+type CollectionInfoProps = CollectionInfoDataProps & CollectionInfoDispatchProps & WithStyles<CssRules>;
+
+const CollectionInfo = withStyles(styles)(
+    connect(ciMapStateToProps, ciMapDispatchToProps)(
+        ({ currentCollection, editCollection, classes }: CollectionInfoProps) =>
+            currentCollection !== undefined
+                ? <div>
+                    <Button
+                        className={classes.editButton} variant='contained'
+                        data-cy='details-panel-edit-btn' color='primary' size='small'
+                        onClick={() => editCollection(currentCollection)}>
+                        <RenameIcon className={classes.editIcon} /> Edit
+                    </Button>
+                    <CollectionDetailsAttributes classes={classes} twoCol={false} item={currentCollection} />
+                </div>
+                : <div />
+    )
+);
+
 interface CollectionVersionBrowserProps {
     currentCollection: CollectionResource | undefined;
     versions: CollectionResource[];
@@ -69,7 +135,7 @@ interface CollectionVersionBrowserDispatchProps {
     handleContextMenu: (event: React.MouseEvent<HTMLElement>, collection: CollectionResource) => void;
 }
 
-const mapStateToProps = (state: RootState): CollectionVersionBrowserProps => {
+const vbMapStateToProps = (state: RootState): CollectionVersionBrowserProps => {
     const currentCollection = getResource<CollectionResource>(state.detailsPanel.resourceUuid)(state.resources);
     const versions = (currentCollection
         && filterResources(rsc =>
@@ -79,7 +145,7 @@ const mapStateToProps = (state: RootState): CollectionVersionBrowserProps => {
     return { currentCollection, versions };
 };
 
-const mapDispatchToProps = () =>
+const vbMapDispatchToProps = () =>
     (dispatch: Dispatch): CollectionVersionBrowserDispatchProps => ({
         showVersion: (collection) => dispatch<any>(navigateTo(collection.uuid)),
         handleContextMenu: (event: React.MouseEvent<HTMLElement>, collection: CollectionResource) => {
@@ -100,7 +166,7 @@ const mapDispatchToProps = () =>
     });
 
 const CollectionVersionBrowser = withStyles(styles)(
-    connect(mapStateToProps, mapDispatchToProps)(
+    connect(vbMapStateToProps, vbMapDispatchToProps)(
         ({ currentCollection, versions, showVersion, handleContextMenu, classes }: CollectionVersionBrowserProps & CollectionVersionBrowserDispatchProps & WithStyles<CssRules>) => {
             return <div data-cy="collection-version-browser">
                 <Grid container>
@@ -109,17 +175,12 @@ const CollectionVersionBrowser = withStyles(styles)(
                             Nr
                         </Typography>
                     </Grid>
-                    <Grid item xs={2}>
+                    <Grid item xs={4}>
                         <Typography variant="caption" className={classes.versionBrowserHeader}>
                             Size
                         </Typography>
                     </Grid>
-                    <Grid item xs={3}>
-                        <Typography variant="caption" className={classes.versionBrowserHeader}>
-                            User
-                        </Typography>
-                    </Grid>
-                    <Grid item xs={5}>
+                    <Grid item xs={6}>
                         <Typography variant="caption" className={classes.versionBrowserHeader}>
                             Date
                         </Typography>
@@ -132,25 +193,26 @@ const CollectionVersionBrowser = withStyles(styles)(
                             key={item.version}
                             onClick={e => showVersion(item)}
                             onContextMenu={event => handleContextMenu(event, item)}
-                            selected={isSelectedVersion}>
+                            selected={isSelectedVersion}
+                            className={classes.versionBrowserItem}>
                             <Grid item xs={2}>
-                                <Typography variant="caption" className={classes.versionBrowserItem}>
+                                <Typography variant="caption" className={classes.versionBrowserField}>
                                     {item.version}
                                 </Typography>
                             </Grid>
-                            <Grid item xs={2}>
-                                <Typography variant="caption" className={classes.versionBrowserItem}>
+                            <Grid item xs={4}>
+                                <Typography variant="caption" className={classes.versionBrowserField}>
                                     {formatFileSize(item.fileSizeTotal)}
                                 </Typography>
                             </Grid>
-                            <Grid item xs={3}>
-                                <Typography variant="caption" className={classes.versionBrowserItem}>
-                                    <UserNameFromID uuid={item.modifiedByUserUuid} />
+                            <Grid item xs={6}>
+                                <Typography variant="caption" className={classes.versionBrowserField}>
+                                    {formatDate(item.modifiedAt)}
                                 </Typography>
                             </Grid>
-                            <Grid item xs={5}>
-                                <Typography variant="caption" className={classes.versionBrowserItem}>
-                                    {formatDate(item.modifiedAt)}
+                            <Grid item xs={12}>
+                                <Typography variant="caption" className={classes.versionBrowserField}>
+                                    Modified by: <UserNameFromID uuid={item.modifiedByUserUuid} />
                                 </Typography>
                             </Grid>
                         </ListItem>
