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 DataExplorer from '../data-explorer/data-explorer';
23 import { getCollectionList } from "../../store/collection/collection-action";
25 const drawerWidth = 240;
26 const appBarHeight = 102;
28 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
30 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
41 zIndex: theme.zIndex.drawer + 1,
42 backgroundColor: '#692498',
51 backgroundColor: theme.palette.background.default,
55 paddingTop: appBarHeight
58 padding: theme.spacing.unit * 3,
62 toolbar: theme.mixins.toolbar
65 interface WorkbenchDataProps {
66 projects: Array<TreeItem<Project>>;
70 interface WorkbenchActionProps {
73 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
75 interface NavBreadcrumb extends Breadcrumb {
77 status: TreeItemStatus;
80 interface NavMenuItem extends MainAppBarMenuItem {
84 interface WorkbenchState {
86 breadcrumbs: NavBreadcrumb[];
89 accountMenu: NavMenuItem[],
90 helpMenu: NavMenuItem[],
91 anonymousMenu: NavMenuItem[]
95 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
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())
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));
144 this.props.dispatch<any>(getCollectionList(itemId));
147 openProjectItem = (itemId: string) => {
148 const branch = getTreePath(this.props.projects, itemId);
150 breadcrumbs: branch.map(item => ({
151 label: item.data.name,
152 itemId: item.data.uuid,
156 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
157 this.props.dispatch(push(`/project/${itemId}`));
161 const { classes, user } = this.props;
163 <div className={classes.root}>
164 <div className={classes.appBar}>
166 breadcrumbs={this.state.breadcrumbs}
167 searchText={this.state.searchText}
168 user={this.props.user}
169 menuItems={this.state.menuItems}
170 {...this.mainAppBarActions}
177 paper: classes.drawerPaper,
179 <div className={classes.toolbar} />
181 projects={this.props.projects}
182 toggleProjectTreeItem={this.toggleProjectTreeItem} />
184 <main className={classes.contentWrapper}>
185 <div className={classes.content}>
187 <Route path="/project/:uuid" component={DataExplorer} />
196 export default connect<WorkbenchDataProps>(
197 (state: RootState) => ({
198 projects: state.projects,
199 user: state.auth.user
202 withStyles(styles)(Workbench)