Add tree structure rendering
[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
23 const drawerWidth = 240;
24
25 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
26
27 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
28     root: {
29         flexGrow: 1,
30         zIndex: 1,
31         overflow: 'hidden',
32         position: 'relative',
33         display: 'flex',
34         width: '100%',
35         height: '100%'
36     },
37     appBar: {
38         zIndex: theme.zIndex.drawer + 1,
39         backgroundColor: '#692498'
40     },
41     drawerPaper: {
42         position: 'relative',
43         width: drawerWidth,
44     },
45     content: {
46         flexGrow: 1,
47         backgroundColor: theme.palette.background.default,
48         padding: theme.spacing.unit * 3,
49         minWidth: 0,
50     },
51     toolbar: theme.mixins.toolbar
52 });
53
54 interface WorkbenchProps {
55     projects: Array<TreeItem<Project>>;
56     toggleProjectTreeItem: (id: string) => any;
57 }
58
59 interface WorkbenchState {
60 }
61
62 class Workbench extends React.Component<WorkbenchProps & WithStyles<CssRules>, WorkbenchState> {
63     render() {
64         const {classes} = this.props;
65         return (
66             <div className={classes.root}>
67                 <AppBar position="absolute" className={classes.appBar}>
68                     <Toolbar>
69                         <Typography variant="title" color="inherit" noWrap>
70                             Arvados<br/>Workbench 2
71                         </Typography>
72                     </Toolbar>
73                 </AppBar>
74                 <Drawer
75                     variant="permanent"
76                     classes={{
77                         paper: classes.drawerPaper,
78                     }}>
79                     <div className={classes.toolbar}/>
80                     <Tree items={this.props.projects}
81                         toggleItem={this.props.toggleProjectTreeItem}
82                         render={(p: Project) => <ListItemText primary={p.name}/>}
83                         />
84                 </Drawer>
85                 <main className={classes.content}>
86                     <div className={classes.toolbar}/>
87                     <Switch>
88                         <Route exact path="/">
89                             <Typography noWrap>Hello new workbench!</Typography>
90                         </Route>
91                         <Route path="/project/:name" component={ProjectList}/>
92                     </Switch>
93                 </main>
94             </div>
95         );
96     }
97 }
98
99 export default connect(
100     (state: RootState) => ({
101         projects: state.projects
102     }), {
103         toggleProjectTreeItem: (id: string) => projectActions.toggleProjectTreeItem(id)
104     }
105 )(
106     withStyles(styles)(Workbench)
107 );