Added icons to 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' | '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     },
55     toolbar: theme.mixins.toolbar
56 });
57
58 interface WorkbenchProps {
59     projects: Array<TreeItem<Project>>;
60     toggleProjectTreeItem: (id: string) => any;
61 }
62
63 interface WorkbenchState {
64 }
65
66 class Workbench extends React.Component<WorkbenchProps & WithStyles<CssRules>, WorkbenchState> {
67     render() {
68         const {classes, projects} = this.props;
69         return (
70             <div className={classes.root}>
71                 <AppBar position="absolute" className={classes.appBar}>
72                     <Toolbar>
73                         <Typography variant="title" color="inherit" noWrap>
74                             Arvados<br/>Workbench 2
75                         </Typography>
76                     </Toolbar>
77                 </AppBar>
78                 <Drawer
79                     variant="permanent"
80                     classes={{
81                         paper: classes.drawerPaper,
82                     }}>
83                     <div className={classes.toolbar}/>
84                     <Tree items={projects}
85                         toggleItem={this.props.toggleProjectTreeItem}
86                         render={(p: Project) => <span className={classes.row}>
87                             <div style={{marginTop: "3px"}}><ListItemIcon>{p.icon}</ListItemIcon></div>
88                             <div><ListItemText primary={p.name}/></div>
89                         </span>}
90                         />
91                 </Drawer>
92                 <main className={classes.content}>
93                     <div className={classes.toolbar}/>
94                     <Switch>
95                         <Route exact path="/">
96                             <Typography noWrap>Hello new workbench!</Typography>
97                         </Route>
98                         <Route path="/project/:name" component={ProjectList}/>
99                     </Switch>
100                 </main>
101             </div>
102         );
103     }
104 }
105
106 export default connect(
107     (state: RootState) => ({
108         projects: state.projects
109     }), {
110         toggleProjectTreeItem: (id: string) => projectActions.toggleProjectTreeItem(id)
111     }
112 )(
113     withStyles(styles)(Workbench)
114 );