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";
27 import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItems, MainAppBarMenuItem } from '../../components/main-app-bar/main-app-bar';
28 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
29 import { push } from 'react-router-redux';
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',
57 backgroundColor: theme.palette.background.default,
58 padding: theme.spacing.unit * 3,
62 toolbar: theme.mixins.toolbar
65 interface WorkbenchDataProps {
70 interface WorkbenchActionProps {
73 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
75 interface NavBreadcrumb extends Breadcrumb {
79 interface NavMenuItem extends MainAppBarMenuItem {
83 interface WorkbenchState {
85 breadcrumbs: NavBreadcrumb[];
88 accountMenu: NavMenuItem[],
89 helpMenu: NavMenuItem[],
90 anonymousMenu: NavMenuItem[]
94 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
104 path: "/projects/project-1"
111 action: () => this.props.dispatch(authActions.LOGOUT())
115 action: () => this.props.dispatch(push("/my-account"))
121 action: () => this.props.dispatch(push("/help"))
127 action: () => this.props.dispatch(authActions.LOGIN())
134 mainAppBarActions: MainAppBarActionProps = {
135 onBreadcrumbClick: (breadcrumb: NavBreadcrumb) => this.props.dispatch(push(breadcrumb.path)),
136 onSearch: searchText => {
137 this.setState({ searchText });
138 this.props.dispatch(push(`/search?q=${searchText}`));
140 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
144 const { classes, user } = this.props;
146 <div className={classes.root}>
147 <div className={classes.appBar}>
149 breadcrumbs={this.state.breadcrumbs}
150 searchText={this.state.searchText}
151 user={this.props.user}
152 menuItems={this.state.menuItems}
153 {...this.mainAppBarActions}
160 paper: classes.drawerPaper,
162 <div className={classes.toolbar} />
163 <div className={classes.toolbar} />
164 <Tree items={this.props.projects} render={(p: Project) =>
165 <Link to={`/project/${p.name}`}>{p.name}</Link>
168 <main className={classes.content}>
169 <div className={classes.toolbar} />
170 <div className={classes.toolbar} />
172 <Route path="/project/:name" component={ProjectList} />
180 export default connect<WorkbenchDataProps>(
181 (state: RootState) => ({
182 projects: state.projects,
183 user: state.auth.user
186 withStyles(styles)(Workbench)