Merge branch '14258-collection-filtering'
[arvados.git] / src / components / collection-panel-files / collection-panel-files.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 { TreeItem, TreeItemStatus } from '../tree/tree';
7 import { FileTreeData } from '../file-tree/file-tree-data';
8 import { FileTree } from '../file-tree/file-tree';
9 import { IconButton, Grid, Typography, StyleRulesCallback, withStyles, WithStyles, CardHeader, Card, Button, Tooltip } from '@material-ui/core';
10 import { CustomizeTableIcon } from '../icon/icon';
11 import { DownloadIcon } from '~/components/icon/icon';
12
13 export interface CollectionPanelFilesProps {
14     items: Array<TreeItem<FileTreeData>>;
15     onUploadDataClick: () => void;
16     onItemMenuOpen: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
17     onOptionsMenuOpen: (event: React.MouseEvent<HTMLElement>) => void;
18     onSelectionToggle: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
19     onCollapseToggle: (id: string, status: TreeItemStatus) => void;
20 }
21
22 type CssRules = 'root' | 'cardSubheader' | 'nameHeader' | 'fileSizeHeader' | 'uploadIcon' | 'button';
23
24 const styles: StyleRulesCallback<CssRules> = theme => ({
25     root: {
26         paddingBottom: theme.spacing.unit
27     },
28     cardSubheader: {
29         paddingTop: 0,
30         paddingBottom: 0
31     },
32     nameHeader: {
33         marginLeft: '75px'
34     },
35     fileSizeHeader: {
36         marginRight: '65px'
37     },
38     uploadIcon: {
39         transform: 'rotate(180deg)'
40     },
41     button: {
42         marginRight: -theme.spacing.unit,
43         marginTop: '0px'
44     }
45 });
46
47 export const CollectionPanelFiles =
48     withStyles(styles)(
49         ({ onItemMenuOpen, onOptionsMenuOpen, onUploadDataClick, classes, ...treeProps }: CollectionPanelFilesProps & WithStyles<CssRules>) =>
50             <Card className={classes.root}>
51                 <CardHeader
52                     title="Files"
53                     classes={{ action: classes.button }}
54                     action={
55                         <Button onClick={onUploadDataClick}
56                             variant='raised'
57                             color='primary'
58                             size='small'>
59                             <DownloadIcon className={classes.uploadIcon} />
60                             Upload data
61                     </Button>
62                     } />
63                 <CardHeader
64                     className={classes.cardSubheader}
65                     action={
66                         <Tooltip title="More options" disableFocusListener>
67                             <IconButton onClick={onOptionsMenuOpen}>
68                                 <CustomizeTableIcon />
69                             </IconButton>
70                         </Tooltip>
71                     } />
72                 <Grid container justify="space-between">
73                     <Typography variant="caption" className={classes.nameHeader}>
74                         Name
75                     </Typography>
76                     <Typography variant="caption" className={classes.fileSizeHeader}>
77                         File size
78                     </Typography>
79                 </Grid>
80                 <FileTree onMenuOpen={onItemMenuOpen} {...treeProps} />
81             </Card>);