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 } 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 ProjectPanel from '../project-panel/project-panel';
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";
29 const drawerWidth = 240;
30 const appBarHeight = 102;
32 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
34 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
45 zIndex: theme.zIndex.drawer + 1,
46 backgroundColor: '#692498',
54 flexDirection: 'column',
57 backgroundColor: theme.palette.background.default,
61 paddingTop: appBarHeight
64 padding: theme.spacing.unit * 3,
68 toolbar: theme.mixins.toolbar
71 interface WorkbenchDataProps {
72 projects: Array<TreeItem<Project>>;
73 currentProjectId: string;
75 sidePanelItems: SidePanelItem[];
78 interface WorkbenchActionProps {
81 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
83 interface NavBreadcrumb extends Breadcrumb {
87 interface NavMenuItem extends MainAppBarMenuItem {
91 interface WorkbenchState {
95 accountMenu: NavMenuItem[],
96 helpMenu: NavMenuItem[],
97 anonymousMenu: NavMenuItem[]
101 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
110 action: () => this.props.dispatch(authActions.LOGOUT())
114 action: () => this.props.dispatch(push("/my-account"))
120 action: () => this.props.dispatch(push("/help"))
126 action: () => this.props.dispatch(authActions.LOGIN())
132 mainAppBarActions: MainAppBarActionProps = {
133 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
134 this.props.dispatch<any>(
135 setProjectItem(this.props.projects, itemId, ResourceKind.PROJECT, 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 branch = getTreePath(this.props.projects, this.props.currentProjectId);
156 const breadcrumbs = branch.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(this.props.projects, itemId, ResourceKind.PROJECT, ItemMode.OPEN)
191 toggleActive={itemId =>
192 this.props.dispatch<any>(
193 setProjectItem(this.props.projects, itemId, ResourceKind.PROJECT, ItemMode.ACTIVE)
198 <main className={classes.contentWrapper}>
199 <div className={classes.content}>
201 <Route path="/projects/:name" component={ProjectPanel} />
210 export default connect<WorkbenchDataProps>(
211 (state: RootState) => ({
212 projects: state.projects.items,
213 currentProjectId: state.projects.currentItemId,
214 user: state.auth.user,
215 sidePanelItems: state.sidePanel
218 withStyles(styles)(Workbench)