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 { connect, DispatchProp } from "react-redux";
10 import { Route, Switch } from "react-router";
11 import authActions from "../../store/auth/auth-action";
12 import { User } from "../../models/user";
13 import { RootState } from "../../store/store";
14 import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItem } from '../../components/main-app-bar/main-app-bar';
15 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
16 import { push } from 'react-router-redux';
17 import projectActions from "../../store/project/project-action";
18 import ProjectTree from '../../components/project-tree/project-tree';
19 import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
20 import { Project } from "../../models/project";
21 import { projectService } from '../../services/services';
22 import DataExplorer from '../data-explorer/data-explorer';
24 const drawerWidth = 240;
26 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
28 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
39 zIndex: theme.zIndex.drawer + 1,
40 backgroundColor: '#692498',
50 backgroundColor: theme.palette.background.default,
51 padding: theme.spacing.unit * 3,
55 toolbar: theme.mixins.toolbar
58 interface WorkbenchDataProps {
59 projects: Array<TreeItem<Project>>;
63 interface WorkbenchActionProps {
66 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
68 interface NavBreadcrumb extends Breadcrumb {
72 interface NavMenuItem extends MainAppBarMenuItem {
76 interface WorkbenchState {
78 breadcrumbs: NavBreadcrumb[];
81 accountMenu: NavMenuItem[],
82 helpMenu: NavMenuItem[],
83 anonymousMenu: NavMenuItem[]
87 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
97 path: "/projects/project-1"
104 action: () => this.props.dispatch(authActions.LOGOUT())
108 action: () => this.props.dispatch(push("/my-account"))
114 action: () => this.props.dispatch(push("/help"))
120 action: () => this.props.dispatch(authActions.LOGIN())
127 mainAppBarActions: MainAppBarActionProps = {
128 onBreadcrumbClick: (breadcrumb: NavBreadcrumb) => this.props.dispatch(push(breadcrumb.path)),
129 onSearch: searchText => {
130 this.setState({ searchText });
131 this.props.dispatch(push(`/search?q=${searchText}`));
133 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
136 toggleProjectTreeItem = (itemId: string, status: TreeItemStatus) => {
137 if (status === TreeItemStatus.Loaded) {
138 this.openProjectItem(itemId);
140 this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => this.openProjectItem(itemId));
144 openProjectItem = (itemId: string) => {
145 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
146 this.props.dispatch(push(`/project/${itemId}`));
150 const { classes, user } = this.props;
152 <div className={classes.root}>
153 <div className={classes.appBar}>
155 breadcrumbs={this.state.breadcrumbs}
156 searchText={this.state.searchText}
157 user={this.props.user}
158 menuItems={this.state.menuItems}
159 {...this.mainAppBarActions}
166 paper: classes.drawerPaper,
168 <div className={classes.toolbar} />
170 projects={this.props.projects}
171 toggleProjectTreeItem={this.toggleProjectTreeItem} />
173 <main className={classes.content}>
174 <div className={classes.toolbar} />
175 <div className={classes.toolbar} />
177 <Route path="/project/:name" component={DataExplorer} />
185 export default connect<WorkbenchDataProps>(
186 (state: RootState) => ({
187 projects: state.projects,
188 user: state.auth.user
191 withStyles(styles)(Workbench)