add copy to clipboard
[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
9 } from '@material-ui/core';
10 import { connect } 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
19 type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon';
20
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22     card: {
23         marginBottom: '20px'
24     },
25     iconHeader: {
26         fontSize: '1.875rem',
27         color: theme.customs.colors.yellow700
28     },
29     tag: {
30         marginRight: theme.spacing.unit
31     },
32     copyIcon: {
33         marginLeft: theme.spacing.unit,
34         fontSize: '1.125rem',
35         cursor: 'pointer'
36     }
37 });
38
39 interface CollectionPanelDataProps {
40     item: CollectionResource;
41 }
42
43 interface CollectionPanelActionProps {
44     onItemRouteChange: (collectionId: string) => void;
45     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
46 }
47
48 type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps 
49                             & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
50
51
52 export const CollectionPanel = withStyles(styles)(
53     connect((state: RootState) => ({ item: state.collectionPanel.item }))(
54         class extends React.Component<CollectionPanelProps> { 
55
56             render() {
57                 const { classes, item, onContextMenu } = this.props;
58                 return <div>
59                         <Card className={classes.card}>
60                             <CardHeader 
61                                 avatar={ <CollectionIcon className={classes.iconHeader} /> }
62                                 action={ 
63                                     <IconButton
64                                         aria-label="More options"
65                                         onClick={event => onContextMenu(event, item)}>
66                                         <MoreOptionsIcon />
67                                     </IconButton> 
68                                 }
69                                 title={item && item.name } 
70                                 subheader={item && item.description} />
71                             <CardContent>
72                                 <Grid container direction="column">
73                                     <Grid item xs={6}>
74                                     <DetailsAttribute label='Collection UUID' value={item && item.uuid}>
75                                         <CopyToClipboard text={item && item.uuid}>
76                                             <CopyIcon className={classes.copyIcon} />
77                                         </CopyToClipboard>
78                                     </DetailsAttribute>
79                                     <DetailsAttribute label='Content size' value='54 MB' />
80                                     <DetailsAttribute label='Owner' value={item && item.ownerUuid} />
81                                     </Grid>
82                                 </Grid>
83                             </CardContent>
84                         </Card>
85
86                         <Card className={classes.card}>
87                             <CardHeader title="Tags" />
88                             <CardContent>
89                                 <Grid container direction="column">
90                                     <Grid item xs={4}>
91                                         <Chip label="Tag 1" className={classes.tag}/>
92                                         <Chip label="Tag 2" className={classes.tag}/>
93                                         <Chip label="Tag 3" className={classes.tag}/>
94                                     </Grid>
95                                 </Grid>
96                             </CardContent>
97                         </Card>
98
99                         <Card className={classes.card}>
100                             <CardHeader title="Files" />
101                             <CardContent>
102                                 <Grid container direction="column">
103                                     <Grid item xs={4}>
104                                         Tags
105                                     </Grid>
106                                 </Grid>
107                             </CardContent>
108                         </Card>
109                     </div>;
110             }
111
112             componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
113                 if (!item || match.params.id !== item.uuid) {
114                     onItemRouteChange(match.params.id);
115                 }
116             }
117
118         }
119     )
120 );