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";
15 MainAppBarActionProps,
17 } from '../../views-components/main-app-bar/main-app-bar';
18 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
19 import { push } from 'react-router-redux';
20 import ProjectTree from '../../views-components/project-tree/project-tree';
21 import { TreeItem } from "../../components/tree/tree";
22 import { Project } from "../../models/project";
23 import { getTreePath } from '../../store/project/project-reducer';
24 import DataExplorer from '../data-explorer/data-explorer';
25 import { setProjectItem } from "../../store/navigation/navigation-action";
26 import { ResourceKind } from "../../models/resource";
28 const drawerWidth = 240;
29 const appBarHeight = 102;
31 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
33 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
44 zIndex: theme.zIndex.drawer + 1,
45 backgroundColor: '#692498',
54 backgroundColor: theme.palette.background.default,
58 paddingTop: appBarHeight
61 padding: theme.spacing.unit * 3,
65 toolbar: theme.mixins.toolbar
68 interface WorkbenchDataProps {
69 projects: Array<TreeItem<Project>>;
70 currentProjectId: string;
74 interface WorkbenchActionProps {
77 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
79 interface NavBreadcrumb extends Breadcrumb {
83 interface NavMenuItem extends MainAppBarMenuItem {
87 interface WorkbenchState {
91 accountMenu: NavMenuItem[],
92 helpMenu: NavMenuItem[],
93 anonymousMenu: NavMenuItem[]
97 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
106 action: () => this.props.dispatch(authActions.LOGOUT())
110 action: () => this.props.dispatch(push("/my-account"))
116 action: () => this.props.dispatch(push("/help"))
122 action: () => this.props.dispatch(authActions.LOGIN())
128 mainAppBarActions: MainAppBarActionProps = {
129 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
130 // this.toggleProjectTreeItem(itemId, status);
132 onSearch: searchText => {
133 this.setState({ searchText });
134 this.props.dispatch(push(`/search?q=${searchText}`));
136 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
140 const branch = getTreePath(this.props.projects, this.props.currentProjectId);
141 const breadcrumbs = branch.map(item => ({
142 label: item.data.name,
143 itemId: item.data.uuid,
147 const { classes, user } = this.props;
149 <div className={classes.root}>
150 <div className={classes.appBar}>
152 breadcrumbs={breadcrumbs}
153 searchText={this.state.searchText}
154 user={this.props.user}
155 menuItems={this.state.menuItems}
156 {...this.mainAppBarActions}
162 paper: classes.drawerPaper,
164 <div className={classes.toolbar} />
166 projects={this.props.projects}
167 toggleProjectTreeItem={itemId =>
168 this.props.dispatch<any>(
169 setProjectItem(this.props.projects, itemId, ResourceKind.PROJECT)
172 <main className={classes.contentWrapper}>
173 <div className={classes.content}>
175 <Route path="/projects/:uuid" component={DataExplorer} />
184 export default connect<WorkbenchDataProps>(
185 (state: RootState) => ({
186 projects: state.projects.items,
187 currentProjectId: state.projects.currentItemId,
188 user: state.auth.user
191 withStyles(styles)(Workbench)