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";
10 import ProjectList from "../../components/project-list/project-list";
11 import { Route, Switch } from "react-router";
12 import authActions from "../../store/auth/auth-action";
13 import { User } from "../../models/user";
14 import { RootState } from "../../store/store";
15 import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItem } from '../../components/main-app-bar/main-app-bar';
16 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
17 import { push } from 'react-router-redux';
18 import projectActions from "../../store/project/project-action";
19 import sidePanelActions from '../../store/side-panel/side-panel-action';
20 import ProjectTree from '../../components/project-tree/project-tree';
21 import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
22 import { Project } from "../../models/project";
23 import { projectService } from '../../services/services';
24 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
26 const drawerWidth = 240;
28 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'toolbar';
30 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
41 zIndex: theme.zIndex.drawer + 1,
42 backgroundColor: '#692498',
50 flexDirection: 'column',
54 backgroundColor: theme.palette.background.default,
55 padding: theme.spacing.unit * 3,
59 toolbar: theme.mixins.toolbar
62 interface WorkbenchDataProps {
63 projects: Array<TreeItem<Project>>;
65 sidePanelItems: SidePanelItem[];
68 interface WorkbenchActionProps {
71 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
73 interface NavBreadcrumb extends Breadcrumb {
77 interface NavMenuItem extends MainAppBarMenuItem {
81 interface WorkbenchState {
83 breadcrumbs: NavBreadcrumb[];
86 accountMenu: NavMenuItem[],
87 helpMenu: NavMenuItem[],
88 anonymousMenu: NavMenuItem[]
92 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
102 path: "/projects/project-1"
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: (breadcrumb: NavBreadcrumb) => this.props.dispatch(push(breadcrumb.path)),
134 onSearch: searchText => {
135 this.setState({ searchText });
136 this.props.dispatch(push(`/search?q=${searchText}`));
138 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
141 toggleProjectTreeItemOpen = (itemId: string, status: TreeItemStatus) => {
142 if (status === TreeItemStatus.Loaded) {
143 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
144 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
146 this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => {
147 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
148 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
153 toggleProjectTreeItemActive = (itemId: string) => {
154 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
155 this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
158 toggleSidePanelOpen = (itemId: string) => {
159 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
162 toggleSidePanelActive = (itemId: string) => {
163 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
164 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
168 const { classes, user, projects, sidePanelItems } = this.props;
170 <div className={classes.root}>
171 <div className={classes.appBar}>
173 breadcrumbs={this.state.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={sidePanelItems}>
193 toggleOpen={this.toggleProjectTreeItemOpen}
194 toggleActive={this.toggleProjectTreeItemActive} />
197 <main className={classes.content}>
198 <div className={classes.toolbar} />
200 <Route path="/project/:name" component={ProjectList} />
208 export default connect<WorkbenchDataProps>(
209 (state: RootState) => ({
210 projects: state.projects,
211 user: state.auth.user,
212 sidePanelItems: state.sidePanel,
215 withStyles(styles)(Workbench)