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 { collectionCreateActions } from '~/store/collections/creator/collection-creator-action';
25 import { ProjectPanel } from "~/views/project-panel/project-panel";
26 import { DetailsPanel } from '~/views-components/details-panel/details-panel';
27 import { ArvadosTheme } from '~/common/custom-theme';
28 import { CreateProjectDialog } from "~/views-components/create-project-dialog/create-project-dialog";
30 import { detailsPanelActions, loadDetails } from "~/store/details-panel/details-panel-action";
31 import { contextMenuActions } from "~/store/context-menu/context-menu-actions";
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 { Snackbar } from '~/views-components/snackbar/snackbar';
38 import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action';
39 import { CreateCollectionDialog } from '~/views-components/create-collection-dialog/create-collection-dialog';
40 import { CollectionPanel } from '../collection-panel/collection-panel';
41 import { loadCollection, loadCollectionTags } from '~/store/collection-panel/collection-panel-action';
42 import { getCollectionUrl } from '~/models/collection';
43 import { UpdateCollectionDialog } from '~/views-components/update-collection-dialog/update-collection-dialog.';
44 import { UpdateProjectDialog } from '~/views-components/update-project-dialog/update-project-dialog';
45 import { AuthService } from "~/services/auth-service/auth-service";
46 import { RenameFileDialog } from '~/views-components/rename-file-dialog/rename-file-dialog';
47 import { FileRemoveDialog } from '~/views-components/file-remove-dialog/file-remove-dialog';
48 import { MultipleFilesRemoveDialog } from '~/views-components/file-remove-dialog/multiple-files-remove-dialog';
49 import { DialogCollectionCreateWithSelectedFile } from '~/views-components/create-collection-dialog-with-selected/create-collection-dialog-with-selected';
50 import { COLLECTION_CREATE_DIALOG } from '~/views-components/dialog-create/dialog-collection-create';
51 import { PROJECT_CREATE_DIALOG } from '~/views-components/dialog-create/dialog-project-create';
52 import { UploadCollectionFilesDialog } from '~/views-components/upload-collection-files-dialog/upload-collection-files-dialog';
53 import { CollectionPartialCopyDialog } from '../../views-components/collection-partial-copy-dialog/collection-partial-copy-dialog';
54 import { MoveProjectDialog } from '~/views-components/move-project-dialog/move-project-dialog';
55 import { MoveCollectionDialog } from '~/views-components/move-collection-dialog/move-collection-dialog';
57 const DRAWER_WITDH = 240;
58 const APP_BAR_HEIGHT = 100;
60 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
62 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
73 zIndex: theme.zIndex.drawer + 1,
81 flexDirection: 'column',
84 backgroundColor: theme.palette.background.default,
88 paddingTop: APP_BAR_HEIGHT
91 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
96 toolbar: theme.mixins.toolbar
99 interface WorkbenchDataProps {
100 projects: Array<TreeItem<ProjectResource>>;
101 currentProjectId: string;
103 currentToken?: string;
104 sidePanelItems: SidePanelItem[];
107 interface WorkbenchGeneralProps {
108 authService: AuthService;
112 interface WorkbenchActionProps {
115 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
117 interface NavBreadcrumb extends Breadcrumb {
121 interface NavMenuItem extends MainAppBarMenuItem {
125 interface WorkbenchState {
126 isCurrentTokenDialogOpen: boolean;
130 accountMenu: NavMenuItem[],
131 helpMenu: NavMenuItem[],
132 anonymousMenu: NavMenuItem[]
136 export const Workbench = withStyles(styles)(
137 connect<WorkbenchDataProps>(
138 (state: RootState) => ({
139 projects: state.projects.items,
140 currentProjectId: state.projects.currentItemId,
141 user: state.auth.user,
142 currentToken: state.auth.apiToken,
143 sidePanelItems: state.sidePanel
146 class extends React.Component<WorkbenchProps, WorkbenchState> {
148 isCreationDialogOpen: false,
149 isCurrentTokenDialogOpen: false,
156 label: 'Current token',
157 action: () => this.toggleCurrentTokenModal()
161 action: () => this.props.dispatch(logout())
165 action: () => this.props.dispatch(push("/my-account"))
171 action: () => this.props.dispatch(push("/help"))
177 action: () => this.props.dispatch(login())
184 const path = getTreePath(this.props.projects, this.props.currentProjectId);
185 const breadcrumbs = path.map(item => ({
186 label: item.data.name,
187 itemId: item.data.uuid,
191 const { classes, user } = this.props;
193 <div className={classes.root}>
194 <div className={classes.appBar}>
196 breadcrumbs={breadcrumbs}
197 searchText={this.state.searchText}
198 user={this.props.user}
199 menuItems={this.state.menuItems}
200 buildInfo={this.props.buildInfo}
201 {...this.mainAppBarActions} />
207 paper: classes.drawerPaper,
209 <div className={classes.toolbar} />
211 toggleOpen={this.toggleSidePanelOpen}
212 toggleActive={this.toggleSidePanelActive}
213 sidePanelItems={this.props.sidePanelItems}
214 onContextMenu={(event) => this.openContextMenu(event, {
215 uuid: this.props.authService.getUuid() || "",
217 kind: ContextMenuKind.ROOT_PROJECT
220 projects={this.props.projects}
221 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
222 onContextMenu={(event, item) => this.openContextMenu(event, {
223 uuid: item.data.uuid,
224 name: item.data.name,
225 kind: ContextMenuKind.PROJECT
227 toggleActive={itemId => {
228 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
229 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
233 <main className={classes.contentWrapper}>
234 <div className={classes.content}>
236 <Route path='/' exact render={() => <Redirect to={`/projects/${this.props.authService.getUuid()}`} />} />
237 <Route path="/projects/:id" render={this.renderProjectPanel} />
238 <Route path="/favorites" render={this.renderFavoritePanel} />
239 <Route path="/collections/:id" render={this.renderCollectionPanel} />
242 {user && <DetailsPanel />}
246 <CreateProjectDialog />
247 <CreateCollectionDialog />
249 <CollectionPartialCopyDialog />
250 <DialogCollectionCreateWithSelectedFile />
252 <MultipleFilesRemoveDialog />
253 <UpdateCollectionDialog />
254 <UploadCollectionFilesDialog />
255 <UpdateProjectDialog />
256 <MoveCollectionDialog />
257 <MoveProjectDialog />
259 currentToken={this.props.currentToken}
260 open={this.state.isCurrentTokenDialogOpen}
261 handleClose={this.toggleCurrentTokenModal} />
266 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
267 onItemRouteChange={(collectionId) => {
268 this.props.dispatch<any>(loadCollection(collectionId));
269 this.props.dispatch<any>(loadCollectionTags(collectionId));
271 onContextMenu={(event, item) => {
272 this.openContextMenu(event, {
275 description: item.description,
276 kind: ContextMenuKind.COLLECTION
281 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
282 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
283 onContextMenu={(event, item) => {
284 let kind: ContextMenuKind;
286 if (item.kind === ResourceKind.PROJECT) {
287 kind = ContextMenuKind.PROJECT;
288 } else if (item.kind === ResourceKind.COLLECTION) {
289 kind = ContextMenuKind.COLLECTION_RESOURCE;
291 kind = ContextMenuKind.RESOURCE;
294 this.openContextMenu(event, {
297 description: item.description,
301 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
302 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
303 onItemClick={item => {
304 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
306 onItemDoubleClick={item => {
308 case ResourceKind.COLLECTION:
309 this.props.dispatch(loadCollection(item.uuid));
310 this.props.dispatch(push(getCollectionUrl(item.uuid)));
312 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
313 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
319 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
320 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
321 onContextMenu={(event, item) => {
322 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
323 this.openContextMenu(event, {
329 onDialogOpen={this.handleProjectCreationDialogOpen}
330 onItemClick={item => {
331 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
333 onItemDoubleClick={item => {
335 case ResourceKind.COLLECTION:
336 this.props.dispatch(loadCollection(item.uuid));
337 this.props.dispatch(push(getCollectionUrl(item.uuid)));
339 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
340 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
346 mainAppBarActions: MainAppBarActionProps = {
347 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
348 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
349 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
351 onSearch: searchText => {
352 this.setState({ searchText });
353 this.props.dispatch(push(`/search?q=${searchText}`));
355 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
356 onDetailsPanelToggle: () => {
357 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
359 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
360 this.openContextMenu(event, {
361 uuid: breadcrumb.itemId,
362 name: breadcrumb.label,
363 kind: ContextMenuKind.PROJECT
368 toggleSidePanelOpen = (itemId: string) => {
369 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
372 toggleSidePanelActive = (itemId: string) => {
373 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
375 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
376 if (panelItem && panelItem.activeAction) {
377 panelItem.activeAction(this.props.dispatch, this.props.authService.getUuid());
381 handleProjectCreationDialogOpen = (itemUuid: string) => {
382 this.props.dispatch(reset(PROJECT_CREATE_DIALOG));
383 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
386 handleCollectionCreationDialogOpen = (itemUuid: string) => {
387 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
388 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
391 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
392 event.preventDefault();
394 contextMenuActions.OPEN_CONTEXT_MENU({
395 position: { x: event.clientX, y: event.clientY },
401 toggleCurrentTokenModal = () => {
402 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });