create tag model and change code
[arvados-workbench2.git] / src / views / collection-panel / collection-panel.tsx
index 99c4e00a1470c440f20a49e7463a772cd99d24a2..271fb8bce22a598fab26b65a610d2346f6494ce4 100644 (file)
@@ -4,21 +4,21 @@
 
 import * as React from 'react';
 import { 
-    StyleRulesCallback, WithStyles, withStyles, Card, CardHeader, IconButton, 
-    CardContent, Grid, MenuItem, Menu, ListItemIcon, ListItemText, Typography 
+    StyleRulesCallback, WithStyles, withStyles, Card, 
+    CardHeader, IconButton, CardContent, Grid, Chip, TextField, Button
 } from '@material-ui/core';
-import { connect } from 'react-redux';
+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, ShareIcon, RenameIcon, AddFavoriteIcon, MoveToIcon, 
-    CopyIcon, ProvenanceGraphIcon, DetailsIcon, AdvancedIcon, RemoveIcon 
-} from '../../components/icon/icon';
+import { MoreOptionsIcon, CollectionIcon, CopyIcon } from '../../components/icon/icon';
 import { DetailsAttribute } from '../../components/details-attribute/details-attribute';
 import { CollectionResource } from '../../models/collection';
+import * as CopyToClipboard from 'react-copy-to-clipboard';
+import { createCollectionTag } from '../../store/collection-panel/collection-panel-action';
+import { TagResource } from '../../models/tag';
 
-type CssRules = 'card' | 'iconHeader';
+type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     card: {
@@ -27,88 +27,41 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     iconHeader: {
         fontSize: '1.875rem',
         color: theme.customs.colors.yellow700
-    }
-});
-
-const MENU_OPTIONS = [
-    {
-        title: 'Edit collection',
-        icon: RenameIcon
-    },
-    {
-        title: 'Share',
-        icon: ShareIcon
-    },
-    {
-        title: 'Move to',
-        icon: MoveToIcon
-    },
-    {
-        title: 'Add to favorites',
-        icon: AddFavoriteIcon
     },
-    {
-        title: 'Copy to project',
-        icon: CopyIcon
+    tag: {
+        marginRight: theme.spacing.unit
     },
-    {
-        title: 'View details',
-        icon: DetailsIcon
-    },
-    {
-        title: 'Provenance graph',
-        icon: ProvenanceGraphIcon
-    },
-    {
-        title: 'Advanced',
-        icon: AdvancedIcon
-    },
-    {
-        title: 'Remove',
-        icon: RemoveIcon
+    copyIcon: {
+        marginLeft: theme.spacing.unit,
+        fontSize: '1.125rem',
+        color: theme.palette.grey["500"],
+        cursor: 'pointer'
     }
-];
+});
 
 interface CollectionPanelDataProps {
     item: CollectionResource;
+    tags: TagResource[];
 }
 
 interface CollectionPanelActionProps {
     onItemRouteChange: (collectionId: string) => void;
+    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
 }
 
-type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps 
+type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps & DispatchProp
                             & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
 
+
 export const CollectionPanel = withStyles(styles)(
-    connect((state: RootState) => ({ item: state.collectionPanel.item }))(
+    connect((state: RootState) => ({ 
+        item: state.collectionPanel.item, 
+        tags: state.collectionPanel.tags 
+    }))(
         class extends React.Component<CollectionPanelProps> { 
 
-            state = {
-                anchorEl: undefined
-            };
-
-            showMenu = (event: any) => {
-                this.setState({ anchorEl: event.currentTarget });
-            }
-
-            closeMenu = () => {
-                this.setState({ anchorEl: undefined });
-            }
-
-            displayMenuAction = () => {
-                return <IconButton
-                    aria-label="More options"
-                    aria-owns={this.state.anchorEl ? 'submenu' : undefined}
-                    aria-haspopup="true"
-                    onClick={this.showMenu}>
-                    <MoreOptionsIcon />
-                </IconButton>;
-            }
-
             render() {
-                const { anchorEl } = this.state;
-                const { classes, item } = this.props;
+                const { classes, item, tags, onContextMenu } = this.props;
                 return <div>
                         <Card className={classes.card}>
                             <CardHeader 
@@ -116,36 +69,21 @@ export const CollectionPanel = withStyles(styles)(
                                 action={ 
                                     <IconButton
                                         aria-label="More options"
-                                        aria-owns={anchorEl ? 'submenu' : undefined}
-                                        aria-haspopup="true"
-                                        onClick={this.showMenu}>
+                                        onClick={event => onContextMenu(event, item)}>
                                         <MoreOptionsIcon />
                                     </IconButton> 
                                 }
-                                title={item && item.name } />
+                                title={item && item.name } 
+                                subheader={item && item.description} />
                             <CardContent>
-                                <Menu
-                                    id="submenu"
-                                    anchorEl={anchorEl}
-                                    open={Boolean(anchorEl)}
-                                    onClose={this.closeMenu}>
-                                    {MENU_OPTIONS.map((option) => (
-                                        <MenuItem key={option.title}>
-                                            <ListItemIcon>
-                                                <option.icon />
-                                            </ListItemIcon>
-                                            <ListItemText inset primary={
-                                                <Typography variant='body1'>
-                                                    {option.title}
-                                                </Typography>
-                                            }/>
-                                        </MenuItem>
-                                    ))}
-                                </Menu>
                                 <Grid container direction="column">
                                     <Grid item xs={6}>
-                                    <DetailsAttribute label='Collection UUID' value={item && item.uuid} />
-                                        <DetailsAttribute label='Content size' value='54 MB' />
+                                    <DetailsAttribute label='Collection UUID' value={item && item.uuid}>
+                                        <CopyToClipboard text={item && item.uuid}>
+                                            <CopyIcon className={classes.copyIcon} />
+                                        </CopyToClipboard>
+                                    </DetailsAttribute>
+                                    <DetailsAttribute label='Content size' value='54 MB' />
                                     <DetailsAttribute label='Owner' value={item && item.ownerUuid} />
                                     </Grid>
                                 </Grid>
@@ -156,8 +94,17 @@ export const CollectionPanel = withStyles(styles)(
                             <CardHeader title="Tags" />
                             <CardContent>
                                 <Grid container direction="column">
-                                    <Grid item xs={4}>
-                                        Tags
+                                    <Grid item xs={12}>
+                                        {/* Temporarty button to add new tag */}
+                                        <Button onClick={this.addTag}>Add Tag</Button>
+                                    </Grid>
+                                    <Grid item xs={12}>
+                                        {
+                                            tags.map(tag => {
+                                                return <Chip key={tag.etag} className={classes.tag}
+                                                    label={renderTagLabel(tag)}  />;
+                                            })
+                                        }
                                     </Grid>
                                 </Grid>
                             </CardContent>
@@ -176,6 +123,11 @@ export const CollectionPanel = withStyles(styles)(
                     </div>;
             }
 
+            // Temporary method to add new tag
+            addTag = () => {
+                this.props.dispatch<any>(createCollectionTag(this.props.item.uuid, { key: 'test', value: 'value for tag'}));
+            }
+
             componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
                 if (!item || match.params.id !== item.uuid) {
                     onItemRouteChange(match.params.id);
@@ -184,4 +136,9 @@ export const CollectionPanel = withStyles(styles)(
 
         }
     )
-);
\ No newline at end of file
+);
+
+const renderTagLabel = (tag: TagResource) => {
+    const { properties } = tag;
+    return `${properties.key}: ${properties.value}`;
+};
\ No newline at end of file