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