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