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';
33 import { findTreeBranch } from '../../store/project/project-reducer';
35 const drawerWidth = 240;
37 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
39 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
50 zIndex: theme.zIndex.drawer + 1,
51 backgroundColor: '#692498',
61 backgroundColor: theme.palette.background.default,
62 padding: theme.spacing.unit * 3,
66 toolbar: theme.mixins.toolbar
69 interface WorkbenchDataProps {
70 projects: Array<TreeItem<Project>>;
74 interface WorkbenchActionProps {
77 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
79 interface NavBreadcrumb extends Breadcrumb {
83 interface NavMenuItem extends MainAppBarMenuItem {
87 interface WorkbenchState {
89 breadcrumbs: NavBreadcrumb[];
92 accountMenu: NavMenuItem[],
93 helpMenu: NavMenuItem[],
94 anonymousMenu: NavMenuItem[]
98 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
107 action: () => this.props.dispatch(authActions.LOGOUT())
111 action: () => this.props.dispatch(push("/my-account"))
117 action: () => this.props.dispatch(push("/help"))
123 action: () => this.props.dispatch(authActions.LOGIN())
130 mainAppBarActions: MainAppBarActionProps = {
131 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
132 this.toggleProjectTreeItem(itemId);
134 onSearch: searchText => {
135 this.setState({ searchText });
136 this.props.dispatch(push(`/search?q=${searchText}`));
138 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
141 toggleProjectTreeItem = (itemId: string) => {
142 const branch = findTreeBranch(this.props.projects, itemId);
144 breadcrumbs: branch.map(item => ({
145 label: item.data.name,
146 itemId: item.data.uuid
149 this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => {
150 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
155 const { classes, user } = this.props;
157 <div className={classes.root}>
158 <div className={classes.appBar}>
160 breadcrumbs={this.state.breadcrumbs}
161 searchText={this.state.searchText}
162 user={this.props.user}
163 menuItems={this.state.menuItems}
164 {...this.mainAppBarActions}
171 paper: classes.drawerPaper,
173 <div className={classes.toolbar} />
175 projects={this.props.projects}
176 toggleProjectTreeItem={this.toggleProjectTreeItem} />
178 <main className={classes.content}>
179 <div className={classes.toolbar} />
180 <div className={classes.toolbar} />
182 <Route path="/project/:name" component={ProjectList} />
190 export default connect<WorkbenchDataProps>(
191 (state: RootState) => ({
192 projects: state.projects,
193 user: state.auth.user
196 withStyles(styles)(Workbench)