X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/31df208339af5e30665455e193cdbde90dabaf1d..23199ed951991534b1c582dce5b609f758f50a68:/src/views/collection-panel/collection-panel.tsx?ds=sidebyside

diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx
index f476c9397c..5d799f0b27 100644
--- a/src/views/collection-panel/collection-panel.tsx
+++ b/src/views/collection-panel/collection-panel.tsx
@@ -5,7 +5,7 @@
 import * as React from 'react';
 import {
     StyleRulesCallback, WithStyles, withStyles, Card,
-    CardHeader, IconButton, CardContent, Grid, Chip
+    CardHeader, IconButton, CardContent, Grid, Chip, Tooltip
 } from '@material-ui/core';
 import { connect, DispatchProp } from "react-redux";
 import { RouteComponentProps } from 'react-router';
@@ -15,12 +15,18 @@ import { MoreOptionsIcon, CollectionIcon, CopyIcon } from '~/components/icon/ico
 import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
 import { CollectionResource } from '~/models/collection';
 import { CollectionPanelFiles } from '~/views-components/collection-panel-files/collection-panel-files';
-import * as CopyToClipboard from 'react-copy-to-clipboard';
-import { TagResource } from '~/models/tag';
 import { CollectionTagForm } from './collection-tag-form';
-import { deleteCollectionTag } from '~/store/collection-panel/collection-panel-action';
+import { deleteCollectionTag, navigateToProcess } from '~/store/collection-panel/collection-panel-action';
+import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
+import { getResource } from '~/store/resources/resources';
+import { openContextMenu } from '~/store/context-menu/context-menu-actions';
+import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
+import { formatFileSize } from "~/common/formatters";
+import { getResourceData } from "~/store/resources-data/resources-data";
+import { ResourceData } from "~/store/resources-data/resources-data-reducer";
+import { openDetailsPanel } from '~/store/details-panel/details-panel-action';
 
-type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'label' | 'value';
+type CssRules = 'card' | 'iconHeader' | 'tag' | 'label' | 'value' | 'link';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     card: {
@@ -34,73 +40,82 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
         marginRight: theme.spacing.unit,
         marginBottom: theme.spacing.unit
     },
-    copyIcon: {
-        marginLeft: theme.spacing.unit,
-        fontSize: '1.125rem',
-        color: theme.palette.grey["500"],
-        cursor: 'pointer'
-    },
     label: {
         fontSize: '0.875rem'
     },
     value: {
         textTransform: 'none',
         fontSize: '0.875rem'
+    },
+    link: {
+        fontSize: '0.875rem',
+        color: theme.palette.primary.main,
+        '&:hover': {
+            cursor: 'pointer'
+        }
     }
 });
 
 interface CollectionPanelDataProps {
     item: CollectionResource;
-    tags: TagResource[];
-}
-
-interface CollectionPanelActionProps {
-    onItemRouteChange: (collectionId: string) => void;
-    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
+    data: ResourceData;
 }
 
