Send new user data to server
[arvados-workbench2.git] / src / components / file-tree / file-tree-item.tsx
index 71e37f1f570cc0afc4341ea66af5efd801179bab..89bf43c66d84d3c6f9f157adb3e84812866ddde2 100644 (file)
@@ -4,13 +4,13 @@
 
 import * as React from "react";
 import { TreeItem } from "../tree/tree";
-import { ProjectIcon, MoreOptionsIcon } from "../icon/icon";
-import { Typography, IconButton, StyleRulesCallback, withStyles, WithStyles } from "@material-ui/core";
-import { formatFileSize } from "../../common/formatters";
+import { ProjectIcon, MoreOptionsIcon, DefaultIcon, CollectionIcon } from "../icon/icon";
+import { Typography, IconButton, StyleRulesCallback, withStyles, WithStyles, Tooltip } from '@material-ui/core';
+import { formatFileSize } from "~/common/formatters";
 import { ListItemTextIcon } from "../list-item-text-icon/list-item-text-icon";
 import { FileTreeData } from "./file-tree-data";
 
-type CssRules = "root" | "spacer" | "sizeInfo" | "button";
+type CssRules = "root" | "spacer" | "sizeInfo" | "button" | "moreOptions";
 
 const fileTreeItemStyle: StyleRulesCallback<CssRules> = theme => ({
     root: {
@@ -22,11 +22,15 @@ const fileTreeItemStyle: StyleRulesCallback<CssRules> = theme => ({
         flex: "1"
     },
     sizeInfo: {
-        marginRight: `${theme.spacing.unit * 3}px`
+        width: `${theme.spacing.unit * 8}px`
     },
     button: {
         width: theme.spacing.unit * 3,
-        height: theme.spacing.unit * 3
+        height: theme.spacing.unit * 3,
+        marginRight: theme.spacing.unit,
+    },
+    moreOptions: {
+        position: 'absolute'
     }
 });
 
@@ -40,17 +44,19 @@ export const FileTreeItem = withStyles(fileTreeItemStyle)(
             const { classes, item } = this.props;
             return <div className={classes.root}>
                 <ListItemTextIcon
-                    icon={ProjectIcon}
+                    icon={getIcon(item)}
                     name={item.data.name} />
                 <div className={classes.spacer} />
                 <Typography
                     className={classes.sizeInfo}
                     variant="caption">{formatFileSize(item.data.size)}</Typography>
-                <IconButton
-                    className={classes.button}
-                    onClick={this.handleClick}>
-                    <MoreOptionsIcon />
-                </IconButton>
+                <Tooltip title="More options" disableFocusListener>
+                    <IconButton
+                        className={classes.button}
+                        onClick={this.handleClick}>
+                        <MoreOptionsIcon className={classes.moreOptions}/>
+                    </IconButton>
+                </Tooltip>
             </div >;
         }
 
@@ -59,3 +65,14 @@ export const FileTreeItem = withStyles(fileTreeItemStyle)(
         }
     });
 
+const getIcon = (item: TreeItem<FileTreeData>) => {
+    switch (item.data.type) {
+        case 'directory':
+            return ProjectIcon;
+        case 'file':
+            return CollectionIcon;
+        default:
+            return DefaultIcon;
+    }
+};
+