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 MainAppBar, { MainAppBarActionProps, MainAppBarMenuItems, MainAppBarMenuItem } from '../../components/main-app-bar/main-app-bar';
26 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
27 import { push } from 'react-router-redux';
28 import projectActions from "../../store/project/project-action"
29 import ProjectTree from '../../components/project-tree/project-tree';
30 import { TreeItem } from "../../components/tree/tree";
31 import { Project } from "../../models/project";
32 import { projectService } from '../../services/services';
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',
60 backgroundColor: theme.palette.background.default,
61 padding: theme.spacing.unit * 3,
65 toolbar: theme.mixins.toolbar
68 interface WorkbenchDataProps {
69 projects: Array<TreeItem<Project>>;
73 interface WorkbenchActionProps {
76 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
78 interface NavBreadcrumb extends Breadcrumb {
82 interface NavMenuItem extends MainAppBarMenuItem {
86 interface WorkbenchState {
88 breadcrumbs: NavBreadcrumb[];
91 accountMenu: NavMenuItem[],
92 helpMenu: NavMenuItem[],
93 anonymousMenu: NavMenuItem[]
97 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
107 path: "/projects/project-1"
114 action: () => this.props.dispatch(authActions.LOGOUT())
118 action: () => this.props.dispatch(push("/my-account"))
124 action: () => this.props.dispatch(push("/help"))
130 action: () => this.props.dispatch(authActions.LOGIN())
137 mainAppBarActions: MainAppBarActionProps = {
138 onBreadcrumbClick: (breadcrumb: NavBreadcrumb) => this.props.dispatch(push(breadcrumb.path)),
139 onSearch: searchText => {
140 this.setState({ searchText });
141 this.props.dispatch(push(`/search?q=${searchText}`));
143 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
146 toggleProjectTreeItem = (itemId: string) => {
147 this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => {
148 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
153 const { classes, user } = this.props;
155 <div className={classes.root}>
156 <div className={classes.appBar}>
158 breadcrumbs={this.state.breadcrumbs}
159 searchText={this.state.searchText}
160 user={this.props.user}
161 menuItems={this.state.menuItems}
162 {...this.mainAppBarActions}
169 paper: classes.drawerPaper,
171 <div className={classes.toolbar}/>
173 projects={this.props.projects}
174 toggleProjectTreeItem={this.toggleProjectTreeItem}/>
176 <main className={classes.content}>
177 <div className={classes.toolbar} />
178 <div className={classes.toolbar} />
180 <Route path="/project/:name" component={ProjectList} />
188 export default connect<WorkbenchDataProps>(
189 (state: RootState) => ({
190 projects: state.projects,
191 user: state.auth.user
194 withStyles(styles)(Workbench)