-type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps & DispatchProp
-                            & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
-
+type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
+    & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
 
 export const CollectionPanel = withStyles(styles)(
-    connect((state: RootState) => ({
-        item: state.collectionPanel.item,
-        tags: state.collectionPanel.tags
-    }))(
+    connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
+        const item = getResource(props.match.params.id)(state.resources);
+        const data = getResourceData(props.match.params.id)(state.resourcesData);
+        return { item, data };
+    })(
         class extends React.Component<CollectionPanelProps> {
 
             render() {
-                const { classes, item, tags, onContextMenu } = this.props;
-                return <div>
+                const { classes, item, data, dispatch } = this.props;
+                return item
+                    ? <>
                         <Card className={classes.card}>
                             <CardHeader
-                                avatar={ <CollectionIcon className={classes.iconHeader} /> }
-                                action={
-                                    <IconButton
-                                        aria-label="More options"
-                                        onClick={event => onContextMenu(event, item)}>
-                                        <MoreOptionsIcon />
+                                avatar={
+                                    <IconButton onClick={this.openCollectionDetails}>
+                                        <CollectionIcon className={classes.iconHeader} />
                                     </IconButton>
                                 }
-                                title={item && item.name }
-                                subheader={item && item.description} />
+                                action={
+                                    <Tooltip title="More options" disableFocusListener>
+                                        <IconButton
+                                            aria-label="More options"
+                                            onClick={this.handleContextMenu}>
+                                            <MoreOptionsIcon />
+                                        </IconButton>
+                                    </Tooltip>
+                                }
+                                title={item && item.name}
+                                titleTypographyProps={this.titleProps}
+                                subheader={item && item.description}
+                                subheaderTypographyProps={this.titleProps} />
                             <CardContent>
                                 <Grid container direction="column">
-                                    <Grid item xs={6}>
+                                    <Grid item xs={10}>
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Collection UUID'
+                                            linkToUuid={item && item.uuid} />
                                         <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                                label='Collection UUID'
-                                                value={item && item.uuid}>
-                                            <CopyToClipboard text={item && item.uuid}>
-                                                <CopyIcon className={classes.copyIcon} />
-                                            </CopyToClipboard>
-                                        </DetailsAttribute>
-                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value} 
-                                            label='Number of files' value='14' />
-                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value} 
-                                            label='Content size' value='54 MB' />
-                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value} 
-                                            label='Owner' value={item && item.ownerUuid} />
+                                            label='Portable data hash'
+                                            linkToUuid={item && item.portableDataHash} />
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Number of files' value={data && data.fileCount} />
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Content size' value={data && formatFileSize(data.fileSize)} />
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Owner' linkToUuid={item && item.ownerUuid} />
+                                        {(item.properties.container_request || item.properties.containerRequest) &&
+                                            <span onClick={() => dispatch<any>(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}>
+                                                <DetailsAttribute classLabel={classes.link} label='Link to process' />
+                                            </span>
+                                        }
                                     </Grid>
                                 </Grid>
                             </CardContent>
@@ -110,13 +125,15 @@ export const CollectionPanel = withStyles(styles)(
                             <CardHeader title="Properties" />
                             <CardContent>
                                 <Grid container direction="column">
-                                    <Grid item xs={12}><CollectionTagForm /></Grid>
+                                    <Grid item xs={12}>
+                                        <CollectionTagForm />
+                                    </Grid>
                                     <Grid item xs={12}>
                                         {
-                                            tags.map(tag => {
-                                                return <Chip key={tag.etag} className={classes.tag}
-                                                    onDelete={this.handleDelete(tag.uuid)}
-                                                    label={renderTagLabel(tag)}  />;
+                                            Object.keys(item.properties).map(k => {
+                                                return <Chip key={k} className={classes.tag}
+                                                    onDelete={this.handleDelete(k)}
+                                                    label={`${k}: ${item.properties[k]}`} />;
                                             })
                                         }
                                     </Grid>
@@ -124,26 +141,42 @@ export const CollectionPanel = withStyles(styles)(
                             </CardContent>
                         </Card>
                         <div className={classes.card}>
-                            <CollectionPanelFiles/>
+                            <CollectionPanelFiles />
                         </div>
-                    </div>;
+                    </>
+                    : null;
+            }
+
+            handleContextMenu = (event: React.MouseEvent<any>) => {
+                const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
+                const resource = {
+                    uuid,
+                    ownerUuid,
+                    name,
+                    description,
+                    kind,
+                    menuKind: isTrashed
+                        ? ContextMenuKind.TRASHED_COLLECTION
+                        : ContextMenuKind.COLLECTION
+                };
+                this.props.dispatch<any>(openContextMenu(event, resource));
             }
 
-            handleDelete = (uuid: string) => () => {
-                this.props.dispatch<any>(deleteCollectionTag(uuid));
+            handleDelete = (key: string) => () => {
+                this.props.dispatch<any>(deleteCollectionTag(key));
             }
 
-            componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
-                if (!item || match.params.id !== item.uuid) {
-                    onItemRouteChange(match.params.id);
+            openCollectionDetails = () => {
+                const { item } = this.props;
+                if (item) {
+                    this.props.dispatch(openDetailsPanel(item.uuid));
                 }
             }
 
+            titleProps = {
+                onClick: this.openCollectionDetails
+            };
+
         }
     )
 );
-
-const renderTagLabel = (tag: TagResource) => {
-    const { properties } = tag;
-    return `${properties.key}: ${properties.value}`;
-};
