Added scrollability, styles for tree
[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' | '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     drawerPaper: {
43         position: 'relative',
44         width: drawerWidth,
45     },
46     content: {
47         flexGrow: 1,
48         backgroundColor: theme.palette.background.default,
49         padding: theme.spacing.unit * 3,
50         minWidth: 0,
51     },
52     row: {
53         display: 'flex',
54         alignItems: 'center'
55     },
56     treeContainer: {
57         position: 'absolute',        
58         overflowX: 'visible',
59         marginTop: '80px',
60         minWidth: drawerWidth,
61         whiteSpace: 'nowrap'
62     },
63     toolbar: theme.mixins.toolbar
64 });
65
66 interface WorkbenchProps {
67     projects: Array<TreeItem<Project>>;
68     toggleProjectTreeItem: (id: string) => any;
69 }
70
71 interface WorkbenchState {
72 }
73
74 class Workbench extends React.Component<WorkbenchProps & WithStyles<CssRules>, WorkbenchState> {
75     render() {
76         const {classes, projects} = this.props;
77         return (
78             <div className={classes.root}>
79                 <AppBar position="absolute" className={classes.appBar}>
80                     <Toolbar>
81                         <Typography variant="title" color="inherit" noWrap>
82                             Arvados<br/>Workbench 2
83                         </Typography>
84                     </Toolbar>
85                 </AppBar>
86                 <Drawer
87                     variant="permanent"
88                     classes={{
89                         paper: classes.drawerPaper,
90                     }}>
91                     <div className={classes.toolbar}/>
92                     <div className={classes.treeContainer}>
93                         <Tree items={projects}
94                             toggleItem={this.props.toggleProjectTreeItem}
95                             render={(p: Project) => <span className={classes.row}>
96                                 <div><ListItemIcon>{p.icon}</ListItemIcon></div>
97                                 <div><ListItemText primary={p.name}/></div>
98                             </span>}
99                             />
100                     </div>
101                 </Drawer>
102                 <main className={classes.content}>
103                     <div className={classes.toolbar}/>
104                     <Switch>
105                         <Route exact path="/">
106                             <Typography noWrap>Hello new workbench!</Typography>
107                         </Route>
108                         <Route path="/project/:name" component={ProjectList}/>
109                     </Switch>
110                 </main>
111             </div>
112         );
113     }
114 }
115
116 export default connect(
117     (state: RootState) => ({
118         projects: state.projects
119     }), {
120         toggleProjectTreeItem: (id: string) => projectActions.toggleProjectTreeItem(id)
121     }
122 )(
123     withStyles(styles)(Workbench)
124 );