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, { loadDetails } from "../../store/details-panel/details-panel-action";
31 import { ResourceKind } from '../../models/kinds';
33 const drawerWidth = 240;
34 const appBarHeight = 100;
36 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
38 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
49 zIndex: theme.zIndex.drawer + 1,
57 flexDirection: 'column',
60 backgroundColor: theme.palette.background.default,
64 paddingTop: appBarHeight
67 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
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[]
105 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
114 action: () => this.props.dispatch(authActions.LOGOUT())
118 action: () => this.props.dispatch(push("/my-account"))
124 action: () => this.props.dispatch(push("/help"))
130 action: () => this.props.dispatch(authActions.LOGIN())
136 mainAppBarActions: MainAppBarActionProps = {
137 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
138 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
140 onSearch: searchText => {
141 this.setState({ searchText });
142 this.props.dispatch(push(`/search?q=${searchText}`));
144 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
145 onDetailsPanelToggle: () => {
146 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
150 toggleSidePanelOpen = (itemId: string) => {
151 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
154 toggleSidePanelActive = (itemId: string) => {
155 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
156 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
160 const path = getTreePath(this.props.projects, this.props.currentProjectId);
161 const breadcrumbs = path.map(item => ({
162 label: item.data.name,
163 itemId: item.data.uuid,
167 const { classes, user } = this.props;
169 <div className={classes.root}>
170 <div className={classes.appBar}>
172 breadcrumbs={breadcrumbs}
173 searchText={this.state.searchText}
174 user={this.props.user}
175 menuItems={this.state.menuItems}
176 {...this.mainAppBarActions}
183 paper: classes.drawerPaper,
185 <div className={classes.toolbar} />
187 toggleOpen={this.toggleSidePanelOpen}
188 toggleActive={this.toggleSidePanelActive}
189 sidePanelItems={this.props.sidePanelItems}>
191 projects={this.props.projects}
192 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
193 toggleActive={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
197 <main className={classes.contentWrapper}>
198 <div className={classes.content}>
200 <Route path="/projects/:id" render={this.renderProjectPanel} />
209 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
210 onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
211 onItemClick={item => {
212 this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
213 this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
219 export default connect<WorkbenchDataProps>(
220 (state: RootState) => ({
221 projects: state.projects.items,
222 currentProjectId: state.projects.currentItemId,
223 user: state.auth.user,
224 sidePanelItems: state.sidePanel
227 withStyles(styles)(Workbench)