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 { 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.toggleProjectTreeItem(itemId, status);
136 onSearch: searchText => {
137 this.setState({ searchText });
138 this.props.dispatch(push(`/search?q=${searchText}`));
140 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
143 toggleSidePanelOpen = (itemId: string) => {
144 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
147 toggleSidePanelActive = (itemId: string) => {
148 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
149 // this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
153 const branch = getTreePath(this.props.projects, this.props.currentProjectId);
154 const breadcrumbs = branch.map(item => ({
155 label: item.data.name,
156 itemId: item.data.uuid,
160 const { classes, user } = this.props;
162 <div className={classes.root}>
163 <div className={classes.appBar}>
165 breadcrumbs={breadcrumbs}
166 searchText={this.state.searchText}
167 user={this.props.user}
168 menuItems={this.state.menuItems}
169 {...this.mainAppBarActions}
176 paper: classes.drawerPaper,
178 <div className={classes.toolbar} />
180 toggleOpen={this.toggleSidePanelOpen}
181 toggleActive={this.toggleSidePanelActive}
182 sidePanelItems={this.props.sidePanelItems}>
184 projects={this.props.projects}
185 toggleOpen={itemId =>
186 this.props.dispatch<any>(
187 setProjectItem(this.props.projects, itemId, ResourceKind.PROJECT)
189 toggleActive={itemId =>
190 this.props.dispatch<any>(
191 setProjectItem(this.props.projects, itemId, ResourceKind.PROJECT)
196 <main className={classes.contentWrapper}>
197 <div className={classes.content}>
199 <Route path="/project/:name" component={ProjectPanel} />
209 projects={this.props.projects}
210 toggleProjectTreeItem={itemId =>
211 this.props.dispatch<any>(
212 setProjectItem(this.props.projects, itemId, ResourceKind.PROJECT)
216 export default connect<WorkbenchDataProps>(
217 (state: RootState) => ({
218 projects: state.projects.items,
219 currentProjectId: state.projects.currentItemId,
220 user: state.auth.user,
221 sidePanelItems: state.sidePanel
224 withStyles(styles)(Workbench)