change chip styles
[arvados-workbench2.git] / src / views / collection-panel / collection-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { 
7     StyleRulesCallback, WithStyles, withStyles, Card, 
8     CardHeader, IconButton, CardContent, Grid, Chip, TextField, Button
9 } from '@material-ui/core';
10 import { connect, DispatchProp } from "react-redux";
11 import { RouteComponentProps } from 'react-router';
12 import { ArvadosTheme } from '../../common/custom-theme';
13 import { RootState } from '../../store/store';
14 import { MoreOptionsIcon, CollectionIcon, CopyIcon } from '../../components/icon/icon';
15 import { DetailsAttribute } from '../../components/details-attribute/details-attribute';
16 import { CollectionResource } from '../../models/collection';
17 import * as CopyToClipboard from 'react-copy-to-clipboard';
18 import { TagResource } from '../../models/tag';
19 import { CollectionTagForm } from './collection-tag-form';
20 import { deleteCollectionTag } from '../../store/collection-panel/collection-panel-action';
21
22 type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon' | 'value';
23
24 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
25     card: {
26         marginBottom: theme.spacing.unit * 2
27     },
28     iconHeader: {
29         fontSize: '1.875rem',
30         color: theme.customs.colors.yellow700
31     },
32     tag: {
33         marginRight: theme.spacing.unit,
34         marginBottom: theme.spacing.unit
35     },
36     copyIcon: {
37         marginLeft: theme.spacing.unit,
38         fontSize: '1.125rem',
39         color: theme.palette.grey["500"],
40         cursor: 'pointer'
41     },
42     value: {
43         textTransform: 'none'
44     }
45 });
46
47 interface CollectionPanelDataProps {
48     item: CollectionResource;
49     tags: TagResource[];
50 }
51
52 interface CollectionPanelActionProps {
53     onItemRouteChange: (collectionId: string) => void;
54     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
55 }
56
57 type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps & DispatchProp
58                             & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
59
60
61 export const CollectionPanel = withStyles(styles)(
62     connect((state: RootState) => ({ 
63         item: state.collectionPanel.item, 
64         tags: state.collectionPanel.tags 
65     }))(
66         class extends React.Component<CollectionPanelProps> { 
67
68             render() {
69                 const { classes, item, tags, onContextMenu } = this.props;
70                 return <div>
71                         <Card className={classes.card}>
72                             <CardHeader 
73                                 avatar={ <CollectionIcon className={classes.iconHeader} /> }
74                                 action={ 
75                                     <IconButton
76                                         aria-label="More options"
77                                         onClick={event => onContextMenu(event, item)}>
78                                         <MoreOptionsIcon />
79                                     </IconButton> 
80                                 }
81                                 title={item && item.name } 
82                                 subheader={item && item.description} />
83                             <CardContent>
84                                 <Grid container direction="column">
85                                     <Grid item xs={6}>
86                                     <DetailsAttribute classValue={classes.value} 
87                                             label='Collection UUID' 
88                                             value={item && item.uuid}>
89                                         <CopyToClipboard text={item && item.uuid}>
90                                             <CopyIcon className={classes.copyIcon} />
91                                         </CopyToClipboard>
92                                     </DetailsAttribute>
93                                     <DetailsAttribute label='Number of files' value='14' />
94                                     <DetailsAttribute label='Content size' value='54 MB' />
95                                     <DetailsAttribute classValue={classes.value} label='Owner' value={item && item.ownerUuid} />
96                                     </Grid>
97                                 </Grid>
98                             </CardContent>
99                         </Card>
100
101                         <Card className={classes.card}>
102                             <CardHeader title="Tags" />
103                             <CardContent>
104                                 <Grid container direction="column">
105                                     <Grid item xs={12}><CollectionTagForm /></Grid>
106                                     <Grid item xs={12}>
107                                         {
108                                             tags.map(tag => {
109                                                 return <Chip key={tag.etag} className={classes.tag}
110                                                     onDelete={this.handleDelete(tag.uuid)}
111                                                     label={renderTagLabel(tag)}  />;
112                                             })
113                                         }
114                                     </Grid>
115                                 </Grid>
116                             </CardContent>
117                         </Card>
118
119                         <Card className={classes.card}>
120                             <CardHeader title="Files" />
121                             <CardContent>
122                                 <Grid container direction="column">
123                                     <Grid item xs={4}>
124                                         Files
125                                     </Grid>
126                                 </Grid>
127                             </CardContent>
128                         </Card>
129                     </div>;
130             }
131
132             handleDelete = (uuid: string) => () => {
133                 this.props.dispatch<any>(deleteCollectionTag(uuid));
134             }
135
136             componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
137                 if (!item || match.params.id !== item.uuid) {
138                     onItemRouteChange(match.params.id);
139                 }
140             }
141
142         }
143     )
144 );
145
146 const renderTagLabel = (tag: TagResource) => {
147     const { properties } = tag;
148     return `${properties.key}: ${properties.value}`;
149 };