1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { TreeItem } from "../tree/tree";
7 import { ProjectIcon, MoreOptionsIcon, DefaultIcon, CollectionIcon } from "../icon/icon";
8 import { Typography, IconButton, StyleRulesCallback, withStyles, WithStyles, Tooltip } from '@material-ui/core';
9 import { formatFileSize } from "~/common/formatters";
10 import { ListItemTextIcon } from "../list-item-text-icon/list-item-text-icon";
11 import { FileTreeData } from "./file-tree-data";
13 type CssRules = "root" | "spacer" | "sizeInfo" | "button" | "moreOptions";
15 const fileTreeItemStyle: StyleRulesCallback<CssRules> = theme => ({
19 paddingRight: `${theme.spacing.unit * 1.5}px`
25 width: `${theme.spacing.unit * 8}px`
28 width: theme.spacing.unit * 3,
29 height: theme.spacing.unit * 3,
30 marginRight: theme.spacing.unit,
37 export interface FileTreeItemProps {
38 item: TreeItem<FileTreeData>;
39 onMoreClick: (event: React.MouseEvent<any>, item: TreeItem<FileTreeData>) => void;
41 export const FileTreeItem = withStyles(fileTreeItemStyle)(
42 class extends React.Component<FileTreeItemProps & WithStyles<CssRules>> {
44 const { classes, item } = this.props;
46 <div className={classes.root}>
48 icon={getIcon(item.data.type)}
49 name={item.data.name} />
50 <div className={classes.spacer} />
52 className={classes.sizeInfo}
53 variant="caption">{formatFileSize(item.data.size)}</Typography>
54 <Tooltip title="More options" disableFocusListener>
56 className={classes.button}
57 onClick={this.handleClick}>
58 <MoreOptionsIcon className={classes.moreOptions} />
65 handleClick = (event: React.MouseEvent<any>) => {
66 this.props.onMoreClick(event, this.props.item);
70 export const getIcon = (type: string) => {
75 return CollectionIcon;