Merge master branch
[arvados-workbench2.git] / src / components / project-tree / project-tree.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { ReactElement } from 'react';
7 import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
8 import ListItemText from "@material-ui/core/ListItemText/ListItemText";
9 import ListItemIcon from '@material-ui/core/ListItemIcon';
10 import Typography from '@material-ui/core/Typography';
11
12 import Tree, { TreeItem } from '../tree/tree';
13 import { Project } from '../../models/project';
14
15 type CssRules = 'active' | 'listItemText' | 'row' | 'treeContainer';
16
17 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
18     active: {
19         color: '#4285F6',
20     },
21     listItemText: {
22         padding: '0px',
23     },
24     row: {
25         display: 'flex',
26         alignItems: 'center',
27         marginLeft: '20px',
28     },
29     treeContainer: {
30         position: 'absolute',
31         overflowX: 'visible',
32         marginTop: '80px',
33         minWidth: '240px',
34         whiteSpace: 'nowrap',
35     }
36 });
37
38 export interface ProjectTreeProps {
39     projects: Array<TreeItem<Project>>;
40     toggleProjectTreeItem: (id: string) => void;
41 }
42
43 class ProjectTree<T> extends React.Component<ProjectTreeProps & WithStyles<CssRules>> {
44     render(): ReactElement<any> {
45         const {classes, projects} = this.props;
46         const {active, listItemText, row, treeContainer} = classes;
47         return (
48             <div className={treeContainer}>
49                 <Tree items={projects}
50                     toggleItem={this.props.toggleProjectTreeItem}
51                     render={(project: TreeItem<Project>, level: number) =>
52                         <span className={row}>
53                             <ListItemIcon className={project.active ? active : ''}>
54                                 {level === 0 ? <i className="fas fa-th"/> : <i className="fas fa-folder"/>}
55                             </ListItemIcon>
56                             <ListItemText className={listItemText} primary={
57                                 <Typography className={project.active ? active : ''}>
58                                     {project.data.name}
59                                 </Typography>
60                             }/>
61                         </span>
62                     }/>
63             </div>
64         );
65     }
66 }
67
68 export default withStyles(styles)(ProjectTree);