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 { getTreePath } from '../../store/project/project-reducer';
22 import sidePanelActions from '../../store/side-panel/side-panel-action';
23 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
24 import { ItemMode, setProjectItem } from "../../store/navigation/navigation-action";
25 import projectActions from "../../store/project/project-action";
26 import ProjectPanel from "../project-panel/project-panel";
27 import DetailsPanel from '../../views-components/details-panel/details-panel';
28 import { ArvadosTheme } from '../../common/custom-theme';
29 import ContextMenu, { ContextMenuKind } from "../../views-components/context-menu";
30 import CreateProjectDialog from "../../views-components/create-project-dialog/create-project-dialog";
31 import { authService } from '../../services/services';
33 import detailsPanelActions, { loadDetails } from "../../store/details-panel/details-panel-action";
34 import contextMenuActions from "../../store/context-menu/context-menu-actions";
35 import { SidePanelIdentifiers } from '../../store/side-panel/side-panel-reducer';
36 import { ProjectResource } from '../../models/project';
37 import { ResourceKind } from '../../models/resource';
39 interface WorkbenchDataProps {
40 projects: Array<TreeItem<ProjectResource>>;
41 currentProjectId: string;
43 sidePanelItems: SidePanelItem[];
46 interface WorkbenchActionProps {
49 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
51 interface NavBreadcrumb extends Breadcrumb {
55 interface NavMenuItem extends MainAppBarMenuItem {
59 interface WorkbenchState {
63 accountMenu: NavMenuItem[],
64 helpMenu: NavMenuItem[],
65 anonymousMenu: NavMenuItem[]
70 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
72 isCreationDialogOpen: false,
80 action: () => this.props.dispatch(authActions.LOGOUT())
84 action: () => this.props.dispatch(push("/my-account"))
90 action: () => this.props.dispatch(push("/help"))
96 action: () => this.props.dispatch(authActions.LOGIN())
103 const path = getTreePath(this.props.projects, this.props.currentProjectId);
104 const breadcrumbs = path.map(item => ({
105 label: item.data.name,
106 itemId: item.data.uuid,
110 const { classes, user } = this.props;
112 <div className={classes.root}>
113 <div className={classes.appBar}>
115 breadcrumbs={breadcrumbs}
116 searchText={this.state.searchText}
117 user={this.props.user}
118 menuItems={this.state.menuItems}
119 {...this.mainAppBarActions} />
125 paper: classes.drawerPaper,
127 <div className={classes.toolbar} />
129 toggleOpen={this.toggleSidePanelOpen}
130 toggleActive={this.toggleSidePanelActive}
131 sidePanelItems={this.props.sidePanelItems}
132 onContextMenu={(event) => this.openContextMenu(event, authService.getUuid() || "", ContextMenuKind.RootProject)}>
134 projects={this.props.projects}
135 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
136 onContextMenu={(event, item) => this.openContextMenu(event, item.data.uuid, ContextMenuKind.Project)}
137 toggleActive={itemId => {
138 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE));
139 this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
140 this.props.dispatch<any>(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.Projects));
144 <main className={classes.contentWrapper}>
145 <div className={classes.content}>
147 <Route path="/projects/:id" render={this.renderProjectPanel} />
150 { user && <DetailsPanel /> }
153 <CreateProjectDialog />
158 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
159 onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
160 onContextMenu={(event, item) => this.openContextMenu(event, item.uuid, ContextMenuKind.Project)}
161 onDialogOpen={this.handleCreationDialogOpen}
162 onItemClick={item => {
163 this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
165 onItemDoubleClick={item => {
166 this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
167 this.props.dispatch<any>(loadDetails(item.uuid, ResourceKind.Project));
171 mainAppBarActions: MainAppBarActionProps = {
172 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
173 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
174 this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
176 onSearch: searchText => {
177 this.setState({ searchText });
178 this.props.dispatch(push(`/search?q=${searchText}`));
180 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
181 onDetailsPanelToggle: () => {
182 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
184 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
185 this.openContextMenu(event, breadcrumb.itemId, ContextMenuKind.Project);
189 toggleSidePanelOpen = (itemId: string) => {
190 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
193 toggleSidePanelActive = (itemId: string) => {
194 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
195 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
196 this.props.dispatch(push("/"));
199 handleCreationDialogOpen = (itemUuid: string) => {
200 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
203 openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string, kind: ContextMenuKind) => {
204 event.preventDefault();
206 contextMenuActions.OPEN_CONTEXT_MENU({
207 position: { x: event.clientX, y: event.clientY },
208 resource: { uuid: itemUuid, kind }
216 const drawerWidth = 240;
217 const appBarHeight = 100;
219 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
221 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
226 position: 'relative',
232 zIndex: theme.zIndex.drawer + 1,
233 position: "absolute",
237 position: 'relative',
240 flexDirection: 'column',
243 backgroundColor: theme.palette.background.default,
247 paddingTop: appBarHeight
250 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
254 toolbar: theme.mixins.toolbar
257 export default connect<WorkbenchDataProps>(
258 (state: RootState) => ({
259 projects: state.projects.items,
260 currentProjectId: state.projects.currentItemId,
261 user: state.auth.user,
262 sidePanelItems: state.sidePanel
265 withStyles(styles)(Workbench)