X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/1feb5aaffe6fee4a9c8c8c64877f1da6f3490e06..22b351e5d49e861d1b1f73b87689e986002cb08a:/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 f0be4497..5edfbc37 100644
--- a/src/views-components/details-panel/collection-details.tsx
+++ b/src/views-components/details-panel/collection-details.tsx
@@ -2,14 +2,54 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { CollectionIcon } from '../../components/icon/icon';
-import { CollectionResource } from '../../models/collection';
-import { formatDate } from '../../common/formatters';
-import { resourceLabel } from '../../common/labels';
-import { ResourceKind } from '../../models/resource';
+import React from 'react';
+import { CollectionIcon, RenameIcon } from 'components/icon/icon';
+import { CollectionResource } from 'models/collection';
 import { DetailsData } from "./details-data";
-import { DetailsAttribute } from "../../components/details-attribute/details-attribute";
+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 { 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'
+    | 'versionBrowserField'
+    | 'editButton'
+    | 'editIcon'
+    | 'tag';
+
+const styles: StyleRulesCallback<CssRules> = theme => ({
+    versionBrowserHeader: {
+        textAlign: 'center',
+        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> {
 
@@ -17,19 +57,167 @@ export class CollectionDetails extends DetailsData<CollectionResource> {
         return <CollectionIcon className={className} />;
     }
 
-    getDetails() {
-        return <div>
-            <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.COLLECTION)} />
-            <DetailsAttribute label='Size' value='---' />
-            <DetailsAttribute label='Owner' value={this.item.ownerUuid} />
-            <DetailsAttribute label='Last modified' value={formatDate(this.item.modifiedAt)} />
-            <DetailsAttribute label='Created at' value={formatDate(this.item.createdAt)} />
-            {/* Links but we dont have view */}
-            <DetailsAttribute label='Collection UUID' link={this.item.uuid} value={this.item.uuid} />
-            <DetailsAttribute label='Content address' link={this.item.portableDataHash} value={this.item.portableDataHash} />
-            {/* Missing attrs */}
-            <DetailsAttribute label='Number of files' value='20' />
-            <DetailsAttribute label='Content size' value='54 MB' />
-        </div>;
+    getTabLabels() {
+        return ['Details', 'Versions'];
+    }
+
+    getDetails({tabNr}) {
+        switch (tabNr) {
+            case 0:
+                return this.getCollectionInfo();
+            case 1:
+                return this.getVersionBrowser();
+            default:
+                return <div />;
+        }
+    }
+
+    private getCollectionInfo() {
+        return <CollectionInfo />;
     }
+
+    private getVersionBrowser() {
+        return <CollectionVersionBrowser />;
+    }
+}
+
+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[];
+}
+
+interface CollectionVersionBrowserDispatchProps {
+    showVersion: (c: CollectionResource) => void;
+    handleContextMenu: (event: React.MouseEvent<HTMLElement>, collection: CollectionResource) => void;
+}
+
+const vbMapStateToProps = (state: RootState): CollectionVersionBrowserProps => {
+    const currentCollection = getResource<CollectionResource>(state.detailsPanel.resourceUuid)(state.resources);
+    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 };
+};
+
+const vbMapDispatchToProps = () =>
+    (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,
+                    description: collection.description,
+                    storageClassesDesired: collection.storageClassesDesired,
+                    ownerUuid: collection.ownerUuid,
+                    isTrashed: collection.isTrashed,
+                    kind: collection.kind,
+                    menuKind
+                }));
+            }
+        },
+    });
+
+const CollectionVersionBrowser = withStyles(styles)(
+    connect(vbMapStateToProps, vbMapDispatchToProps)(
+        ({ 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 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}
+                            className={classes.versionBrowserItem}>
+                            <Grid item xs={2}>
+                                <Typography variant="caption" className={classes.versionBrowserField}>
+                                    {item.version}
+                                </Typography>
+                            </Grid>
+                            <Grid item xs={4}>
+                                <Typography variant="caption" className={classes.versionBrowserField}>
+                                    {formatFileSize(item.fileSizeTotal)}
+                                </Typography>
+                            </Grid>
+                            <Grid item xs={6}>
+                                <Typography variant="caption" className={classes.versionBrowserField}>
+                                    {formatDate(item.modifiedAt)}
+                                </Typography>
+                            </Grid>
+                            <Grid item xs={12}>
+                                <Typography variant="caption" className={classes.versionBrowserField}>
+                                    Modified by: <UserNameFromID uuid={item.modifiedByUserUuid} />
+                                </Typography>
+                            </Grid>
+                        </ListItem>
+                    );
+                })}
+                </Grid>
+            </div>;
+        }));
