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 { MoveToProjectDialog } from '../../views-components/move-to-dialog/move-to-dialog';
51 import { COLLECTION_CREATE_DIALOG } from '~/views-components/dialog-create/dialog-collection-create';
52 import { PROJECT_CREATE_DIALOG } from '~/views-components/dialog-create/dialog-project-create';
53 import { UploadCollectionFilesDialog } from '~/views-components/upload-collection-files-dialog/upload-collection-files-dialog';
55 const DRAWER_WITDH = 240;
56 const APP_BAR_HEIGHT = 100;
58 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
60 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
71 zIndex: theme.zIndex.drawer + 1,
79 flexDirection: 'column',
82 backgroundColor: theme.palette.background.default,
86 paddingTop: APP_BAR_HEIGHT
89 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
94 toolbar: theme.mixins.toolbar
97 interface WorkbenchDataProps {
98 projects: Array<TreeItem<ProjectResource>>;
99 currentProjectId: string;
101 currentToken?: string;
102 sidePanelItems: SidePanelItem[];
105 interface WorkbenchGeneralProps {
106 authService: AuthService;
110 interface WorkbenchActionProps {
113 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
115 interface NavBreadcrumb extends Breadcrumb {
119 interface NavMenuItem extends MainAppBarMenuItem {
123 interface WorkbenchState {
124 isCurrentTokenDialogOpen: boolean;
128 accountMenu: NavMenuItem[],
129 helpMenu: NavMenuItem[],
130 anonymousMenu: NavMenuItem[]
134 export const Workbench = withStyles(styles)(
135 connect<WorkbenchDataProps>(
136 (state: RootState) => ({
137 projects: state.projects.items,
138 currentProjectId: state.projects.currentItemId,
139 user: state.auth.user,
140 currentToken: state.auth.apiToken,
141 sidePanelItems: state.sidePanel
144 class extends React.Component<WorkbenchProps, WorkbenchState> {
146 isCreationDialogOpen: false,
147 isCurrentTokenDialogOpen: false,
154 label: 'Current token',
155 action: () => this.toggleCurrentTokenModal()
159 action: () => this.props.dispatch(logout())
163 action: () => this.props.dispatch(push("/my-account"))
169 action: () => this.props.dispatch(push("/help"))
175 action: () => this.props.dispatch(login())
182 const path = getTreePath(this.props.projects, this.props.currentProjectId);
183 const breadcrumbs = path.map(item => ({
184 label: item.data.name,
185 itemId: item.data.uuid,
189 const { classes, user } = this.props;
191 <div className={classes.root}>
192 <div className={classes.appBar}>
194 breadcrumbs={breadcrumbs}
195 searchText={this.state.searchText}
196 user={this.props.user}
197 menuItems={this.state.menuItems}
198 buildInfo={this.props.buildInfo}
199 {...this.mainAppBarActions} />
205 paper: classes.drawerPaper,
207 <div className={classes.toolbar} />
209 toggleOpen={this.toggleSidePanelOpen}
210 toggleActive={this.toggleSidePanelActive}
211 sidePanelItems={this.props.sidePanelItems}
212 onContextMenu={(event) => this.openContextMenu(event, {
213 uuid: this.props.authService.getUuid() || "",
215 kind: ContextMenuKind.ROOT_PROJECT
218 projects={this.props.projects}
219 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
220 onContextMenu={(event, item) => this.openContextMenu(event, {
221 uuid: item.data.uuid,
222 name: item.data.name,
223 kind: ContextMenuKind.PROJECT
225 toggleActive={itemId => {
226 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
227 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
231 <main className={classes.contentWrapper}>
232 <div className={classes.content}>
234 <Route path='/' exact render={() => <Redirect to={`/projects/${this.props.authService.getUuid()}`} />} />
235 <Route path="/projects/:id" render={this.renderProjectPanel} />
236 <Route path="/favorites" render={this.renderFavoritePanel} />
237 <Route path="/collections/:id" render={this.renderCollectionPanel} />
240 {user && <DetailsPanel />}
244 <CreateProjectDialog />
245 <CreateCollectionDialog />
247 <MoveToProjectDialog />
248 <DialogCollectionCreateWithSelectedFile />
250 <MultipleFilesRemoveDialog />
251 <UpdateCollectionDialog />
252 <UploadCollectionFilesDialog />
253 <UpdateProjectDialog />
255 currentToken={this.props.currentToken}
256 open={this.state.isCurrentTokenDialogOpen}
257 handleClose={this.toggleCurrentTokenModal} />
262 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
263 onItemRouteChange={(collectionId) => {
264 this.props.dispatch<any>(loadCollection(collectionId));
265 this.props.dispatch<any>(loadCollectionTags(collectionId));
267 onContextMenu={(event, item) => {
268 this.openContextMenu(event, {
271 description: item.description,
272 kind: ContextMenuKind.COLLECTION
277 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
278 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
279 onContextMenu={(event, item) => {
280 let kind: ContextMenuKind;
282 if (item.kind === ResourceKind.PROJECT) {
283 kind = ContextMenuKind.PROJECT;
284 } else if (item.kind === ResourceKind.COLLECTION) {
285 kind = ContextMenuKind.COLLECTION_RESOURCE;
287 kind = ContextMenuKind.RESOURCE;
290 this.openContextMenu(event, {
293 description: item.description,
297 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
298 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
299 onItemClick={item => {
300 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
302 onItemDoubleClick={item => {
304 case ResourceKind.COLLECTION:
305 this.props.dispatch(loadCollection(item.uuid));
306 this.props.dispatch(push(getCollectionUrl(item.uuid)));
308 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
309 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
315 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
316 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
317 onContextMenu={(event, item) => {
318 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
319 this.openContextMenu(event, {
325 onDialogOpen={this.handleProjectCreationDialogOpen}
326 onItemClick={item => {
327 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
329 onItemDoubleClick={item => {
331 case ResourceKind.COLLECTION:
332 this.props.dispatch(loadCollection(item.uuid));
333 this.props.dispatch(push(getCollectionUrl(item.uuid)));
335 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
336 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
342 mainAppBarActions: MainAppBarActionProps = {
343 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
344 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
345 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
347 onSearch: searchText => {
348 this.setState({ searchText });
349 this.props.dispatch(push(`/search?q=${searchText}`));
351 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
352 onDetailsPanelToggle: () => {
353 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
355 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
356 this.openContextMenu(event, {
357 uuid: breadcrumb.itemId,
358 name: breadcrumb.label,
359 kind: ContextMenuKind.PROJECT
364 toggleSidePanelOpen = (itemId: string) => {
365 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
368 toggleSidePanelActive = (itemId: string) => {
369 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
371 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
372 if (panelItem && panelItem.activeAction) {
373 panelItem.activeAction(this.props.dispatch, this.props.authService.getUuid());
377 handleProjectCreationDialogOpen = (itemUuid: string) => {
378 this.props.dispatch(reset(PROJECT_CREATE_DIALOG));
379 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
382 handleCollectionCreationDialogOpen = (itemUuid: string) => {
383 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
384 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
387 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
388 event.preventDefault();
390 contextMenuActions.OPEN_CONTEXT_MENU({
391 position: { x: event.clientX, y: event.clientY },
397 toggleCurrentTokenModal = () => {
398 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });