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));
139 this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
141 onSearch: searchText => {
142 this.setState({ searchText });
143 this.props.dispatch(push(`/search?q=${searchText}`));
145 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
146 onDetailsPanelToggle: () => {
147 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
151 toggleSidePanelOpen = (itemId: string) => {
152 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
155 toggleSidePanelActive = (itemId: string) => {
156 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
157 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
161 const path = getTreePath(this.props.projects, this.props.currentProjectId);
162 const breadcrumbs = path.map(item => ({
163 label: item.data.name,
164 itemId: item.data.uuid,
168 const { classes, user } = this.props;
170 <div className={classes.root}>
171 <div className={classes.appBar}>
173 breadcrumbs={breadcrumbs}
174 searchText={this.state.searchText}
175 user={this.props.user}
176 menuItems={this.state.menuItems}
177 {...this.mainAppBarActions}
184 paper: classes.drawerPaper,
186 <div className={classes.toolbar} />
188 toggleOpen={this.toggleSidePanelOpen}
189 toggleActive={this.toggleSidePanelActive}
190 sidePanelItems={this.props.sidePanelItems}>
192 projects={this.props.projects}
193 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
194 toggleActive={itemId => {
195 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE));
196 this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
201 <main className={classes.contentWrapper}>
202 <div className={classes.content}>
204 <Route path="/projects/:id" render={this.renderProjectPanel} />
213 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
214 onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
215 onItemClick={item => {
216 this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
218 onItemDoubleClick={item => {
219 this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
220 this.props.dispatch<any>(loadDetails(item.uuid, ResourceKind.Project));
226 export default connect<WorkbenchDataProps>(
227 (state: RootState) => ({
228 projects: state.projects.items,
229 currentProjectId: state.projects.currentItemId,
230 user: state.auth.user,
231 sidePanelItems: state.sidePanel
234 withStyles(styles)(Workbench)