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, Theme, 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 } 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";
14 import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItem } from '../../views-components/main-app-bar/main-app-bar';
15 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
16 import { push } from 'react-router-redux';
17 import projectActions, { getProjectList } from "../../store/project/project-action";
18 import ProjectTree from '../../views-components/project-tree/project-tree';
19 import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
20 import { Project } from "../../models/project";
21 import { getTreePath, findTreeItem } from '../../store/project/project-reducer';
22 import ProjectExplorer, { PROJECT_EXPLORER_ID } from '../../views-components/project-explorer/project-explorer';
23 import { ProjectExplorerItem, mapProjectTreeItem } from '../../views-components/project-explorer/project-explorer-item';
24 import sidePanelActions from '../../store/side-panel/side-panel-action';
25 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
27 const drawerWidth = 240;
28 const appBarHeight = 102;
30 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
32 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
43 zIndex: theme.zIndex.drawer + 1,
44 backgroundColor: '#692498',
52 flexDirection: 'column',
55 backgroundColor: theme.palette.background.default,
59 paddingTop: appBarHeight
62 padding: theme.spacing.unit * 3,
66 toolbar: theme.mixins.toolbar
69 interface WorkbenchDataProps {
70 projects: Array<TreeItem<Project>>;
72 sidePanelItems: SidePanelItem[];
75 interface WorkbenchActionProps {
78 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
80 interface NavBreadcrumb extends Breadcrumb {
82 status: TreeItemStatus;
85 interface NavMenuItem extends MainAppBarMenuItem {
89 interface WorkbenchState {
91 breadcrumbs: NavBreadcrumb[];
94 accountMenu: NavMenuItem[],
95 helpMenu: NavMenuItem[],
96 anonymousMenu: NavMenuItem[]
100 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
109 action: () => this.props.dispatch(authActions.LOGOUT())
113 action: () => this.props.dispatch(push("/my-account"))
119 action: () => this.props.dispatch(push("/help"))
125 action: () => this.props.dispatch(authActions.LOGIN())
132 mainAppBarActions: MainAppBarActionProps = {
133 onBreadcrumbClick: ({ itemId, status }: NavBreadcrumb) => {
134 this.toggleProjectTreeItemOpen(itemId, status);
136 onSearch: searchText => {
137 this.setState({ searchText });
138 this.props.dispatch(push(`/search?q=${searchText}`));
140 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
143 toggleProjectTreeItemOpen = (itemId: string, status: TreeItemStatus) => {
144 if (status === TreeItemStatus.Loaded) {
145 this.openProjectItem(itemId);
146 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
147 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
149 this.props.dispatch<any>(getProjectList(itemId))
151 this.openProjectItem(itemId);
152 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
153 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
158 toggleProjectTreeItemActive = (itemId: string, status: TreeItemStatus) => {
159 if (status === TreeItemStatus.Loaded) {
160 this.openProjectItem(itemId);
161 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
162 this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
164 this.props.dispatch<any>(getProjectList(itemId))
166 this.openProjectItem(itemId);
167 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
168 this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
173 toggleSidePanelOpen = (itemId: string) => {
174 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
177 toggleSidePanelActive = (itemId: string) => {
178 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
179 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
182 openProjectItem = (itemId: string) => {
183 const branch = getTreePath(this.props.projects, itemId);
185 breadcrumbs: branch.map(item => ({
186 label: item.data.name,
187 itemId: item.data.uuid,
191 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
192 this.props.dispatch(push(`/project/${itemId}`));
194 const project = findTreeItem(this.props.projects, itemId);
195 const items: ProjectExplorerItem[] = project && project.items
196 ? project.items.map(mapProjectTreeItem)
198 this.props.dispatch(dataExplorerActions.SET_ITEMS({ id: PROJECT_EXPLORER_ID, items }));
202 const { classes, user, projects, sidePanelItems } = this.props;
204 <div className={classes.root}>
205 <div className={classes.appBar}>
207 breadcrumbs={this.state.breadcrumbs}
208 searchText={this.state.searchText}
209 user={this.props.user}
210 menuItems={this.state.menuItems}
211 {...this.mainAppBarActions}
218 paper: classes.drawerPaper,
220 <div className={classes.toolbar} />
222 toggleOpen={this.toggleSidePanelOpen}
223 toggleActive={this.toggleSidePanelActive}
224 sidePanelItems={sidePanelItems}>
227 toggleOpen={this.toggleProjectTreeItemOpen}
228 toggleActive={this.toggleProjectTreeItemActive} />
231 <main className={classes.contentWrapper}>
232 <div className={classes.content}>
234 <Route path="/project/:name" component={ProjectExplorer} />
243 export default connect<WorkbenchDataProps>(
244 (state: RootState) => ({
245 projects: state.projects,
246 user: state.auth.user,
247 sidePanelItems: state.sidePanel,
250 withStyles(styles)(Workbench)