1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
7 import Drawer from '@material-ui/core/Drawer';
8 import { connect, DispatchProp } from "react-redux";
9 import { Route, Switch, RouteComponentProps } from "react-router";
10 import authActions from "../../store/auth/auth-action";
11 import dataExplorerActions from "../../store/data-explorer/data-explorer-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, findTreeItem } from '../../store/project/project-reducer';
24 import sidePanelActions from '../../store/side-panel/side-panel-action';
25 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
26 import { ResourceKind } from "../../models/resource";
27 import { ItemMode, setProjectItem } from "../../store/navigation/navigation-action";
28 import projectActions from "../../store/project/project-action";
29 import ProjectPanel from "../project-panel/project-panel";
31 const drawerWidth = 240;
32 const appBarHeight = 102;
34 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
36 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
47 zIndex: theme.zIndex.drawer + 1,
48 backgroundColor: '#692498',
56 flexDirection: 'column',
59 backgroundColor: theme.palette.background.default,
63 paddingTop: appBarHeight
66 padding: theme.spacing.unit * 3,
70 toolbar: theme.mixins.toolbar
73 interface WorkbenchDataProps {
74 projects: Array<TreeItem<Project>>;
75 currentProjectId: string;
77 sidePanelItems: SidePanelItem[];
80 interface WorkbenchActionProps {
83 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
85 interface NavBreadcrumb extends Breadcrumb {
89 interface NavMenuItem extends MainAppBarMenuItem {
93 interface WorkbenchState {
97 accountMenu: NavMenuItem[],
98 helpMenu: NavMenuItem[],
99 anonymousMenu: NavMenuItem[]
103 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
112 action: () => this.props.dispatch(authActions.LOGOUT())
116 action: () => this.props.dispatch(push("/my-account"))
122 action: () => this.props.dispatch(push("/help"))
128 action: () => this.props.dispatch(authActions.LOGIN())
134 mainAppBarActions: MainAppBarActionProps = {
135 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
136 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
138 onSearch: searchText => {
139 this.setState({ searchText });
140 this.props.dispatch(push(`/search?q=${searchText}`));
142 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
145 toggleSidePanelOpen = (itemId: string) => {
146 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
149 toggleSidePanelActive = (itemId: string) => {
150 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
151 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
155 const path = getTreePath(this.props.projects, this.props.currentProjectId);
156 const breadcrumbs = path.map(item => ({
157 label: item.data.name,
158 itemId: item.data.uuid,
162 const { classes, user } = this.props;
164 <div className={classes.root}>
165 <div className={classes.appBar}>
167 breadcrumbs={breadcrumbs}
168 searchText={this.state.searchText}
169 user={this.props.user}
170 menuItems={this.state.menuItems}
171 {...this.mainAppBarActions}
178 paper: classes.drawerPaper,
180 <div className={classes.toolbar} />
182 toggleOpen={this.toggleSidePanelOpen}
183 toggleActive={this.toggleSidePanelActive}
184 sidePanelItems={this.props.sidePanelItems}>
186 projects={this.props.projects}
187 toggleOpen={itemId =>
188 this.props.dispatch<any>(
189 setProjectItem(itemId, ItemMode.OPEN)
191 toggleActive={itemId =>
192 this.props.dispatch<any>(
193 setProjectItem(itemId, ItemMode.ACTIVE)
198 <main className={classes.contentWrapper}>
199 <div className={classes.content}>
201 <Route path="/projects/:id" render={this.renderProjectPanel} />
209 renderProjectPanel = (props: RouteComponentProps<any>) =>
211 onItemOpen={itemId => this.props.dispatch<any>(
212 setProjectItem(itemId, ItemMode.ACTIVE)
217 export default connect<WorkbenchDataProps>(
218 (state: RootState) => ({
219 projects: state.projects.items,
220 currentProjectId: state.projects.currentItemId,
221 user: state.auth.user,
222 sidePanelItems: state.sidePanel
225 withStyles(styles)(Workbench)