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 ProjectPanel from '../project-panel/project-panel';
23 import { PROJECT_EXPLORER_ID } from '../../views-components/project-explorer/project-explorer';
24 import { ProjectExplorerItem } from '../../views-components/project-explorer/project-explorer-item';
25 import sidePanelActions from '../../store/side-panel/side-panel-action';
26 import { projectService } from '../../services/services';
27 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
29 const drawerWidth = 240;
30 const appBarHeight = 102;
32 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
34 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
45 zIndex: theme.zIndex.drawer + 1,
46 backgroundColor: '#692498',
54 flexDirection: 'column',
57 backgroundColor: theme.palette.background.default,
61 paddingTop: appBarHeight
64 padding: theme.spacing.unit * 3,
68 toolbar: theme.mixins.toolbar
71 interface WorkbenchDataProps {
72 projects: Array<TreeItem<Project>>;
74 sidePanelItems: SidePanelItem[];
77 interface WorkbenchActionProps {
80 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
82 interface NavBreadcrumb extends Breadcrumb {
84 status: TreeItemStatus;
87 interface NavMenuItem extends MainAppBarMenuItem {
91 interface WorkbenchState {
93 breadcrumbs: NavBreadcrumb[];
96 accountMenu: NavMenuItem[],
97 helpMenu: NavMenuItem[],
98 anonymousMenu: NavMenuItem[]
102 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
111 action: () => this.props.dispatch(authActions.LOGOUT())
115 action: () => this.props.dispatch(push("/my-account"))
121 action: () => this.props.dispatch(push("/help"))
127 action: () => this.props.dispatch(authActions.LOGIN())
134 mainAppBarActions: MainAppBarActionProps = {
135 onBreadcrumbClick: ({ itemId, status }: NavBreadcrumb) => {
136 this.toggleProjectTreeItemOpen(itemId, status);
138 onSearch: searchText => {
139 this.setState({ searchText });
140 this.props.dispatch(push(`/search?q=${searchText}`));
142 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
145 toggleProjectTreeItemOpen = (itemId: string, status: TreeItemStatus) => {
146 if (status === TreeItemStatus.Loaded) {
147 this.openProjectItem(itemId);
148 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
149 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
151 this.props.dispatch<any>(getProjectList(itemId))
153 this.openProjectItem(itemId);
154 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
155 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
160 toggleProjectTreeItemActive = (itemId: string, status: TreeItemStatus) => {
161 if (status === TreeItemStatus.Loaded) {
162 this.openProjectItem(itemId);
163 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
164 this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
166 this.props.dispatch<any>(getProjectList(itemId))
168 this.openProjectItem(itemId);
169 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
170 this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
175 toggleSidePanelOpen = (itemId: string) => {
176 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
179 toggleSidePanelActive = (itemId: string) => {
180 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
181 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
184 openProjectItem = (itemId: string) => {
185 const branch = getTreePath(this.props.projects, itemId);
187 breadcrumbs: branch.map(item => ({
188 label: item.data.name,
189 itemId: item.data.uuid,
193 this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
194 this.props.dispatch(push(`/project/${itemId}`));
196 const project = findTreeItem(this.props.projects, itemId);
197 const items: ProjectExplorerItem[] = project && project.items
198 ? project.items.map(({ data }) => ({
202 owner: data.ownerUuid,
203 lastModified: data.modifiedAt
206 this.props.dispatch(dataExplorerActions.SET_ITEMS({ id: PROJECT_EXPLORER_ID, items }));
210 const { classes, user, projects, sidePanelItems } = this.props;
212 <div className={classes.root}>
213 <div className={classes.appBar}>
215 breadcrumbs={this.state.breadcrumbs}
216 searchText={this.state.searchText}
217 user={this.props.user}
218 menuItems={this.state.menuItems}
219 {...this.mainAppBarActions}
226 paper: classes.drawerPaper,
228 <div className={classes.toolbar} />
230 toggleOpen={this.toggleSidePanelOpen}
231 toggleActive={this.toggleSidePanelActive}
232 sidePanelItems={sidePanelItems}>
235 toggleOpen={this.toggleProjectTreeItemOpen}
236 toggleActive={this.toggleProjectTreeItemActive} />
239 <main className={classes.contentWrapper}>
240 <div className={classes.content}>
242 <Route path="/project/:name" component={ProjectPanel} />
251 export default connect<WorkbenchDataProps>(
252 (state: RootState) => ({
253 projects: state.projects,
254 user: state.auth.user,
255 sidePanelItems: state.sidePanel,
258 withStyles(styles)(Workbench)