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';
54 import { CollectionPartialCopyDialog } from '../../views-components/collection-partial-copy-dialog/collection-partial-copy-dialog';
56 const DRAWER_WITDH = 240;
57 const APP_BAR_HEIGHT = 100;
59 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
61 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
72 zIndex: theme.zIndex.drawer + 1,
80 flexDirection: 'column',
83 backgroundColor: theme.palette.background.default,
87 paddingTop: APP_BAR_HEIGHT
90 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
95 toolbar: theme.mixins.toolbar
98 interface WorkbenchDataProps {
99 projects: Array<TreeItem<ProjectResource>>;
100 currentProjectId: string;
102 currentToken?: string;
103 sidePanelItems: SidePanelItem[];
106 interface WorkbenchGeneralProps {
107 authService: AuthService;
111 interface WorkbenchActionProps {
114 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
116 interface NavBreadcrumb extends Breadcrumb {
120 interface NavMenuItem extends MainAppBarMenuItem {
124 interface WorkbenchState {
125 isCurrentTokenDialogOpen: boolean;
129 accountMenu: NavMenuItem[],
130 helpMenu: NavMenuItem[],
131 anonymousMenu: NavMenuItem[]
135 export const Workbench = withStyles(styles)(
136 connect<WorkbenchDataProps>(
137 (state: RootState) => ({
138 projects: state.projects.items,
139 currentProjectId: state.projects.currentItemId,
140 user: state.auth.user,
141 currentToken: state.auth.apiToken,
142 sidePanelItems: state.sidePanel
145 class extends React.Component<WorkbenchProps, WorkbenchState> {
147 isCreationDialogOpen: false,
148 isCurrentTokenDialogOpen: false,
155 label: 'Current token',
156 action: () => this.toggleCurrentTokenModal()
160 action: () => this.props.dispatch(logout())
164 action: () => this.props.dispatch(push("/my-account"))
170 action: () => this.props.dispatch(push("/help"))
176 action: () => this.props.dispatch(login())
183 const path = getTreePath(this.props.projects, this.props.currentProjectId);
184 const breadcrumbs = path.map(item => ({
185 label: item.data.name,
186 itemId: item.data.uuid,
190 const { classes, user } = this.props;
192 <div className={classes.root}>
193 <div className={classes.appBar}>
195 breadcrumbs={breadcrumbs}
196 searchText={this.state.searchText}
197 user={this.props.user}
198 menuItems={this.state.menuItems}
199 buildInfo={this.props.buildInfo}
200 {...this.mainAppBarActions} />
206 paper: classes.drawerPaper,
208 <div className={classes.toolbar} />
210 toggleOpen={this.toggleSidePanelOpen}
211 toggleActive={this.toggleSidePanelActive}
212 sidePanelItems={this.props.sidePanelItems}
213 onContextMenu={(event) => this.openContextMenu(event, {
214 uuid: this.props.authService.getUuid() || "",
216 kind: ContextMenuKind.ROOT_PROJECT
219 projects={this.props.projects}
220 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
221 onContextMenu={(event, item) => this.openContextMenu(event, {
222 uuid: item.data.uuid,
223 name: item.data.name,
224 kind: ContextMenuKind.PROJECT
226 toggleActive={itemId => {
227 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
228 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
232 <main className={classes.contentWrapper}>
233 <div className={classes.content}>
235 <Route path='/' exact render={() => <Redirect to={`/projects/${this.props.authService.getUuid()}`} />} />
236 <Route path="/projects/:id" render={this.renderProjectPanel} />
237 <Route path="/favorites" render={this.renderFavoritePanel} />
238 <Route path="/collections/:id" render={this.renderCollectionPanel} />
241 {user && <DetailsPanel />}
245 <CreateProjectDialog />
246 <CreateCollectionDialog />
248 <CollectionPartialCopyDialog />
249 <MoveToProjectDialog />
250 <DialogCollectionCreateWithSelectedFile />
252 <MultipleFilesRemoveDialog />
253 <UpdateCollectionDialog />
254 <UploadCollectionFilesDialog />
255 <UpdateProjectDialog />
257 currentToken={this.props.currentToken}
258 open={this.state.isCurrentTokenDialogOpen}
259 handleClose={this.toggleCurrentTokenModal} />
264 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
265 onItemRouteChange={(collectionId) => {
266 this.props.dispatch<any>(loadCollection(collectionId));
267 this.props.dispatch<any>(loadCollectionTags(collectionId));
269 onContextMenu={(event, item) => {
270 this.openContextMenu(event, {
273 description: item.description,
274 kind: ContextMenuKind.COLLECTION
279 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
280 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
281 onContextMenu={(event, item) => {
282 let kind: ContextMenuKind;
284 if (item.kind === ResourceKind.PROJECT) {
285 kind = ContextMenuKind.PROJECT;
286 } else if (item.kind === ResourceKind.COLLECTION) {
287 kind = ContextMenuKind.COLLECTION_RESOURCE;
289 kind = ContextMenuKind.RESOURCE;
292 this.openContextMenu(event, {
295 description: item.description,
299 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
300 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
301 onItemClick={item => {
302 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
304 onItemDoubleClick={item => {
306 case ResourceKind.COLLECTION:
307 this.props.dispatch(loadCollection(item.uuid));
308 this.props.dispatch(push(getCollectionUrl(item.uuid)));
310 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
311 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
317 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
318 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
319 onContextMenu={(event, item) => {
320 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
321 this.openContextMenu(event, {
327 onDialogOpen={this.handleProjectCreationDialogOpen}
328 onItemClick={item => {
329 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
331 onItemDoubleClick={item => {
333 case ResourceKind.COLLECTION:
334 this.props.dispatch(loadCollection(item.uuid));
335 this.props.dispatch(push(getCollectionUrl(item.uuid)));
337 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
338 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
344 mainAppBarActions: MainAppBarActionProps = {
345 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
346 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
347 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
349 onSearch: searchText => {
350 this.setState({ searchText });
351 this.props.dispatch(push(`/search?q=${searchText}`));
353 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
354 onDetailsPanelToggle: () => {
355 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
357 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
358 this.openContextMenu(event, {
359 uuid: breadcrumb.itemId,
360 name: breadcrumb.label,
361 kind: ContextMenuKind.PROJECT
366 toggleSidePanelOpen = (itemId: string) => {
367 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
370 toggleSidePanelActive = (itemId: string) => {
371 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
373 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
374 if (panelItem && panelItem.activeAction) {
375 panelItem.activeAction(this.props.dispatch, this.props.authService.getUuid());
379 handleProjectCreationDialogOpen = (itemUuid: string) => {
380 this.props.dispatch(reset(PROJECT_CREATE_DIALOG));
381 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
384 handleCollectionCreationDialogOpen = (itemUuid: string) => {
385 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
386 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
389 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
390 event.preventDefault();
392 contextMenuActions.OPEN_CONTEXT_MENU({
393 position: { x: event.clientX, y: event.clientY },
399 toggleCurrentTokenModal = () => {
400 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });