X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f14b66751cfaf92a2bc28331d8878789d4040e8f..2f39812f57c2acbc20a6292964b0a6b3512a9870:/src/views-components/project-tree/project-tree.tsx?ds=sidebyside

diff --git a/src/views-components/project-tree/project-tree.tsx b/src/views-components/project-tree/project-tree.tsx
index d94d3bff..fe808af5 100644
--- a/src/views-components/project-tree/project-tree.tsx
+++ b/src/views-components/project-tree/project-tree.tsx
@@ -4,65 +4,48 @@
 
 import * as React from 'react';
 import { ReactElement } from 'react';
-import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
-import ListItemText from "@material-ui/core/ListItemText/ListItemText";
-import ListItemIcon from '@material-ui/core/ListItemIcon';
-import Typography from '@material-ui/core/Typography';
+import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
+import { Tree, TreeItem, TreeItemStatus } from '~/components/tree/tree';
+import { ProjectResource } from '~/models/project';
+import { ProjectIcon } from '~/components/icon/icon';
+import { ArvadosTheme } from '~/common/custom-theme';
+import { ListItemTextIcon } from '~/components/list-item-text-icon/list-item-text-icon';
 
-import Tree, { TreeItem, TreeItemStatus } from '../../components/tree/tree';
-import { Project } from '../../models/project';
+type CssRules = 'root';
 
-export interface ProjectTreeProps {
-    projects: Array<TreeItem<Project>>;
-    toggleOpen: (id: string, status: TreeItemStatus) => void;
-    toggleActive: (id: string, status: TreeItemStatus) => void;
-    handleCreationDialogOpen: () => void;
-    handleCreationDialogClose: () => void;
-}
-
-class ProjectTree<T> extends React.Component<ProjectTreeProps & WithStyles<CssRules>> {
-    render(): ReactElement<any> {
-        const { classes, projects, toggleOpen, toggleActive } = this.props;
-        const { active, listItemText, row, treeContainer } = classes;
-        return (
-            <div className={treeContainer}>
-                <Tree items={projects}
-                    toggleItemOpen={toggleOpen}
-                    toggleItemActive={toggleActive}
-                    render={(project: TreeItem<Project>) =>
-                        <span className={row}>
-                            <ListItemIcon className={project.active ? active : ''}>
-                                <i className="fas fa-folder" />
-                            </ListItemIcon>
-                            <ListItemText className={listItemText} primary={
-                                <Typography className={project.active ? active : ''}>{project.data.name}</Typography>
-                            } />
-                        </span>
-                    } />
-            </div>
-        );
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    root: {
+        marginLeft: `${theme.spacing.unit * 1.5}px`,
     }
-}
+});
 
-type CssRules = 'active' | 'listItemText' | 'row' | 'treeContainer';
+export interface ProjectTreeProps<T> {
+    projects: Array<TreeItem<ProjectResource>>;
+    toggleOpen: (event: React.MouseEvent<HTMLElement>, item: TreeItem<T>) => void;
+    toggleActive: (event: React.MouseEvent<HTMLElement>, item: TreeItem<T>) => void;
+    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: TreeItem<ProjectResource>) => void;
+}
 
-const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
-    active: {
-        color: '#4285F6',
-    },
-    listItemText: {
-        padding: '0px',
-    },
-    row: {
-        display: 'flex',
-        alignItems: 'center',
-        marginLeft: '20px',
-    },
-    treeContainer: {
-        minWidth: '240px',
-        whiteSpace: 'nowrap',
-        marginLeft: '13px',
+export const ProjectTree = withStyles(styles)(
+    class ProjectTreeGeneric<T> extends React.Component<ProjectTreeProps<T> & WithStyles<CssRules>> {
+        render(): ReactElement<any> {
+            const { classes, projects, toggleOpen, toggleActive, onContextMenu } = this.props;
+            return (
+                <div className={classes.root}>
+                    <Tree items={projects}
+                        onContextMenu={onContextMenu}
+                        toggleItemOpen={toggleOpen}
+                        toggleItemActive={toggleActive}
+                        render={
+                            (project: TreeItem<ProjectResource>) =>
+                                <ListItemTextIcon
+                                    icon={ProjectIcon}
+                                    name={project.data.name}
+                                    isActive={project.active}
+                                    hasMargin={true} />
+                        } />
+                </div>
+            );
+        }
     }
-});
-
-export default withStyles(styles)(ProjectTree);
+);
