Merge branch '14013-upload-collection-files-using-webdav' into 14014-create-collectio...
[arvados-workbench2.git] / src / views / collection-panel / collection-panel.tsx
index 32961905ccfc8b8bd93254da1650ffa7073a27db..374cb95159483f5d4896fcbd539fddfc61931ea3 100644 (file)
@@ -3,45 +3,51 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { 
-    StyleRulesCallback, WithStyles, withStyles, Card, 
-    CardHeader, IconButton, CardContent, Grid, Chip, TextField, Button
+import {
+    StyleRulesCallback, WithStyles, withStyles, Card,
+    CardHeader, IconButton, CardContent, Grid, Chip
 } 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 { DetailsAttribute } from '../../components/details-attribute/details-attribute';
-import { CollectionResource } from '../../models/collection';
+import { ArvadosTheme } from '~/common/custom-theme';
+import { RootState } from '~/store/store';
+import { MoreOptionsIcon, CollectionIcon, CopyIcon } 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 { createCollectionTag } from '../../store/collection-panel/collection-panel-action';
-import { LinkResource } from '../../models/link';
+import { TagResource } from '~/models/tag';
+import { CollectionTagForm } from './collection-tag-form';
+import { deleteCollectionTag } from '~/store/collection-panel/collection-panel-action';
 
-type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon';
+type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'value';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     card: {
-        marginBottom: '20px'
+        marginBottom: theme.spacing.unit * 2
     },
     iconHeader: {
         fontSize: '1.875rem',
         color: theme.customs.colors.yellow700
     },
     tag: {
-        marginRight: theme.spacing.unit
+        marginRight: theme.spacing.unit,
+        marginBottom: theme.spacing.unit
     },
     copyIcon: {
         marginLeft: theme.spacing.unit,
         fontSize: '1.125rem',
         color: theme.palette.grey["500"],
         cursor: 'pointer'
+    },
+    value: {
+        textTransform: 'none'
     }
 });
 
 interface CollectionPanelDataProps {
     item: CollectionResource;
-    tags: LinkResource[];
+    tags: TagResource[];
 }
 
 interface CollectionPanelActionProps {
@@ -54,54 +60,55 @@ type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProp
 
 
 export const CollectionPanel = withStyles(styles)(
-    connect((state: RootState) => ({ 
-        item: state.collectionPanel.item, 
-        tags: state.collectionPanel.tags 
+    connect((state: RootState) => ({
+        item: state.collectionPanel.item,
+        tags: state.collectionPanel.tags
     }))(
-        class extends React.Component<CollectionPanelProps> { 
+        class extends React.Component<CollectionPanelProps> {
 
             render() {
                 const { classes, item, tags, onContextMenu } = this.props;
                 return <div>
                         <Card className={classes.card}>
-                            <CardHeader 
+                            <CardHeader
                                 avatar={ <CollectionIcon className={classes.iconHeader} /> }
-                                action={ 
+                                action={
                                     <IconButton
                                         aria-label="More options"
                                         onClick={event => onContextMenu(event, item)}>
                                         <MoreOptionsIcon />
-                                    </IconButton> 
+                                    </IconButton>
                                 }
-                                title={item && item.name } 
+                                title={item && item.name }
                                 subheader={item && item.description} />
                             <CardContent>
                                 <Grid container direction="column">
                                     <Grid item xs={6}>
-                                    <DetailsAttribute label='Collection UUID' value={item && item.uuid}>
+                                    <DetailsAttribute classValue={classes.value}
+                                            label='Collection UUID'
+                                            value={item && item.uuid}>
                                         <CopyToClipboard text={item && item.uuid}>
                                             <CopyIcon className={classes.copyIcon} />
                                         </CopyToClipboard>
                                     </DetailsAttribute>
+                                    <DetailsAttribute label='Number of files' value='14' />
                                     <DetailsAttribute label='Content size' value='54 MB' />
-                                    <DetailsAttribute label='Owner' value={item && item.ownerUuid} />
+                                    <DetailsAttribute classValue={classes.value} label='Owner' value={item && item.ownerUuid} />
                                     </Grid>
                                 </Grid>
                             </CardContent>
                         </Card>
 
                         <Card className={classes.card}>
-                            <CardHeader title="Tags" />
+                            <CardHeader title="Properties" />
                             <CardContent>
                                 <Grid container direction="column">
-                                    <Grid item xs={12}>
-                                        {/* Temporarty button to add new tag */}
-                                        <Button onClick={this.addTag}>Add Tag</Button>
-                                    </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)}  />;
                                             })
                                         }
@@ -109,23 +116,14 @@ export const CollectionPanel = withStyles(styles)(
                                 </Grid>
                             </CardContent>
                         </Card>
-
-                        <Card className={classes.card}>
-                            <CardHeader title="Files" />
-                            <CardContent>
-                                <Grid container direction="column">
-                                    <Grid item xs={4}>
-                                        Tags
-                                    </Grid>
-                                </Grid>
-                            </CardContent>
-                        </Card>
+                        <div className={classes.card}>
+                            <CollectionPanelFiles/>
+                        </div>
                     </div>;
             }
 
-            // Temporary method to add new tag
-            addTag = () => {
-                this.props.dispatch<any>(createCollectionTag(this.props.item.uuid, 'dodalem nowy'));
+            handleDelete = (uuid: string) => () => {
+                this.props.dispatch<any>(deleteCollectionTag(uuid));
             }
 
             componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
@@ -138,7 +136,7 @@ export const CollectionPanel = withStyles(styles)(
     )
 );
 
-const renderTagLabel = (tag: LinkResource) => {
+const renderTagLabel = (tag: TagResource) => {
     const { properties } = tag;
     return `${properties.key}: ${properties.value}`;
-};
\ No newline at end of file
+};