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 { getTreePath } from '../../store/project/project-reducer';
23 import DataExplorer from '../data-explorer/data-explorer';
25 const drawerWidth = 240;
27 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
29 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
40 zIndex: theme.zIndex.drawer + 1,
41 backgroundColor: '#692498',
51 backgroundColor: theme.palette.background.default,
52 padding: theme.spacing.unit * 3,
56 toolbar: theme.mixins.toolbar
59 interface WorkbenchDataProps {
60 projects: Array<TreeItem<Project>>;
64 interface WorkbenchActionProps {
67 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
69 interface NavBreadcrumb extends Breadcrumb {
71 status: TreeItemStatus;
74 interface NavMenuItem extends MainAppBarMenuItem {
78 interface WorkbenchState {
80 breadcrumbs: NavBreadcrumb[];
83 accountMenu: NavMenuItem[],
84 helpMenu: NavMenuItem[],
85 anonymousMenu: NavMenuItem[]
89 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
98 action: () => this.props.dispatch(authActions.LOGOUT())
102 action: () => this.props.dispatch(push("/my-account"))
108 action: () => this.props.dispatch(push("/help"))
114 action: () => this.props.dispatch(authActions.LOGIN())
121 mainAppBarActions: MainAppBarActionProps = {
122 onBreadcrumbClick: ({ itemId, status }: NavBreadcrumb) => {
123 this.toggleProjectTreeItem(itemId, status);
125 onSearch: searchText => {
126 this.setState({ searchText });
127 this.props.dispatch(push(`/search?q=${searchText}`));
129 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
132 toggleProjectTreeItem = (itemId: string, status: TreeItemStatus) => {
133 if (status === TreeItemStatus.Loaded) {
134 this.openProjectItem(itemId);
136 this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => this.openProjectItem(itemId));
140 openProjectItem = (itemId: string) => {
141 const branch = getTreePath(this.props.projects, itemId);
143 breadcrumbs: branch.map(item => ({
144 label: item.data.name,
145 itemId: item.data.uuid,
149 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
150 this.props.dispatch(push(`/project/${itemId}`));
154 const { classes, user } = this.props;
156 <div className={classes.root}>
157 <div className={classes.appBar}>
159 breadcrumbs={this.state.breadcrumbs}
160 searchText={this.state.searchText}
161 user={this.props.user}
162 menuItems={this.state.menuItems}
163 {...this.mainAppBarActions}
170 paper: classes.drawerPaper,
172 <div className={classes.toolbar} />
174 projects={this.props.projects}
175 toggleProjectTreeItem={this.toggleProjectTreeItem} />
177 <main className={classes.content}>
178 <div className={classes.toolbar} />
179 <div className={classes.toolbar} />
181 <Route path="/project/:name" component={DataExplorer} />
189 export default connect<WorkbenchDataProps>(
190 (state: RootState) => ({
191 projects: state.projects,
192 user: state.auth.user
195 withStyles(styles)(Workbench)