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, withRouter } 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";
30 import { sidePanelData } from '../../store/side-panel/side-panel-reducer';
32 const drawerWidth = 240;
33 const appBarHeight = 102;
35 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
37 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
48 zIndex: theme.zIndex.drawer + 1,
49 backgroundColor: '#692498',
57 flexDirection: 'column',
60 backgroundColor: theme.palette.background.default,
64 paddingTop: appBarHeight
67 padding: theme.spacing.unit * 3,
71 toolbar: theme.mixins.toolbar
74 interface WorkbenchDataProps {
75 projects: Array<TreeItem<Project>>;
76 currentProjectId: string;
78 sidePanelItems: SidePanelItem[];
81 interface WorkbenchActionProps {
84 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
86 interface NavBreadcrumb extends Breadcrumb {
90 interface NavMenuItem extends MainAppBarMenuItem {
94 interface WorkbenchState {
98 accountMenu: NavMenuItem[],
99 helpMenu: NavMenuItem[],
100 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()
146 toggleSidePanelOpen = (itemId: string) => {
147 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
150 toggleSidePanelActive = (itemId: string) => {
151 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
152 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
156 const path = getTreePath(this.props.projects, this.props.currentProjectId);
157 const breadcrumbs = path.map(item => ({
158 label: item.data.name,
159 itemId: item.data.uuid,
163 const { classes, user } = this.props;
165 <div className={classes.root}>
166 <div className={classes.appBar}>
168 breadcrumbs={breadcrumbs}
169 searchText={this.state.searchText}
170 user={this.props.user}
171 menuItems={this.state.menuItems}
172 {...this.mainAppBarActions}
179 paper: classes.drawerPaper,
181 <div className={classes.toolbar} />
183 toggleOpen={this.toggleSidePanelOpen}
184 toggleActive={this.toggleSidePanelActive}
185 sidePanelItems={this.props.sidePanelItems}>
187 projects={this.props.projects}
188 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
189 toggleActive={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
193 <main className={classes.contentWrapper}>
194 <div className={classes.content}>
196 <Route path="/projects/:id" render={this.renderProjectPanel} />
204 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
205 onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
206 onItemClick={item => this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE))}
211 export default connect<WorkbenchDataProps>(
212 (state: RootState) => ({
213 projects: state.projects.items,
214 currentProjectId: state.projects.currentItemId,
215 user: state.auth.user,
216 sidePanelItems: state.sidePanel
219 withStyles(styles)(Workbench)