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 ProjectList from "../../components/project-list/project-list";
16 import { Route, Switch } from "react-router";
17 import { Link } from "react-router-dom";
18 import Button from "@material-ui/core/Button/Button";
19 import authActions from "../../store/auth/auth-action";
20 import IconButton from "@material-ui/core/IconButton/IconButton";
21 import Menu from "@material-ui/core/Menu/Menu";
22 import MenuItem from "@material-ui/core/MenuItem/MenuItem";
23 import { AccountCircle } from "@material-ui/icons";
24 import { User } from "../../models/user";
25 import Grid from "@material-ui/core/Grid/Grid";
26 import { RootState } from "../../store/store";
28 import { actions as projectActions } from "../../store/project-action";
29 import ProjectTree, { WorkbenchProps } from '../../components/project-tree/project-tree';
31 const drawerWidth = 240;
33 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
35 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
46 zIndex: theme.zIndex.drawer + 1,
47 backgroundColor: '#692498'
55 backgroundColor: theme.palette.background.default,
56 padding: theme.spacing.unit * 3,
60 toolbar: theme.mixins.toolbar
63 interface WorkbenchDataProps {
68 interface WorkbenchActionProps {
71 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
73 interface WorkbenchState {
77 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
78 constructor(props: WorkbenchProps) {
86 this.props.dispatch(authActions.LOGIN());
91 this.props.dispatch(authActions.LOGOUT());
94 handleOpenMenu = (event: React.MouseEvent<any>) => {
96 anchorEl: event.currentTarget
100 handleClose = () => {
107 const {classes, user} = this.props;
109 <div className={classes.root}>
110 <AppBar position="absolute" className={classes.appBar}>
112 <Typography variant="title" color="inherit" noWrap style={{flexGrow: 1}}>
113 <span>Arvados</span><br/><span style={{fontSize: 12}}>Workbench 2</span>
116 <Grid container style={{width: 'auto'}}>
117 <Grid container style={{width: 'auto'}} alignItems='center'>
118 <Typography variant="title" color="inherit" noWrap>
119 {user.firstName} {user.lastName}
124 aria-owns={this.state.anchorEl ? 'menu-appbar' : undefined}
126 onClick={this.handleOpenMenu}
133 anchorEl={this.state.anchorEl}
142 open={!!this.state.anchorEl}
143 onClose={this.handleClose}>
144 <MenuItem onClick={this.logout}>Logout</MenuItem>
145 <MenuItem onClick={this.handleClose}>My account</MenuItem>
149 <Button color="inherit" onClick={this.login}>Login</Button>
157 paper: classes.drawerPaper,
159 <div className={classes.toolbar}/>
161 projects={this.props.projects}
162 toggleProjectTreeItem={this.props.toggleProjectTreeItem}/>
164 <main className={classes.content}>
165 <div className={classes.toolbar}/>
167 <Route path="/project/:name" component={ProjectList}/>
175 export default connect<WorkbenchDataProps>(
176 (state: RootState) => ({
177 projects: state.projects,
178 user: state.auth.user
180 toggleProjectTreeItem: (id: string) => projectActions.toggleProjectTreeItem(id)
183 withStyles(styles)(Workbench)