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 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 { 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))
137 .then(() => this.openProjectItem(itemId));
141 openProjectItem = (itemId: string) => {
142 const branch = getTreePath(this.props.projects, itemId);
144 breadcrumbs: branch.map(item => ({
145 label: item.data.name,
146 itemId: item.data.uuid,
150 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
151 this.props.dispatch(push(`/project/${itemId}`));
155 const { classes, user } = this.props;
157 <div className={classes.root}>
158 <div className={classes.appBar}>
160 breadcrumbs={this.state.breadcrumbs}
161 searchText={this.state.searchText}
162 user={this.props.user}
163 menuItems={this.state.menuItems}
164 {...this.mainAppBarActions}
171 paper: classes.drawerPaper,
173 <div className={classes.toolbar} />
175 projects={this.props.projects}
176 toggleProjectTreeItem={this.toggleProjectTreeItem} />
178 <main className={classes.content}>
179 <div className={classes.toolbar} />
180 <div className={classes.toolbar} />
182 <Route path="/project/:name" component={DataExplorer} />
190 export default connect<WorkbenchDataProps>(
191 (state: RootState) => ({
192 projects: state.projects,
193 user: state.auth.user
196 withStyles(styles)(Workbench)