1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import 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, CircularProgress } from '@material-ui/core';
10 import { CustomizeTableIcon } from 'components/icon/icon';
11 import { DownloadIcon } from 'components/icon/icon';
12 import { SearchInput } from '../search-input/search-input';
14 export interface CollectionPanelFilesProps {
15 items: Array<TreeItem<FileTreeData>>;
18 tooManyFiles: boolean;
19 onUploadDataClick: () => void;
20 onSearchChange: (searchValue: string) => void;
21 onItemMenuOpen: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>, isWritable: boolean) => void;
22 onOptionsMenuOpen: (event: React.MouseEvent<HTMLElement>, isWritable: boolean) => void;
23 onSelectionToggle: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
24 onCollapseToggle: (id: string, status: TreeItemStatus) => void;
25 onFileClick: (id: string) => void;
26 loadFilesFunc: () => void;
27 currentItemUuid?: string;
30 export type CssRules = 'root' | 'cardSubheader' | 'nameHeader' | 'fileSizeHeader' | 'uploadIcon' | 'button' | 'centeredLabel' | 'cardHeaderContent' | 'cardHeaderContentTitle';
32 const styles: StyleRulesCallback<CssRules> = theme => ({
34 paddingBottom: theme.spacing.unit,
40 minHeight: 8 * theme.spacing.unit,
44 paddingRight: 2 * theme.spacing.unit,
45 justifyContent: 'space-between',
47 cardHeaderContentTitle: {
48 paddingLeft: theme.spacing.unit,
49 paddingTop: 2 * theme.spacing.unit,
50 paddingRight: 2 * theme.spacing.unit,
59 transform: 'rotate(180deg)'
62 marginRight: -theme.spacing.unit,
71 export const CollectionPanelFilesComponent = ({ onItemMenuOpen, onSearchChange, onOptionsMenuOpen, onUploadDataClick, classes,
72 isWritable, isLoading, tooManyFiles, loadFilesFunc, ...treeProps }: CollectionPanelFilesProps & WithStyles<CssRules>) => {
73 const { useState, useEffect } = React;
74 const [searchValue, setSearchValue] = useState('');
77 onSearchChange(searchValue);
78 }, [onSearchChange, searchValue]);
80 return (<Card data-cy='collection-files-panel' className={classes.root}>
83 <div className={classes.cardHeaderContent}>
84 <span className={classes.cardHeaderContentTitle}>Files</span>
88 onSearch={setSearchValue} />
91 className={classes.cardSubheader}
92 classes={{ action: classes.button }}
96 data-cy='upload-button'
97 onClick={onUploadDataClick}
101 <DownloadIcon className={classes.uploadIcon} />
105 <Tooltip title="More options" disableFocusListener>
107 data-cy='collection-files-panel-options-btn'
108 onClick={(ev) => onOptionsMenuOpen(ev, isWritable)}>
109 <CustomizeTableIcon />
115 ? <div className={classes.centeredLabel}>
116 File listing may take some time, please click to browse: <Button onClick={loadFilesFunc}><DownloadIcon />Show files</Button>
119 <Grid container justify="space-between">
120 <Typography variant="caption" className={classes.nameHeader}>
123 <Typography variant="caption" className={classes.fileSizeHeader}>
128 ? <div className={classes.centeredLabel}><CircularProgress /></div>
129 : <div style={{ height: 'calc(100% - 60px)' }}>
131 onMenuOpen={(ev, item) => onItemMenuOpen(ev, item, isWritable)}
132 {...treeProps} /></div>}
138 export const CollectionPanelFiles = withStyles(styles)(CollectionPanelFilesComponent);