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 ProjectList from "../../components/project-list/project-list";
14 import { Route, Switch } from "react-router";
15 import { Link } from "react-router-dom";
16 import Button from "@material-ui/core/Button/Button";
17 import authActions from "../../store/auth/auth-action";
18 import IconButton from "@material-ui/core/IconButton/IconButton";
19 import Menu from "@material-ui/core/Menu/Menu";
20 import MenuItem from "@material-ui/core/MenuItem/MenuItem";
21 import { AccountCircle } from "@material-ui/icons";
22 import { User } from "../../models/user";
23 import Grid from "@material-ui/core/Grid/Grid";
24 import { RootState } from "../../store/store";
25 import projectActions from "../../store/project/project-action"
27 import ProjectTree from '../../components/project-tree/project-tree';
28 import { TreeItem } from "../../components/tree/tree";
29 import { Project } from "../../models/project";
30 import { projectService } from '../../services/services';
32 const drawerWidth = 240;
34 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
36 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
47 zIndex: theme.zIndex.drawer + 1,
48 backgroundColor: '#692498'
56 backgroundColor: theme.palette.background.default,
57 padding: theme.spacing.unit * 3,
61 toolbar: theme.mixins.toolbar
64 interface WorkbenchDataProps {
65 projects: Array<TreeItem<Project>>;
69 interface WorkbenchActionProps {
72 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
74 interface WorkbenchState {
78 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
79 constructor(props: WorkbenchProps) {
87 this.props.dispatch(authActions.LOGIN());
92 this.props.dispatch(authActions.LOGOUT());
95 handleOpenMenu = (event: React.MouseEvent<any>) => {
97 anchorEl: event.currentTarget
101 handleClose = () => {
107 toggleProjectTreeItem = (itemId: string) => {
108 this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => {
109 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
114 const {classes, user} = this.props;
116 <div className={classes.root}>
117 <AppBar position="absolute" className={classes.appBar}>
119 <Typography variant="title" color="inherit" noWrap style={{flexGrow: 1}}>
120 <span>Arvados</span><br/><span style={{fontSize: 12}}>Workbench 2</span>
123 <Grid container style={{width: 'auto'}}>
124 <Grid container style={{width: 'auto'}} alignItems='center'>
125 <Typography variant="title" color="inherit" noWrap>
126 {user.firstName} {user.lastName}
131 aria-owns={this.state.anchorEl ? 'menu-appbar' : undefined}
133 onClick={this.handleOpenMenu}
140 anchorEl={this.state.anchorEl}
149 open={!!this.state.anchorEl}
150 onClose={this.handleClose}>
151 <MenuItem onClick={this.logout}>Logout</MenuItem>
152 <MenuItem onClick={this.handleClose}>My account</MenuItem>
156 <Button color="inherit" onClick={this.login}>Login</Button>
164 paper: classes.drawerPaper,
166 <div className={classes.toolbar}/>
168 projects={this.props.projects}
169 toggleProjectTreeItem={this.toggleProjectTreeItem}/>
171 <main className={classes.content}>
172 <div className={classes.toolbar}/>
174 <Route path="/project/:name" component={ProjectList}/>
182 export default connect<WorkbenchDataProps>(
183 (state: RootState) => ({
184 projects: state.projects,
185 user: state.auth.user
188 withStyles(styles)(Workbench)