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