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, 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';
31 import DetailsPanel from '../../views-components/details-panel/details-panel';
32 import { ArvadosTheme } from '../../common/custom-theme';
34 const drawerWidth = 240;
35 const appBarHeight = 100;
37 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
39 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
50 zIndex: theme.zIndex.drawer + 1,
58 flexDirection: 'column',
61 backgroundColor: theme.palette.background.default,
65 paddingTop: appBarHeight
68 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
72 toolbar: theme.mixins.toolbar
75 interface WorkbenchDataProps {
76 projects: Array<TreeItem<Project>>;
77 currentProjectId: string;
79 sidePanelItems: SidePanelItem[];
82 interface WorkbenchActionProps {
85 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
87 interface NavBreadcrumb extends Breadcrumb {
91 interface NavMenuItem extends MainAppBarMenuItem {
95 interface WorkbenchState {
99 accountMenu: NavMenuItem[],
100 helpMenu: NavMenuItem[],
101 anonymousMenu: NavMenuItem[]
103 isDetailsPanelOpened: boolean;
106 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
115 action: () => this.props.dispatch(authActions.LOGOUT())
119 action: () => this.props.dispatch(push("/my-account"))
125 action: () => this.props.dispatch(push("/help"))
131 action: () => this.props.dispatch(authActions.LOGIN())
135 isDetailsPanelOpened: false
138 mainAppBarActions: MainAppBarActionProps = {
139 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
140 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
142 onSearch: searchText => {
143 this.setState({ searchText });
144 this.props.dispatch(push(`/search?q=${searchText}`));
146 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
147 onDetailsPanelToggle: () => {
148 this.setState(prev => ({ isDetailsPanelOpened: !prev.isDetailsPanelOpened }));
152 toggleSidePanelOpen = (itemId: string) => {
153 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
156 toggleSidePanelActive = (itemId: string) => {
157 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
158 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
162 const path = getTreePath(this.props.projects, this.props.currentProjectId);
163 const breadcrumbs = path.map(item => ({
164 label: item.data.name,
165 itemId: item.data.uuid,
169 const { classes, user } = this.props;
171 <div className={classes.root}>
172 <div className={classes.appBar}>
174 breadcrumbs={breadcrumbs}
175 searchText={this.state.searchText}
176 user={this.props.user}
177 menuItems={this.state.menuItems}
178 {...this.mainAppBarActions}
185 paper: classes.drawerPaper,
187 <div className={classes.toolbar} />
189 toggleOpen={this.toggleSidePanelOpen}
190 toggleActive={this.toggleSidePanelActive}
191 sidePanelItems={this.props.sidePanelItems}>
193 projects={this.props.projects}
194 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
195 toggleActive={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
199 <main className={classes.contentWrapper}>
200 <div className={classes.content}>
202 <Route path="/projects/:id" render={this.renderProjectPanel} />
206 isOpened={this.state.isDetailsPanelOpened}
207 onCloseDrawer={this.mainAppBarActions.onDetailsPanelToggle} />
213 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
214 onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
215 onItemClick={item => this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE))}
220 export default connect<WorkbenchDataProps>(
221 (state: RootState) => ({
222 projects: state.projects.items,
223 currentProjectId: state.projects.currentItemId,
224 user: state.auth.user,
225 sidePanelItems: state.sidePanel
228 withStyles(styles)(Workbench)