project-tree component
[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 { RootState } from "../../store/root-reducer";
14 import ProjectList from "../../components/project-list/project-list";
15 import { Route, Switch } from "react-router";
16 import { Link } from "react-router-dom";
17
18 import { actions as projectActions } from "../../store/project-action";
19 import ProjectTree from '../../components/project-tree/project-tree';
20 import { TreeItem } from '../../components/tree/tree';
21 import { Project } from '../../models/project';
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 class Workbench extends React.Component<WorkbenchProps & WithStyles<CssRules>> {
60     render() {
61         const { classes } = this.props;
62         return (
63             <div className={classes.root}>
64                 <AppBar position="absolute" className={classes.appBar}>
65                     <Toolbar>
66                         <Typography variant="title" color="inherit" noWrap>
67                             Arvados<br />Workbench 2
68                         </Typography>
69                     </Toolbar>
70                 </AppBar>
71                 <Drawer
72                     variant="permanent"
73                     classes={{
74                         paper: classes.drawerPaper,
75                     }}>
76                     <div className={classes.toolbar} />
77                     <ProjectTree
78                         projects={this.props.projects}
79                         toggleProjectTreeItem={this.props.toggleProjectTreeItem} />
80                 </Drawer>
81                 <main className={classes.content}>
82                     <div className={classes.toolbar} />
83                     <Switch>
84                         <Route exact path="/">
85                             <Typography noWrap>Hello new workbench!</Typography>
86                         </Route>
87                         <Route path="/project/:name" component={ProjectList} />
88                     </Switch>
89                 </main>
90             </div>
91         );
92     }
93 }
94
95 export default connect(
96     (state: RootState) => ({
97         projects: state.projects
98     }), {
99         toggleProjectTreeItem: (id: string) => projectActions.toggleProjectTreeItem(id)
100     }
101 )(
102     withStyles(styles)(Workbench)
103 );