Generic tree issue withStyles
[arvados-workbench2.git] / src / views / workbench / workbench.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
7 import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
8 import Drawer from '@material-ui/core/Drawer';
9 import AppBar from '@material-ui/core/AppBar';
10 import Toolbar from '@material-ui/core/Toolbar';
11 import Typography from '@material-ui/core/Typography';
12 import { connect } from "react-redux";
13 import Tree, { TreeItem } from "../../components/tree/tree";
14 import { Project } from "../../models/project";
15 import { RootState } from "../../store/root-reducer";
16 import ProjectList from "../../components/project-list/project-list";
17 import { Route, Switch } from "react-router";
18 import { Link } from "react-router-dom";
19
20 import { actions as projectActions } from "../../store/project-action";
21 import ListItemText from "@material-ui/core/ListItemText/ListItemText";
22 import ListItemIcon from '@material-ui/core/ListItemIcon';
23
24 const drawerWidth = 240;
25
26 type CssRules = 'root' | 'appBar' | 'active' | 'drawerPaper' | 'content' | 'row' | 'treeContainer' | 'toolbar';
27
28 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
29     root: {
30         flexGrow: 1,
31         zIndex: 1,
32         overflow: 'hidden',
33         position: 'relative',
34         display: 'flex',
35         width: '100%',
36         height: '100%'
37     },
38     appBar: {
39         zIndex: theme.zIndex.drawer + 1,
40         backgroundColor: '#692498'
41     },
42     active: {
43         color: '#4285F6',
44     },
45     drawerPaper: {
46         position: 'relative',
47         width: drawerWidth,
48     },
49     content: {
50         flexGrow: 1,
51         backgroundColor: theme.palette.background.default,
52         padding: theme.spacing.unit * 3,
53         minWidth: 0,
54     },
55     row: {
56         display: 'flex',
57         alignItems: 'center',
58         marginLeft: '20px', 
59     },
60     treeContainer: {
61         position: 'absolute',        
62         overflowX: 'visible',
63         marginTop: '80px',
64         minWidth: drawerWidth,
65         whiteSpace: 'nowrap',
66     },
67     toolbar: theme.mixins.toolbar
68 });
69
70 interface WorkbenchProps {
71     projects: Array<TreeItem<Project>>;
72     toggleProjectTreeItem: (id: string) => any;
73 }
74
75 interface WorkbenchState {
76 }
77
78 class Workbench extends React.Component<WorkbenchProps & WithStyles<CssRules>, WorkbenchState> {
79     render() {
80         const {classes, projects} = this.props;
81         return (
82             <div className={classes.root}>
83                 <AppBar position="absolute" className={classes.appBar}>
84                     <Toolbar>
85                         <Typography variant="title" color="inherit" noWrap>
86                             Arvados<br/>Workbench 2
87                         </Typography>
88                     </Toolbar>
89                 </AppBar>
90                 <Drawer
91                     variant="permanent"
92                     classes={{
93                         paper: classes.drawerPaper,
94                     }}>
95                     <div className={classes.toolbar}/>
96                     <div className={classes.treeContainer}>
97                         <Tree items={projects}
98                             toggleItem={this.props.toggleProjectTreeItem}
99                             render={(project: TreeItem<Project>) => <span className={classes.row}>
100                                 <div><ListItemIcon className={project.active ? classes.active : ''}>{project.data.icon}</ListItemIcon></div>
101                                 <div><ListItemText primary={<Typography className={project.active ? classes.active : ''}>{project.data.name}</Typography>} /></div>
102                             </span>}
103                             />
104                     </div>
105                 </Drawer>
106                 <main className={classes.content}>
107                     <div className={classes.toolbar}/>
108                     <Switch>
109                         <Route exact path="/">
110                             <Typography noWrap>Hello new workbench!</Typography>
111                         </Route>
112                         <Route path="/project/:name" component={ProjectList}/>
113                     </Switch>
114                 </main>
115             </div>
116         );
117     }
118 }
119
120 export default connect(
121     (state: RootState) => ({
122         projects: state.projects
123     }), {
124         toggleProjectTreeItem: (id: string) => projectActions.toggleProjectTreeItem(id)
125     }
126 )(
127     withStyles(styles)(Workbench)
128 );