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