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 { login, logout } from "../../store/auth/auth-action";
11 import { User } from "../../models/user";
12 import { RootState } from "../../store/store";
13 import { MainAppBar, MainAppBarActionProps, MainAppBarMenuItem } from '../../views-components/main-app-bar/main-app-bar';
14 import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
15 import { push } from 'react-router-redux';
16 import { ProjectTree } from '../../views-components/project-tree/project-tree';
17 import { TreeItem } from "../../components/tree/tree";
18 import { getTreePath } from '../../store/project/project-reducer';
19 import { sidePanelActions } from '../../store/side-panel/side-panel-action';
20 import { SidePanel, SidePanelItem } from '../../components/side-panel/side-panel';
21 import { ItemMode, setProjectItem } from "../../store/navigation/navigation-action";
22 import { projectActions } from "../../store/project/project-action";
23 import { collectionCreateActions } from '../../store/collections/creator/collection-creator-action';
24 import { ProjectPanel } from "../project-panel/project-panel";
25 import { DetailsPanel } from '../../views-components/details-panel/details-panel';
26 import { ArvadosTheme } from '../../common/custom-theme';
27 import { CreateProjectDialog } from "../../views-components/create-project-dialog/create-project-dialog";
29 import { detailsPanelActions, loadDetails } from "../../store/details-panel/details-panel-action";
30 import { contextMenuActions } from "../../store/context-menu/context-menu-actions";
31 import { SidePanelIdentifiers } from '../../store/side-panel/side-panel-reducer';
32 import { ProjectResource } from '../../models/project';
33 import { ResourceKind } from '../../models/resource';
34 import { ContextMenu, ContextMenuKind } from "../../views-components/context-menu/context-menu";
35 import { FavoritePanel } from "../favorite-panel/favorite-panel";
36 import { CurrentTokenDialog } from '../../views-components/current-token-dialog/current-token-dialog';
37 import { dataExplorerActions } from '../../store/data-explorer/data-explorer-action';
38 import { Snackbar } from '../../views-components/snackbar/snackbar';
39 import { favoritePanelActions } from '../../store/favorite-panel/favorite-panel-action';
40 import { CreateCollectionDialog } from '../../views-components/create-collection-dialog/create-collection-dialog';
41 import { CollectionPanel } from '../collection-panel/collection-panel';
42 import { loadCollection } from '../../store/collection-panel/collection-panel-action';
43 import { getCollectionUrl } from '../../models/collection';
44 import { AuthService } from "../../services/auth-service/auth-service";
46 const DRAWER_WITDH = 240;
47 const APP_BAR_HEIGHT = 100;
49 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
51 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
62 zIndex: theme.zIndex.drawer + 1,
70 flexDirection: 'column',
73 backgroundColor: theme.palette.background.default,
77 paddingTop: APP_BAR_HEIGHT
80 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
84 toolbar: theme.mixins.toolbar
87 interface WorkbenchDataProps {
88 projects: Array<TreeItem<ProjectResource>>;
89 currentProjectId: string;
91 currentToken?: string;
92 sidePanelItems: SidePanelItem[];
95 interface WorkbenchServiceProps {
96 authService: AuthService;
99 interface WorkbenchActionProps {
102 type WorkbenchProps = WorkbenchDataProps & WorkbenchServiceProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
104 interface NavBreadcrumb extends Breadcrumb {
108 interface NavMenuItem extends MainAppBarMenuItem {
112 interface WorkbenchState {
113 isCurrentTokenDialogOpen: boolean;
117 accountMenu: NavMenuItem[],
118 helpMenu: NavMenuItem[],
119 anonymousMenu: NavMenuItem[]
123 export const Workbench = withStyles(styles)(
124 connect<WorkbenchDataProps>(
125 (state: RootState) => ({
126 projects: state.projects.items,
127 currentProjectId: state.projects.currentItemId,
128 user: state.auth.user,
129 currentToken: state.auth.apiToken,
130 sidePanelItems: state.sidePanel
133 class extends React.Component<WorkbenchProps, WorkbenchState> {
135 isCreationDialogOpen: false,
136 isCurrentTokenDialogOpen: false,
143 label: 'Current token',
144 action: () => this.toggleCurrentTokenModal()
148 action: () => this.props.dispatch(logout())
152 action: () => this.props.dispatch(push("/my-account"))
158 action: () => this.props.dispatch(push("/help"))
164 action: () => this.props.dispatch(login())
171 const path = getTreePath(this.props.projects, this.props.currentProjectId);
172 const breadcrumbs = path.map(item => ({
173 label: item.data.name,
174 itemId: item.data.uuid,
178 const { classes, user } = this.props;
180 <div className={classes.root}>
181 <div className={classes.appBar}>
183 breadcrumbs={breadcrumbs}
184 searchText={this.state.searchText}
185 user={this.props.user}
186 menuItems={this.state.menuItems}
187 {...this.mainAppBarActions} />
193 paper: classes.drawerPaper,
195 <div className={classes.toolbar} />
197 toggleOpen={this.toggleSidePanelOpen}
198 toggleActive={this.toggleSidePanelActive}
199 sidePanelItems={this.props.sidePanelItems}
200 onContextMenu={(event) => this.openContextMenu(event, {
201 uuid: this.props.authService.getUuid() || "",
203 kind: ContextMenuKind.ROOT_PROJECT
206 projects={this.props.projects}
207 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
208 onContextMenu={(event, item) => this.openContextMenu(event, {
209 uuid: item.data.uuid,
210 name: item.data.name,
211 kind: ContextMenuKind.PROJECT
213 toggleActive={itemId => {
214 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
215 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
216 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
220 <main className={classes.contentWrapper}>
221 <div className={classes.content}>
223 <Route path="/projects/:id" render={this.renderProjectPanel} />
224 <Route path="/favorites" render={this.renderFavoritePanel} />
225 <Route path="/collections/:id" render={this.renderCollectionPanel} />
228 {user && <DetailsPanel />}
232 <CreateProjectDialog />
233 <CreateCollectionDialog />
235 currentToken={this.props.currentToken}
236 open={this.state.isCurrentTokenDialogOpen}
237 handleClose={this.toggleCurrentTokenModal} />
242 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
243 onItemRouteChange={(collectionId) => this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION))}
244 onContextMenu={(event, item) => {
245 this.openContextMenu(event, {
248 kind: ContextMenuKind.COLLECTION
253 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
254 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
255 onContextMenu={(event, item) => {
257 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
258 this.openContextMenu(event, {
264 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
265 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
266 onItemClick={item => {
267 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
269 onItemDoubleClick={item => {
271 case ResourceKind.COLLECTION:
272 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
273 this.props.dispatch(push(getCollectionUrl(item.uuid)));
275 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
276 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
282 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
283 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
284 onContextMenu={(event, item) => {
285 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
286 this.openContextMenu(event, {
292 onDialogOpen={this.handleProjectCreationDialogOpen}
293 onItemClick={item => {
294 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
296 onItemDoubleClick={item => {
298 case ResourceKind.COLLECTION:
299 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
300 this.props.dispatch(push(getCollectionUrl(item.uuid)));
302 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
303 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
304 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
310 mainAppBarActions: MainAppBarActionProps = {
311 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
312 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
313 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
315 onSearch: searchText => {
316 this.setState({ searchText });
317 this.props.dispatch(push(`/search?q=${searchText}`));
319 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
320 onDetailsPanelToggle: () => {
321 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
323 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
324 this.openContextMenu(event, {
325 uuid: breadcrumb.itemId,
326 name: breadcrumb.label,
327 kind: ContextMenuKind.PROJECT
332 toggleSidePanelOpen = (itemId: string) => {
333 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
336 toggleSidePanelActive = (itemId: string) => {
337 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
338 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
339 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
340 if (panelItem && panelItem.activeAction) {
341 panelItem.activeAction(this.props.dispatch);
345 handleProjectCreationDialogOpen = (itemUuid: string) => {
346 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
349 handleCollectionCreationDialogOpen = (itemUuid: string) => {
350 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
353 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; kind: ContextMenuKind; }) => {
354 event.preventDefault();
356 contextMenuActions.OPEN_CONTEXT_MENU({
357 position: { x: event.clientX, y: event.clientY },
363 toggleCurrentTokenModal = () => {
364 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });