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, 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 { User } from "../../models/user";
12 import { RootState } from "../../store/store";
14 MainAppBarActionProps,
16 } from '../../views-components/main-app-bar/main-app-bar';
17 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
18 import { push } from 'react-router-redux';
19 import ProjectTree from '../../views-components/project-tree/project-tree';
20 import { TreeItem } from "../../components/tree/tree";
21 import { Project } from "../../models/project";
22 import { getTreePath } from '../../store/project/project-reducer';
23 import sidePanelActions from '../../store/side-panel/side-panel-action';
24 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
25 import { ItemMode, setProjectItem } from "../../store/navigation/navigation-action";
26 import projectActions from "../../store/project/project-action";
27 import ProjectPanel from "../project-panel/project-panel";
28 import DetailsPanel from '../../views-components/details-panel/details-panel';
29 import { ArvadosTheme } from '../../common/custom-theme';
30 import detailsPanelActions from "../../store/details-panel/details-panel-action";
32 const drawerWidth = 240;
33 const appBarHeight = 100;
35 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
37 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
48 zIndex: theme.zIndex.drawer + 1,
56 flexDirection: 'column',
59 backgroundColor: theme.palette.background.default,
63 paddingTop: appBarHeight
66 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
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[]
104 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
113 action: () => this.props.dispatch(authActions.LOGOUT())
117 action: () => this.props.dispatch(push("/my-account"))
123 action: () => this.props.dispatch(push("/help"))
129 action: () => this.props.dispatch(authActions.LOGIN())
135 mainAppBarActions: MainAppBarActionProps = {
136 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
137 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
139 onSearch: searchText => {
140 this.setState({ searchText });
141 this.props.dispatch(push(`/search?q=${searchText}`));
143 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
144 onDetailsPanelToggle: () => {
145 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
149 toggleSidePanelOpen = (itemId: string) => {
150 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
153 toggleSidePanelActive = (itemId: string) => {
154 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
155 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
159 const path = getTreePath(this.props.projects, this.props.currentProjectId);
160 const breadcrumbs = path.map(item => ({
161 label: item.data.name,
162 itemId: item.data.uuid,
166 const { classes, user } = this.props;
168 <div className={classes.root}>
169 <div className={classes.appBar}>
171 breadcrumbs={breadcrumbs}
172 searchText={this.state.searchText}
173 user={this.props.user}
174 menuItems={this.state.menuItems}
175 {...this.mainAppBarActions}
182 paper: classes.drawerPaper,
184 <div className={classes.toolbar} />
186 toggleOpen={this.toggleSidePanelOpen}
187 toggleActive={this.toggleSidePanelActive}
188 sidePanelItems={this.props.sidePanelItems}>
190 projects={this.props.projects}
191 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
192 toggleActive={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
196 <main className={classes.contentWrapper}>
197 <div className={classes.content}>
199 <Route path="/projects/:id" render={this.renderProjectPanel} />
208 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
209 onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
210 onItemClick={item => this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE))}
215 export default connect<WorkbenchDataProps>(
216 (state: RootState) => ({
217 projects: state.projects.items,
218 currentProjectId: state.projects.currentItemId,
219 user: state.auth.user,
220 sidePanelItems: state.sidePanel
223 withStyles(styles)(Workbench)