X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/76522b9722369b2d99a43c64d898087ed7f8ee9a..4cad4c0d882111b0eb5576005108a62ff30b143d:/src/views/collection-panel/collection-panel.tsx

diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx
index 8e46385cc9..b92557f9de 100644
--- a/src/views/collection-panel/collection-panel.tsx
+++ b/src/views/collection-panel/collection-panel.tsx
@@ -5,26 +5,28 @@
 import * as React from 'react';
 import {
     StyleRulesCallback, WithStyles, withStyles, Card,
-    CardHeader, IconButton, CardContent, Grid, Chip, Tooltip
+    CardHeader, IconButton, CardContent, Grid, Tooltip
 } from '@material-ui/core';
 import { connect, DispatchProp } from "react-redux";
 import { RouteComponentProps } from 'react-router';
 import { ArvadosTheme } from '~/common/custom-theme';
 import { RootState } from '~/store/store';
-import { MoreOptionsIcon, CollectionIcon, CopyIcon } from '~/components/icon/icon';
+import { MoreOptionsIcon, CollectionIcon } from '~/components/icon/icon';
 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 { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import { deleteCollectionTag, navigateToProcess } from '~/store/collection-panel/collection-panel-action';
 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 { openDetailsPanel } from '~/store/details-panel/details-panel-action';
+import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
+import { PropertyChipComponent } from '~/views-components/resource-properties-form/property-chip';
+import { IllegalNamingWarning } from '~/components/warning/warning';
 
-type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'label' | 'value';
+type CssRules = 'card' | 'iconHeader' | 'tag' | 'label' | 'value' | 'link';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     card: {
@@ -38,130 +40,147 @@ 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[];
 }
 
 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
     & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
 
-
 export const CollectionPanel = withStyles(styles)(
     connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
-        const collection = getResource(props.match.params.id)(state.resources);
-        return {
-            item: collection,
-            tags: state.collectionPanel.tags
-        };
+        const item = getResource(props.match.params.id)(state.resources);
+        return { item };
     })(
         class extends React.Component<CollectionPanelProps> {
+
             render() {
-                const { classes, item, tags } = this.props;
-                return <div>
-                    <Card className={classes.card}>
-                        <CardHeader
-                            avatar={<CollectionIcon className={classes.iconHeader} />}
-                            action={
-                                <Tooltip title="More options">
-                                    <IconButton
-                                        aria-label="More options"
-                                        onClick={this.handleContextMenu}>
-                                        <MoreOptionsIcon />
+                const { classes, item, dispatch } = this.props;
+                return item
+                    ? <>
+                        <Card className={classes.card}>
+                            <CardHeader
+                                avatar={
+                                    <IconButton onClick={this.openCollectionDetails}>
+                                        <CollectionIcon className={classes.iconHeader} />
                                     </IconButton>
-                                </Tooltip>
-                            }
-                            title={item && item.name}
-                            subheader={item && item.description} />
-                        <CardContent>
-                            <Grid container direction="column">
-                                <Grid item xs={6}>
-                                    <DetailsAttribute classLabel={classes.label} classValue={classes.value}
-                                        label='Collection UUID'
-                                        value={item && item.uuid}>
-                                        <Tooltip title="Copy uuid">
-                                            <CopyToClipboard text={item && item.uuid} onCopy={() => this.onCopy()}>
-                                                <CopyIcon className={classes.copyIcon} />
-                                            </CopyToClipboard>
-                                        </Tooltip>
-                                    </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} />
+                                }
+                                action={
+                                    <Tooltip title="More options" disableFocusListener>
+                                        <IconButton
+                                            aria-label="More options"
+                                            onClick={this.handleContextMenu}>
+                                            <MoreOptionsIcon />
+                                        </IconButton>
+                                    </Tooltip>
+                                }
+                                title={item && <span><IllegalNamingWarning name={item.name}/>{item.name}</span>}
+                                titleTypographyProps={this.titleProps}
+                                subheader={item && item.description}
+                                subheaderTypographyProps={this.titleProps} />
+                            <CardContent>
+                                <Grid container direction="column">
+                                    <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='Portable data hash'
+                                            linkToUuid={item && item.portableDataHash} />
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Number of files' value={item && item.fileCount} />
+                                        <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                                            label='Content size' value={item && formatFileSize(item.fileSizeTotal)} />
+                                        <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>
-                            </Grid>
-                        </CardContent>
-                    </Card>
+                            </CardContent>
+                        </Card>
 
-                    <Card className={classes.card}>
-                        <CardHeader title="Properties" />
-                        <CardContent>
-                            <Grid container direction="column">
-                                <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)} />;
-                                        })
-                                    }
+                        <Card className={classes.card}>
+                            <CardHeader title="Properties" />
+                            <CardContent>
+                                <Grid container direction="column">
+                                    <Grid item xs={12}>
+                                        <CollectionTagForm />
+                                    </Grid>
+                                    <Grid item xs={12}>
+                                        {Object.keys(item.properties).map(k =>
+                                            <PropertyChipComponent
+                                                key={k} className={classes.tag}
+                                                onDelete={this.handleDelete(k)}
+                                                propKey={k} propValue={item.properties[k]} />
+                                        )}
+                                    </Grid>
                                 </Grid>
-                            </Grid>
-                        </CardContent>
-                    </Card>
-                    <div className={classes.card}>
-                        <CollectionPanelFiles />
-                    </div>
-                </div>;
+                            </CardContent>
+                        </Card>
+                        <div className={classes.card}>
+                            <CollectionPanelFiles />
+                        </div>
+                    </>
+                    : null;
             }
 
             handleContextMenu = (event: React.MouseEvent<any>) => {
-                const { uuid, ownerUuid, name, description, kind } = this.props.item;
+                const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item;
                 const resource = {
                     uuid,
                     ownerUuid,
                     name,
                     description,
                     kind,
-                    menuKind: ContextMenuKind.COLLECTION
+                    menuKind: isTrashed
+                        ? ContextMenuKind.TRASHED_COLLECTION
+                        : ContextMenuKind.COLLECTION
                 };
                 this.props.dispatch<any>(openContextMenu(event, resource));
             }
 
-            handleDelete = (uuid: string) => () => {
-                this.props.dispatch<any>(deleteCollectionTag(uuid));
+            onCopy = (message: string) =>
+                this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
+                    message,
+                    hideDuration: 2000,
+                    kind: SnackbarKind.SUCCESS
+                }))
+
+            handleDelete = (key: string) => () => {
+                this.props.dispatch<any>(deleteCollectionTag(key));
             }
 
-            onCopy = () => {
-                this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
-                    message: "Uuid has been copied",
-                    hideDuration: 2000
-                }));
+            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}`;
-};
