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 { authActions } 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";
28 import { authService } from '../../services/services';
30 import { detailsPanelActions, loadDetails } from "../../store/details-panel/details-panel-action";
31 import { contextMenuActions } from "../../store/context-menu/context-menu-actions";
32 import { SidePanelIdentifiers } from '../../store/side-panel/side-panel-reducer';
33 import { ProjectResource } from '../../models/project';
34 import { ResourceKind } from '../../models/resource';
35 import { ContextMenu, ContextMenuKind } from "../../views-components/context-menu/context-menu";
36 import { FavoritePanel } from "../favorite-panel/favorite-panel";
37 import { CurrentTokenDialog } from '../../views-components/current-token-dialog/current-token-dialog';
38 import { dataExplorerActions } from '../../store/data-explorer/data-explorer-action';
39 import { Snackbar } from '../../views-components/snackbar/snackbar';
40 import { favoritePanelActions } from '../../store/favorite-panel/favorite-panel-action';
41 import { CreateCollectionDialog } from '../../views-components/create-collection-dialog/create-collection-dialog';
42 import { CollectionPanel } from '../collection-panel/collection-panel';
43 import { loadCollection } from '../../store/collection-panel/collection-panel-action';
44 import { getCollectionUrl } from '../../models/collection';
45 import { RemoveDialog } from '../../views-components/remove-dialog/remove-dialog';
46 import { RenameDialog } from '../../views-components/rename-dialog/rename-dialog';
48 const drawerWidth = 240;
49 const appBarHeight = 100;
51 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
53 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
64 zIndex: theme.zIndex.drawer + 1,
72 flexDirection: 'column',
75 backgroundColor: theme.palette.background.default,
79 paddingTop: appBarHeight
82 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
86 toolbar: theme.mixins.toolbar
89 interface WorkbenchDataProps {
90 projects: Array<TreeItem<ProjectResource>>;
91 currentProjectId: string;
93 currentToken?: string;
94 sidePanelItems: SidePanelItem[];
97 interface WorkbenchActionProps {
100 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
102 interface NavBreadcrumb extends Breadcrumb {
106 interface NavMenuItem extends MainAppBarMenuItem {
110 interface WorkbenchState {
111 isCurrentTokenDialogOpen: boolean;
115 accountMenu: NavMenuItem[],
116 helpMenu: NavMenuItem[],
117 anonymousMenu: NavMenuItem[]
121 export const Workbench = withStyles(styles)(
122 connect<WorkbenchDataProps>(
123 (state: RootState) => ({
124 projects: state.projects.items,
125 currentProjectId: state.projects.currentItemId,
126 user: state.auth.user,
127 currentToken: state.auth.apiToken,
128 sidePanelItems: state.sidePanel
131 class extends React.Component<WorkbenchProps, WorkbenchState> {
133 isCreationDialogOpen: false,
134 isCurrentTokenDialogOpen: false,
141 label: 'Current token',
142 action: () => this.toggleCurrentTokenModal()
146 action: () => this.props.dispatch(authActions.LOGOUT())
150 action: () => this.props.dispatch(push("/my-account"))
156 action: () => this.props.dispatch(push("/help"))
162 action: () => this.props.dispatch(authActions.LOGIN())
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} />
191 paper: classes.drawerPaper,
193 <div className={classes.toolbar} />
195 toggleOpen={this.toggleSidePanelOpen}
196 toggleActive={this.toggleSidePanelActive}
197 sidePanelItems={this.props.sidePanelItems}
198 onContextMenu={(event) => this.openContextMenu(event, {
199 uuid: authService.getUuid() || "",
201 kind: ContextMenuKind.ROOT_PROJECT
204 projects={this.props.projects}
205 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
206 onContextMenu={(event, item) => this.openContextMenu(event, {
207 uuid: item.data.uuid,
208 name: item.data.name,
209 kind: ContextMenuKind.PROJECT
211 toggleActive={itemId => {
212 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE));
213 this.props.dispatch<any>(loadDetails(itemId, ResourceKind.PROJECT));
214 this.props.dispatch<any>(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
218 <main className={classes.contentWrapper}>
219 <div className={classes.content}>
221 <Route path="/projects/:id" render={this.renderProjectPanel} />
222 <Route path="/favorites" render={this.renderFavoritePanel} />
223 <Route path="/collections/:id" render={this.renderCollectionPanel} />
226 {user && <DetailsPanel />}
230 <CreateProjectDialog />
231 <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<any>(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<any>(loadDetails(item.uuid, item.kind as ResourceKind));
269 onItemDoubleClick={item => {
271 case ResourceKind.COLLECTION:
272 this.props.dispatch<any>(loadCollection(item.uuid, item.kind as ResourceKind));
273 this.props.dispatch(push(getCollectionUrl(item.uuid)));
275 this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
276 this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
282 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
283 onItemRouteChange={() => this.props.dispatch<any>(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<any>(loadDetails(item.uuid, item.kind as ResourceKind));
296 onItemDoubleClick={item => {
298 case ResourceKind.COLLECTION:
299 this.props.dispatch<any>(loadCollection(item.uuid, item.kind as ResourceKind));
300 this.props.dispatch(push(getCollectionUrl(item.uuid)));
302 this.props.dispatch<any>(loadDetails(item.uuid, ResourceKind.PROJECT));
303 this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
304 this.props.dispatch<any>(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
310 mainAppBarActions: MainAppBarActionProps = {
311 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
312 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
313 this.props.dispatch<any>(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 });