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 '../../views-components/main-app-bar/main-app-bar';
15 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
16 import { push } from 'react-router-redux';
17 import projectActions, { getProjectList } from "../../store/project/project-action";
18 import ProjectTree from '../../views-components/project-tree/project-tree';
19 import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
20 import { Project } from "../../models/project";
21 import { getTreePath } from '../../store/project/project-reducer';
22 import ProjectPanel from '../project-panel/project-panel';
24 const drawerWidth = 240;
25 const appBarHeight = 102;
27 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
29 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
40 zIndex: theme.zIndex.drawer + 1,
41 backgroundColor: '#692498',
50 backgroundColor: theme.palette.background.default,
54 paddingTop: appBarHeight
57 padding: theme.spacing.unit * 3,
61 toolbar: theme.mixins.toolbar
64 interface WorkbenchDataProps {
65 projects: Array<TreeItem<Project>>;
69 interface WorkbenchActionProps {
72 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
74 interface NavBreadcrumb extends Breadcrumb {
76 status: TreeItemStatus;
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> {
103 action: () => this.props.dispatch(authActions.LOGOUT())
107 action: () => this.props.dispatch(push("/my-account"))
113 action: () => this.props.dispatch(push("/help"))
119 action: () => this.props.dispatch(authActions.LOGIN())
126 mainAppBarActions: MainAppBarActionProps = {
127 onBreadcrumbClick: ({ itemId, status }: NavBreadcrumb) => {
128 this.toggleProjectTreeItem(itemId, status);
130 onSearch: searchText => {
131 this.setState({ searchText });
132 this.props.dispatch(push(`/search?q=${searchText}`));
134 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
137 toggleProjectTreeItem = (itemId: string, status: TreeItemStatus) => {
138 if (status === TreeItemStatus.Loaded) {
139 this.openProjectItem(itemId);
141 this.props.dispatch<any>(getProjectList(itemId))
142 .then(() => this.openProjectItem(itemId));
146 openProjectItem = (itemId: string) => {
147 const branch = getTreePath(this.props.projects, itemId);
149 breadcrumbs: branch.map(item => ({
150 label: item.data.name,
151 itemId: item.data.uuid,
155 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
156 this.props.dispatch(push(`/project/${itemId}`));
160 const { classes, user } = this.props;
162 <div className={classes.root}>
163 <div className={classes.appBar}>
165 breadcrumbs={this.state.breadcrumbs}
166 searchText={this.state.searchText}
167 user={this.props.user}
168 menuItems={this.state.menuItems}
169 {...this.mainAppBarActions}
176 paper: classes.drawerPaper,
178 <div className={classes.toolbar} />
180 projects={this.props.projects}
181 toggleProjectTreeItem={this.toggleProjectTreeItem} />
183 <main className={classes.contentWrapper}>
184 <div className={classes.content}>
186 <Route path="/project/:name" component={ProjectPanel} />
195 export default connect<WorkbenchDataProps>(
196 (state: RootState) => ({
197 projects: state.projects,
198 user: state.auth.user
201 withStyles(styles)(Workbench)