Move collection-panel-files to collection-panel
[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
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 import { CollectionPanelFiles } from '../../views-components/collection-panel-files/collection-panel-files';
18
19 type CssRules = 'card' | 'iconHeader';
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 });
30
31 interface CollectionPanelDataProps {
32     item: CollectionResource;
33 }
34
35 interface CollectionPanelActionProps {
36     onItemRouteChange: (collectionId: string) => void;
37     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
38 }
39
40 type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps 
41                             & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
42
43 export const CollectionPanel = withStyles(styles)(
44     connect((state: RootState) => ({ item: state.collectionPanel.item }))(
45         class extends React.Component<CollectionPanelProps> { 
46
47             render() {
48                 const { classes, item, onContextMenu } = this.props;
49                 return <div>
50                         <Card className={classes.card}>
51                             <CardHeader 
52                                 avatar={ <CollectionIcon className={classes.iconHeader} /> }
53                                 action={ 
54                                     <IconButton
55                                         aria-label="More options"
56                                         onClick={event => onContextMenu(event, item)}>
57                                         <MoreOptionsIcon />
58                                     </IconButton> 
59                                 }
60                                 title={item && item.name } />
61                             <CardContent>
62                                 <Grid container direction="column">
63                                     <Grid item xs={6}>
64                                     <DetailsAttribute label='Collection UUID' value={item && item.uuid} />
65                                         <DetailsAttribute label='Content size' value='54 MB' />
66                                     <DetailsAttribute label='Owner' value={item && item.ownerUuid} />
67                                     </Grid>
68                                 </Grid>
69                             </CardContent>
70                         </Card>
71
72                         <Card className={classes.card}>
73                             <CardHeader title="Tags" />
74                             <CardContent>
75                                 <Grid container direction="column">
76                                     <Grid item xs={4}>
77                                         Tags
78                                     </Grid>
79                                 </Grid>
80                             </CardContent>
81                         </Card>
82                         <div className={classes.card}>
83                             <CollectionPanelFiles/>
84                         </div>
85                     </div>;
86             }
87
88             componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
89                 if (!item || match.params.id !== item.uuid) {
90                     onItemRouteChange(match.params.id);
91                 }
92             }
93
94         }
95     )
96 );