1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
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, DispatchProp } from "react-redux";
13 import Tree 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 import Button from "@material-ui/core/Button/Button";
20 import authActions from "../../store/auth-action";
21 import IconButton from "@material-ui/core/IconButton/IconButton";
22 import Menu from "@material-ui/core/Menu/Menu";
23 import MenuItem from "@material-ui/core/MenuItem/MenuItem";
24 import { AccountCircle } from "@material-ui/icons";
25 import { User } from "../../models/user";
27 const drawerWidth = 240;
29 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
31 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
42 zIndex: theme.zIndex.drawer + 1,
43 backgroundColor: '#692498'
51 backgroundColor: theme.palette.background.default,
52 padding: theme.spacing.unit * 3,
56 toolbar: theme.mixins.toolbar
59 interface WorkbenchDataProps {
64 interface WorkbenchActionProps {
67 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
69 interface WorkbenchState {
73 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
74 constructor(props: WorkbenchProps) {
82 this.props.dispatch(authActions.LOGIN());
87 this.props.dispatch(authActions.LOGOUT());
90 handleOpenMenu = (event: React.MouseEvent<any>) => {
92 anchorEl: event.currentTarget
103 const {classes, user} = this.props;
105 <div className={classes.root}>
106 <AppBar position="absolute" className={classes.appBar}>
108 <Typography variant="title" color="inherit" noWrap style={{flexGrow: 1}}>
109 <span>Arvados</span><br/><span style={{fontSize: 12}}>Workbench 2</span>
113 <Typography variant="title" color="inherit" noWrap>
114 {user.firstName} {user.lastName}
117 aria-owns={this.state.anchorEl ? 'menu-appbar' : undefined}
119 onClick={this.handleOpenMenu}
125 anchorEl={this.state.anchorEl}
134 open={!!this.state.anchorEl}
135 onClose={this.handleClose}>
136 <MenuItem onClick={this.logout}>Logout</MenuItem>
137 <MenuItem onClick={this.handleClose}>My account</MenuItem>
141 <Button color="inherit" onClick={this.login}>Login</Button>
149 paper: classes.drawerPaper,
151 <div className={classes.toolbar}/>
152 <Tree items={this.props.projects} render={(p: Project) =>
153 <Link to={`/project/${p.name}`}>{p.name}</Link>
156 <main className={classes.content}>
157 <div className={classes.toolbar}/>
159 <Route path="/project/:name" component={ProjectList}/>
167 export default connect<WorkbenchDataProps>(
168 (state: RootState) => ({
169 projects: state.projects,
170 user: state.auth.user
173 withStyles(styles)(Workbench)