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';
31 import ProjectExplorer from '../project-explorer/project-explorer';
32 import { push } from 'react-router-redux';
34 const drawerWidth = 240;
36 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
38 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
49 zIndex: theme.zIndex.drawer + 1,
50 backgroundColor: '#692498'
58 backgroundColor: theme.palette.background.default,
59 padding: theme.spacing.unit * 3,
63 toolbar: theme.mixins.toolbar
66 interface WorkbenchDataProps {
67 projects: Array<TreeItem<Project>>;
71 interface WorkbenchActionProps {
74 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
76 interface WorkbenchState {
80 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
81 constructor(props: WorkbenchProps) {
89 this.props.dispatch(authActions.LOGIN());
94 this.props.dispatch(authActions.LOGOUT());
97 handleOpenMenu = (event: React.MouseEvent<any>) => {
99 anchorEl: event.currentTarget
103 handleClose = () => {
109 toggleProjectTreeItem = (itemId: string) => {
110 this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => {
111 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
112 this.props.dispatch(push(`/project/${itemId}`))
117 const {classes, user} = this.props;
119 <div className={classes.root}>
120 <AppBar position="absolute" className={classes.appBar}>
122 <Typography variant="title" color="inherit" noWrap style={{flexGrow: 1}}>
123 <span>Arvados</span><br/><span style={{fontSize: 12}}>Workbench 2</span>
126 <Grid container style={{width: 'auto'}}>
127 <Grid container style={{width: 'auto'}} alignItems='center'>
128 <Typography variant="title" color="inherit" noWrap>
129 {user.firstName} {user.lastName}
134 aria-owns={this.state.anchorEl ? 'menu-appbar' : undefined}
136 onClick={this.handleOpenMenu}
143 anchorEl={this.state.anchorEl}
152 open={!!this.state.anchorEl}
153 onClose={this.handleClose}>
154 <MenuItem onClick={this.logout}>Logout</MenuItem>
155 <MenuItem onClick={this.handleClose}>My account</MenuItem>
159 <Button color="inherit" onClick={this.login}>Login</Button>
167 paper: classes.drawerPaper,
169 <div className={classes.toolbar}/>
171 projects={this.props.projects}
172 toggleProjectTreeItem={this.toggleProjectTreeItem}/>
174 <main className={classes.content}>
175 <div className={classes.toolbar}/>
177 <Route path="/project/:name" component={ProjectExplorer}/>
185 export default connect<WorkbenchDataProps>(
186 (state: RootState) => ({
187 projects: state.projects,
188 user: state.auth.user
191 withStyles(styles)(Workbench)