init collection edit dialog, add reducers, modify store, refactor code
[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 } 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                             <CardContent>
64                                 <Grid container direction="column">
65                                     <Grid item xs={6}>
66                                     <DetailsAttribute label='Collection UUID' value={item && item.uuid}>
67                                         Here I will add copy
68                                     </DetailsAttribute>
69                                     <DetailsAttribute label='Content size' value='54 MB' />
70                                     <DetailsAttribute label='Owner' value={item && item.ownerUuid} />
71                                     </Grid>
72                                 </Grid>
73                             </CardContent>
74                         </Card>
75
76                         <Card className={classes.card}>
77                             <CardHeader title="Tags" />
78                             <CardContent>
79                                 <Grid container direction="column">
80                                     <Grid item xs={4}>
81                                         <Chip label="Tag 1" className={classes.tag}/>
82                                         <Chip label="Tag 2" className={classes.tag}/>
83                                         <Chip label="Tag 3" className={classes.tag}/>
84                                     </Grid>
85                                 </Grid>
86                             </CardContent>
87                         </Card>
88
89                         <Card className={classes.card}>
90                             <CardHeader title="Files" />
91                             <CardContent>
92                                 <Grid container direction="column">
93                                     <Grid item xs={4}>
94                                         Tags
95                                     </Grid>
96                                 </Grid>
97                             </CardContent>
98                         </Card>
99                     </div>;
100             }
101
102             componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
103                 if (!item || match.params.id !== item.uuid) {
104                     onItemRouteChange(match.params.id);
105                 }
106             }
107
108         }
109     )
110 );