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 { ProjectCopyDialog } from '~/views-components/project-copy-dialog/project-copy-dialog';
54 import { CollectionPartialCopyDialog } from '../../views-components/collection-partial-copy-dialog/collection-partial-copy-dialog';
55 import { MoveProjectDialog } from '~/views-components/move-project-dialog/move-project-dialog';
56 import { MoveCollectionDialog } from '~/views-components/move-collection-dialog/move-collection-dialog';
58 const DRAWER_WITDH = 240;
59 const APP_BAR_HEIGHT = 100;
61 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
63 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
74 zIndex: theme.zIndex.drawer + 1,
82 flexDirection: 'column',
85 backgroundColor: theme.palette.background.default,
89 paddingTop: APP_BAR_HEIGHT
92 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
97 toolbar: theme.mixins.toolbar
100 interface WorkbenchDataProps {
101 projects: Array<TreeItem<ProjectResource>>;
102 currentProjectId: string;
104 currentToken?: string;
105 sidePanelItems: SidePanelItem[];
108 interface WorkbenchGeneralProps {
109 authService: AuthService;
113 interface WorkbenchActionProps {
116 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
118 interface NavBreadcrumb extends Breadcrumb {
122 interface NavMenuItem extends MainAppBarMenuItem {
126 interface WorkbenchState {
127 isCurrentTokenDialogOpen: boolean;
131 accountMenu: NavMenuItem[],
132 helpMenu: NavMenuItem[],
133 anonymousMenu: NavMenuItem[]
137 export const Workbench = withStyles(styles)(
138 connect<WorkbenchDataProps>(
139 (state: RootState) => ({
140 projects: state.projects.items,
141 currentProjectId: state.projects.currentItemId,
142 user: state.auth.user,
143 currentToken: state.auth.apiToken,
144 sidePanelItems: state.sidePanel
147 class extends React.Component<WorkbenchProps, WorkbenchState> {
149 isCreationDialogOpen: false,
150 isCurrentTokenDialogOpen: false,
157 label: 'Current token',
158 action: () => this.toggleCurrentTokenModal()
162 action: () => this.props.dispatch(logout())
166 action: () => this.props.dispatch(push("/my-account"))
172 action: () => this.props.dispatch(push("/help"))
178 action: () => this.props.dispatch(login())
185 const path = getTreePath(this.props.projects, this.props.currentProjectId);
186 const breadcrumbs = path.map(item => ({
187 label: item.data.name,
188 itemId: item.data.uuid,
192 const { classes, user } = this.props;
194 <div className={classes.root}>
195 <div className={classes.appBar}>
197 breadcrumbs={breadcrumbs}
198 searchText={this.state.searchText}
199 user={this.props.user}
200 menuItems={this.state.menuItems}
201 buildInfo={this.props.buildInfo}
202 {...this.mainAppBarActions} />
208 paper: classes.drawerPaper,
210 <div className={classes.toolbar} />
212 toggleOpen={this.toggleSidePanelOpen}
213 toggleActive={this.toggleSidePanelActive}
214 sidePanelItems={this.props.sidePanelItems}
215 onContextMenu={(event) => this.openContextMenu(event, {
216 uuid: this.props.authService.getUuid() || "",
218 kind: ContextMenuKind.ROOT_PROJECT
221 projects={this.props.projects}
222 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
223 onContextMenu={(event, item) => this.openContextMenu(event, {
224 uuid: item.data.uuid,
225 name: item.data.name,
226 kind: ContextMenuKind.PROJECT
228 toggleActive={itemId => {
229 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
230 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
234 <main className={classes.contentWrapper}>
235 <div className={classes.content}>
237 <Route path='/' exact render={() => <Redirect to={`/projects/${this.props.authService.getUuid()}`} />} />
238 <Route path="/projects/:id" render={this.renderProjectPanel} />
239 <Route path="/favorites" render={this.renderFavoritePanel} />
240 <Route path="/collections/:id" render={this.renderCollectionPanel} />
243 {user && <DetailsPanel />}
247 <CreateProjectDialog />
248 <CreateCollectionDialog />
250 <CollectionPartialCopyDialog />
251 <DialogCollectionCreateWithSelectedFile />
253 <ProjectCopyDialog />
254 <MultipleFilesRemoveDialog />
255 <UpdateCollectionDialog />
256 <UploadCollectionFilesDialog />
257 <UpdateProjectDialog />
258 <MoveCollectionDialog />
259 <MoveProjectDialog />
261 currentToken={this.props.currentToken}
262 open={this.state.isCurrentTokenDialogOpen}
263 handleClose={this.toggleCurrentTokenModal} />
268 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
269 onItemRouteChange={(collectionId) => {
270 this.props.dispatch<any>(loadCollection(collectionId));
271 this.props.dispatch<any>(loadCollectionTags(collectionId));
273 onContextMenu={(event, item) => {
274 this.openContextMenu(event, {
277 description: item.description,
278 kind: ContextMenuKind.COLLECTION
283 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
284 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
285 onContextMenu={(event, item) => {
286 let kind: ContextMenuKind;
288 if (item.kind === ResourceKind.PROJECT) {
289 kind = ContextMenuKind.PROJECT;
290 } else if (item.kind === ResourceKind.COLLECTION) {
291 kind = ContextMenuKind.COLLECTION_RESOURCE;
293 kind = ContextMenuKind.RESOURCE;
296 this.openContextMenu(event, {
299 description: item.description,
303 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
304 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
305 onItemClick={item => {
306 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
308 onItemDoubleClick={item => {
310 case ResourceKind.COLLECTION:
311 this.props.dispatch(loadCollection(item.uuid));
312 this.props.dispatch(push(getCollectionUrl(item.uuid)));
314 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
315 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
321 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
322 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
323 onContextMenu={(event, item) => {
324 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
325 this.openContextMenu(event, {
331 onDialogOpen={this.handleProjectCreationDialogOpen}
332 onItemClick={item => {
333 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
335 onItemDoubleClick={item => {
337 case ResourceKind.COLLECTION:
338 this.props.dispatch(loadCollection(item.uuid));
339 this.props.dispatch(push(getCollectionUrl(item.uuid)));
341 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
342 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
348 mainAppBarActions: MainAppBarActionProps = {
349 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
350 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
351 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
353 onSearch: searchText => {
354 this.setState({ searchText });
355 this.props.dispatch(push(`/search?q=${searchText}`));
357 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
358 onDetailsPanelToggle: () => {
359 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
361 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
362 this.openContextMenu(event, {
363 uuid: breadcrumb.itemId,
364 name: breadcrumb.label,
365 kind: ContextMenuKind.PROJECT
370 toggleSidePanelOpen = (itemId: string) => {
371 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
374 toggleSidePanelActive = (itemId: string) => {
375 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
377 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
378 if (panelItem && panelItem.activeAction) {
379 panelItem.activeAction(this.props.dispatch, this.props.authService.getUuid());
383 handleProjectCreationDialogOpen = (itemUuid: string) => {
384 this.props.dispatch(reset(PROJECT_CREATE_DIALOG));
385 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
388 handleCollectionCreationDialogOpen = (itemUuid: string) => {
389 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
390 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
393 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
394 event.preventDefault();
396 contextMenuActions.OPEN_CONTEXT_MENU({
397 position: { x: event.clientX, y: event.clientY },
403 toggleCurrentTokenModal = () => {
404 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });