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, RouteComponentProps, Switch, Redirect } 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 { reset } from 'redux-form';
17 import { ProjectTree } from '~/views-components/project-tree/project-tree';
18 import { TreeItem } from "~/components/tree/tree";
19 import { getTreePath } from '~/store/project/project-reducer';
20 import { sidePanelActions } from '~/store/side-panel/side-panel-action';
21 import { SidePanel, SidePanelItem } from '~/components/side-panel/side-panel';
22 import { ItemMode, setProjectItem } from "~/store/navigation/navigation-action";
23 import { projectActions } from "~/store/project/project-action";
24 import { DetailsPanel } from '~/views-components/details-panel/details-panel';
25 import { ArvadosTheme } from '~/common/custom-theme';
27 import { detailsPanelActions, loadDetails } from "~/store/details-panel/details-panel-action";
28 import { contextMenuActions } from "~/store/context-menu/context-menu-actions";
29 import { ProjectResource } from '~/models/project';
30 import { ResourceKind } from '~/models/resource';
31 import { ProcessPanel } from '~/views/process-panel/process-panel';
32 import { ContextMenu, ContextMenuKind } from "~/views-components/context-menu/context-menu";
33 import { FavoritePanel } from "../favorite-panel/favorite-panel";
34 import { CurrentTokenDialog } from '~/views-components/current-token-dialog/current-token-dialog';
35 import { Snackbar } from '~/views-components/snackbar/snackbar';
36 import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action';
37 import { CollectionPanel } from '../collection-panel/collection-panel';
38 import { loadCollection, loadCollectionTags } from '~/store/collection-panel/collection-panel-action';
39 import { getCollectionUrl } from '~/models/collection';
41 import { PROJECT_CREATE_FORM_NAME, openProjectCreateDialog } from '~/store/projects/project-create-actions';
42 import { COLLECTION_CREATE_FORM_NAME, openCollectionCreateDialog } from '~/store/collections/collection-create-actions';
43 import { CreateCollectionDialog } from '~/views-components/dialog-forms/create-collection-dialog';
44 import { UpdateCollectionDialog } from '~/views-components/dialog-forms/update-collection-dialog';
45 import { CreateProjectDialog } from '~/views-components/dialog-forms/create-project-dialog';
46 import { UpdateProjectDialog } from '~/views-components/dialog-forms/update-project-dialog';
48 import { ProjectPanel } from "~/views/project-panel/project-panel";
49 import { AuthService } from "~/services/auth-service/auth-service";
50 import { RenameFileDialog } from '~/views-components/rename-file-dialog/rename-file-dialog';
51 import { FileRemoveDialog } from '~/views-components/file-remove-dialog/file-remove-dialog';
52 import { MultipleFilesRemoveDialog } from '~/views-components/file-remove-dialog/multiple-files-remove-dialog';
53 import { UploadCollectionFilesDialog } from '~/views-components/upload-collection-files-dialog/upload-collection-files-dialog';
54 import { CollectionPartialCopyDialog } from '~/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog';
55 import { MoveProjectDialog } from '~/views-components/dialog-forms/move-project-dialog';
56 import { MoveCollectionDialog } from '~/views-components/dialog-forms/move-collection-dialog';
57 import { CopyCollectionDialog } from '~/views-components/dialog-forms/copy-collection-dialog';
59 const DRAWER_WITDH = 240;
60 const APP_BAR_HEIGHT = 100;
62 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
64 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
75 zIndex: theme.zIndex.drawer + 1,
83 flexDirection: 'column',
86 backgroundColor: theme.palette.background.default,
90 paddingTop: APP_BAR_HEIGHT
93 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
98 toolbar: theme.mixins.toolbar
101 interface WorkbenchDataProps {
102 projects: Array<TreeItem<ProjectResource>>;
103 currentProjectId: string;
105 currentToken?: string;
106 sidePanelItems: SidePanelItem[];
109 interface WorkbenchGeneralProps {
110 authService: AuthService;
114 interface WorkbenchActionProps {
117 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
119 interface NavBreadcrumb extends Breadcrumb {
123 interface NavMenuItem extends MainAppBarMenuItem {
127 interface WorkbenchState {
128 isCurrentTokenDialogOpen: boolean;
132 accountMenu: NavMenuItem[],
133 helpMenu: NavMenuItem[],
134 anonymousMenu: NavMenuItem[]
138 export const Workbench = withStyles(styles)(
139 connect<WorkbenchDataProps>(
140 (state: RootState) => ({
141 projects: state.projects.items,
142 currentProjectId: state.projects.currentItemId,
143 user: state.auth.user,
144 currentToken: state.auth.apiToken,
145 sidePanelItems: state.sidePanel
148 class extends React.Component<WorkbenchProps, WorkbenchState> {
150 isCreationDialogOpen: false,
151 isCurrentTokenDialogOpen: false,
158 label: 'Current token',
159 action: () => this.toggleCurrentTokenModal()
163 action: () => this.props.dispatch(logout())
167 action: () => this.props.dispatch(push("/my-account"))
173 action: () => this.props.dispatch(push("/help"))
179 action: () => this.props.dispatch(login())
186 const path = getTreePath(this.props.projects, this.props.currentProjectId);
187 const breadcrumbs = path.map(item => ({
188 label: item.data.name,
189 itemId: item.data.uuid,
193 const { classes, user } = this.props;
195 <div className={classes.root}>
196 <div className={classes.appBar}>
198 breadcrumbs={breadcrumbs}
199 searchText={this.state.searchText}
200 user={this.props.user}
201 menuItems={this.state.menuItems}
202 buildInfo={this.props.buildInfo}
203 {...this.mainAppBarActions} />
209 paper: classes.drawerPaper,
211 <div className={classes.toolbar} />
213 toggleOpen={this.toggleSidePanelOpen}
214 toggleActive={this.toggleSidePanelActive}
215 sidePanelItems={this.props.sidePanelItems}
216 onContextMenu={(event) => this.openContextMenu(event, {
217 uuid: this.props.authService.getUuid() || "",
219 kind: ContextMenuKind.ROOT_PROJECT
222 projects={this.props.projects}
223 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
224 onContextMenu={(event, item) => this.openContextMenu(event, {
225 uuid: item.data.uuid,
226 name: item.data.name,
227 kind: ContextMenuKind.PROJECT
229 toggleActive={itemId => {
230 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
231 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
235 <main className={classes.contentWrapper}>
236 <div className={classes.content}>
238 <Route path='/' exact render={() => <Redirect to={`/projects/${this.props.authService.getUuid()}`} />} />
239 <Route path="/projects/:id" render={this.renderProjectPanel} />
240 <Route path="/favorites" render={this.renderFavoritePanel} />
241 <Route path="/collections/:id" render={this.renderCollectionPanel} />
242 <Route path="/process/:id" render={this.renderProcessPanel} />
245 {user && <DetailsPanel />}
249 <CreateProjectDialog />
250 <CreateCollectionDialog />
252 <CollectionPartialCopyDialog />
254 <CopyCollectionDialog />
255 <MultipleFilesRemoveDialog />
256 <UpdateCollectionDialog />
257 <UploadCollectionFilesDialog />
258 <UpdateProjectDialog />
259 <MoveCollectionDialog />
260 <MoveProjectDialog />
262 currentToken={this.props.currentToken}
263 open={this.state.isCurrentTokenDialogOpen}
264 handleClose={this.toggleCurrentTokenModal} />
269 renderProcessPanel = (props: RouteComponentProps<{ id: string }>) => <ProcessPanel
270 onContextMenu={(event, item) => {
271 this.openContextMenu(event, {
274 description: 'item.description',
275 kind: ContextMenuKind.PROCESS
280 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
281 onItemRouteChange={(collectionId) => {
282 this.props.dispatch<any>(loadCollection(collectionId));
283 this.props.dispatch<any>(loadCollectionTags(collectionId));
285 onContextMenu={(event, item) => {
286 this.openContextMenu(event, {
289 description: item.description,
290 kind: ContextMenuKind.COLLECTION
295 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
296 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
297 onContextMenu={(event, item) => {
298 let kind: ContextMenuKind;
300 if (item.kind === ResourceKind.PROJECT) {
301 kind = ContextMenuKind.PROJECT;
302 } else if (item.kind === ResourceKind.COLLECTION) {
303 kind = ContextMenuKind.COLLECTION_RESOURCE;
305 kind = ContextMenuKind.RESOURCE;
308 this.openContextMenu(event, {
311 description: item.description,
315 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
316 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
317 onItemClick={item => {
318 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
320 onItemDoubleClick={item => {
322 case ResourceKind.COLLECTION:
323 this.props.dispatch(loadCollection(item.uuid));
324 this.props.dispatch(push(getCollectionUrl(item.uuid)));
326 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
327 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
333 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
334 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
335 onContextMenu={(event, item) => {
336 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
337 this.openContextMenu(event, {
343 onDialogOpen={this.handleProjectCreationDialogOpen}
344 onItemClick={item => {
345 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
347 onItemDoubleClick={item => {
349 case ResourceKind.COLLECTION:
350 this.props.dispatch(loadCollection(item.uuid));
351 this.props.dispatch(push(getCollectionUrl(item.uuid)));
353 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
354 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
360 mainAppBarActions: MainAppBarActionProps = {
361 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
362 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
363 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
365 onSearch: searchText => {
366 this.setState({ searchText });
367 this.props.dispatch(push(`/search?q=${searchText}`));
369 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
370 onDetailsPanelToggle: () => {
371 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
373 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
374 this.openContextMenu(event, {
375 uuid: breadcrumb.itemId,
376 name: breadcrumb.label,
377 kind: ContextMenuKind.PROJECT
382 toggleSidePanelOpen = (itemId: string) => {
383 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
386 toggleSidePanelActive = (itemId: string) => {
387 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
389 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
390 if (panelItem && panelItem.activeAction) {
391 panelItem.activeAction(this.props.dispatch, this.props.authService.getUuid());
395 handleProjectCreationDialogOpen = (itemUuid: string) => {
396 this.props.dispatch(reset(PROJECT_CREATE_FORM_NAME));
397 this.props.dispatch<any>(openProjectCreateDialog(itemUuid));
400 handleCollectionCreationDialogOpen = (itemUuid: string) => {
401 this.props.dispatch(reset(COLLECTION_CREATE_FORM_NAME));
402 this.props.dispatch<any>(openCollectionCreateDialog(itemUuid));
405 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
406 event.preventDefault();
408 contextMenuActions.OPEN_CONTEXT_MENU({
409 position: { x: event.clientX, y: event.clientY },
415 toggleCurrentTokenModal = () => {
416 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });