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;
104 detailsPanelHeader: React.ComponentType<{}> | undefined;
105 detailsPanelDetails: React.ComponentType<{}> | undefined;
106 detailsPanelActivity: React.ComponentType<{}> | undefined;
110 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
119 action: () => this.props.dispatch(authActions.LOGOUT())
123 action: () => this.props.dispatch(push("/my-account"))
129 action: () => this.props.dispatch(push("/help"))
135 action: () => this.props.dispatch(authActions.LOGIN())
139 isDetailsPanelOpened: false,
140 detailsPanelHeader: undefined,
141 detailsPanelDetails: undefined,
142 detailsPanelActivity: undefined,
145 mainAppBarActions: MainAppBarActionProps = {
146 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
147 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
149 onSearch: searchText => {
150 this.setState({ searchText });
151 this.props.dispatch(push(`/search?q=${searchText}`));
153 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
154 onDetailsPanelToggle: () => {
155 this.setState(prev => ({ isDetailsPanelOpened: !prev.isDetailsPanelOpened }));
159 toggleSidePanelOpen = (itemId: string) => {
160 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
163 toggleSidePanelActive = (itemId: string) => {
164 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
165 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
169 const path = getTreePath(this.props.projects, this.props.currentProjectId);
170 const breadcrumbs = path.map(item => ({
171 label: item.data.name,
172 itemId: item.data.uuid,
176 const { classes, user } = this.props;
178 <div className={classes.root}>
179 <div className={classes.appBar}>
181 breadcrumbs={breadcrumbs}
182 searchText={this.state.searchText}
183 user={this.props.user}
184 menuItems={this.state.menuItems}
185 {...this.mainAppBarActions}
192 paper: classes.drawerPaper,
194 <div className={classes.toolbar} />
196 toggleOpen={this.toggleSidePanelOpen}
197 toggleActive={this.toggleSidePanelActive}
198 sidePanelItems={this.props.sidePanelItems}>
200 projects={this.props.projects}
201 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
202 toggleActive={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
206 <main className={classes.contentWrapper}>
207 <div className={classes.content}>
209 <Route path="/projects/:id" render={this.renderProjectPanel} />
213 renderHeader={this.state.detailsPanelHeader}
214 renderDetails={this.state.detailsPanelDetails}
215 renderActivity={this.state.detailsPanelActivity}
216 isOpened={this.state.isDetailsPanelOpened}
217 onCloseDrawer={this.mainAppBarActions.onDetailsPanelToggle} />
223 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
224 onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
225 onItemClick={item => this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE))}
230 export default connect<WorkbenchDataProps>(
231 (state: RootState) => ({
232 projects: state.projects.items,
233 currentProjectId: state.projects.currentItemId,
234 user: state.auth.user,
235 sidePanelItems: state.sidePanel
238 withStyles(styles)(Workbench)