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";
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
34 export interface FileTreeItemProps {
35 item: TreeItem<FileTreeData>;
36 onMoreClick: (event: React.MouseEvent<any>, item: TreeItem<FileTreeData>) => void;
38 export const FileTreeItem = withStyles(fileTreeItemStyle)(
39 class extends React.Component<FileTreeItemProps & WithStyles<CssRules>> {
41 const { classes, item } = this.props;
42 return <div className={classes.root}>
45 name={item.data.name} />
46 <div className={classes.spacer} />
48 className={classes.sizeInfo}
49 variant="caption">{formatFileSize(item.data.size)}</Typography>
51 className={classes.button}
52 onClick={this.handleClick}>
53 <Tooltip title="More options">
60 handleClick = (event: React.MouseEvent<any>) => {
61 this.props.onMoreClick(event, this.props.item);
65 const getIcon = (item: TreeItem<FileTreeData>) => {
66 switch (item.data.type) {
70 return CollectionIcon;