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 { authService } from "../../services/services";
22 import IconButton from "@material-ui/core/IconButton/IconButton";
23 import Menu from "@material-ui/core/Menu/Menu";
24 import MenuItem from "@material-ui/core/MenuItem/MenuItem";
25 import { AccountCircle } from "@material-ui/icons";
26 import { User } from "../../models/user";
28 const drawerWidth = 240;
30 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
32 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
43 zIndex: theme.zIndex.drawer + 1,
44 backgroundColor: '#692498'
52 backgroundColor: theme.palette.background.default,
53 padding: theme.spacing.unit * 3,
57 toolbar: theme.mixins.toolbar
60 interface WorkbenchDataProps {
65 interface WorkbenchActionProps {
68 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
70 interface WorkbenchState {
74 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
75 constructor(props: WorkbenchProps) {
83 this.props.dispatch(authActions.LOGIN());
88 this.props.dispatch(authActions.LOGOUT());
91 handleOpenMenu = (event: React.MouseEvent<any>) => {
93 anchorEl: event.currentTarget
104 const {classes} = this.props;
105 const userLoggedIn = authService.isUserLoggedIn();
107 <div className={classes.root}>
108 <AppBar position="absolute" className={classes.appBar}>
110 <Typography variant="title" color="inherit" noWrap style={{flexGrow: 1}}>
111 <span>Arvados</span><br/><span style={{fontSize: 12}}>Workbench 2</span>
115 <Typography variant="title" color="inherit" noWrap>
116 {this.props.user.firstName} {this.props.user.lastName}
119 aria-owns={this.state.anchorEl ? 'menu-appbar' : undefined}
121 onClick={this.handleOpenMenu}
127 anchorEl={this.state.anchorEl}
136 open={!!this.state.anchorEl}
137 onClose={this.handleClose}>
138 <MenuItem onClick={this.logout}>Logout</MenuItem>
139 <MenuItem onClick={this.handleClose}>My account</MenuItem>
143 <Button color="inherit" onClick={this.login}>Login</Button>
151 paper: classes.drawerPaper,
153 <div className={classes.toolbar}/>
154 <Tree items={this.props.projects} render={(p: Project) =>
155 <Link to={`/project/${p.name}`}>{p.name}</Link>
158 <main className={classes.content}>
159 <div className={classes.toolbar}/>
161 <Route path="/project/:name" component={ProjectList}/>
169 export default connect<WorkbenchDataProps>(
170 (state: RootState) => ({
171 projects: state.projects,
172 user: state.auth.user!
175 withStyles(styles)(Workbench)