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 { COLLECTION_CREATE_DIALOG } from '~/views-components/dialog-create/dialog-collection-create';
50 import { PROJECT_CREATE_DIALOG } from '~/views-components/dialog-create/dialog-project-create';
51 import { UploadCollectionFilesDialog } from '~/views-components/upload-collection-files-dialog/upload-collection-files-dialog';
52 import { CollectionPartialCopyDialog } from '../../views-components/collection-partial-copy-dialog/collection-partial-copy-dialog';
54 const DRAWER_WITDH = 240;
55 const APP_BAR_HEIGHT = 100;
57 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
59 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
70 zIndex: theme.zIndex.drawer + 1,
78 flexDirection: 'column',
81 backgroundColor: theme.palette.background.default,
85 paddingTop: APP_BAR_HEIGHT
88 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
93 toolbar: theme.mixins.toolbar
96 interface WorkbenchDataProps {
97 projects: Array<TreeItem<ProjectResource>>;
98 currentProjectId: string;
100 currentToken?: string;
101 sidePanelItems: SidePanelItem[];
104 interface WorkbenchGeneralProps {
105 authService: AuthService;
109 interface WorkbenchActionProps {
112 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
114 interface NavBreadcrumb extends Breadcrumb {
118 interface NavMenuItem extends MainAppBarMenuItem {
122 interface WorkbenchState {
123 isCurrentTokenDialogOpen: boolean;
127 accountMenu: NavMenuItem[],
128 helpMenu: NavMenuItem[],
129 anonymousMenu: NavMenuItem[]
133 export const Workbench = withStyles(styles)(
134 connect<WorkbenchDataProps>(
135 (state: RootState) => ({
136 projects: state.projects.items,
137 currentProjectId: state.projects.currentItemId,
138 user: state.auth.user,
139 currentToken: state.auth.apiToken,
140 sidePanelItems: state.sidePanel
143 class extends React.Component<WorkbenchProps, WorkbenchState> {
145 isCreationDialogOpen: false,
146 isCurrentTokenDialogOpen: false,
153 label: 'Current token',
154 action: () => this.toggleCurrentTokenModal()
158 action: () => this.props.dispatch(logout())
162 action: () => this.props.dispatch(push("/my-account"))
168 action: () => this.props.dispatch(push("/help"))
174 action: () => this.props.dispatch(login())
181 const path = getTreePath(this.props.projects, this.props.currentProjectId);
182 const breadcrumbs = path.map(item => ({
183 label: item.data.name,
184 itemId: item.data.uuid,
188 const { classes, user } = this.props;
190 <div className={classes.root}>
191 <div className={classes.appBar}>
193 breadcrumbs={breadcrumbs}
194 searchText={this.state.searchText}
195 user={this.props.user}
196 menuItems={this.state.menuItems}
197 buildInfo={this.props.buildInfo}
198 {...this.mainAppBarActions} />
204 paper: classes.drawerPaper,
206 <div className={classes.toolbar} />
208 toggleOpen={this.toggleSidePanelOpen}
209 toggleActive={this.toggleSidePanelActive}
210 sidePanelItems={this.props.sidePanelItems}
211 onContextMenu={(event) => this.openContextMenu(event, {
212 uuid: this.props.authService.getUuid() || "",
214 kind: ContextMenuKind.ROOT_PROJECT
217 projects={this.props.projects}
218 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
219 onContextMenu={(event, item) => this.openContextMenu(event, {
220 uuid: item.data.uuid,
221 name: item.data.name,
222 kind: ContextMenuKind.PROJECT
224 toggleActive={itemId => {
225 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
226 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
230 <main className={classes.contentWrapper}>
231 <div className={classes.content}>
233 <Route path='/' exact render={() => <Redirect to={`/projects/${this.props.authService.getUuid()}`} />} />
234 <Route path="/projects/:id" render={this.renderProjectPanel} />
235 <Route path="/favorites" render={this.renderFavoritePanel} />
236 <Route path="/collections/:id" render={this.renderCollectionPanel} />
239 {user && <DetailsPanel />}
243 <CreateProjectDialog />
244 <CreateCollectionDialog />
246 <CollectionPartialCopyDialog />
248 <MultipleFilesRemoveDialog />
249 <UpdateCollectionDialog />
250 <UploadCollectionFilesDialog />
251 <UpdateProjectDialog />
253 currentToken={this.props.currentToken}
254 open={this.state.isCurrentTokenDialogOpen}
255 handleClose={this.toggleCurrentTokenModal} />
260 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
261 onItemRouteChange={(collectionId) => {
262 this.props.dispatch<any>(loadCollection(collectionId));
263 this.props.dispatch<any>(loadCollectionTags(collectionId));
265 onContextMenu={(event, item) => {
266 this.openContextMenu(event, {
269 description: item.description,
270 kind: ContextMenuKind.COLLECTION
275 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
276 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
277 onContextMenu={(event, item) => {
278 let kind: ContextMenuKind;
280 if (item.kind === ResourceKind.PROJECT) {
281 kind = ContextMenuKind.PROJECT;
282 } else if (item.kind === ResourceKind.COLLECTION) {
283 kind = ContextMenuKind.COLLECTION_RESOURCE;
285 kind = ContextMenuKind.RESOURCE;
288 this.openContextMenu(event, {
291 description: item.description,
295 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
296 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
297 onItemClick={item => {
298 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
300 onItemDoubleClick={item => {
302 case ResourceKind.COLLECTION:
303 this.props.dispatch(loadCollection(item.uuid));
304 this.props.dispatch(push(getCollectionUrl(item.uuid)));
306 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
307 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
313 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
314 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
315 onContextMenu={(event, item) => {
316 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
317 this.openContextMenu(event, {
323 onDialogOpen={this.handleProjectCreationDialogOpen}
324 onItemClick={item => {
325 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
327 onItemDoubleClick={item => {
329 case ResourceKind.COLLECTION:
330 this.props.dispatch(loadCollection(item.uuid));
331 this.props.dispatch(push(getCollectionUrl(item.uuid)));
333 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
334 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
340 mainAppBarActions: MainAppBarActionProps = {
341 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
342 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
343 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
345 onSearch: searchText => {
346 this.setState({ searchText });
347 this.props.dispatch(push(`/search?q=${searchText}`));
349 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
350 onDetailsPanelToggle: () => {
351 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
353 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
354 this.openContextMenu(event, {
355 uuid: breadcrumb.itemId,
356 name: breadcrumb.label,
357 kind: ContextMenuKind.PROJECT
362 toggleSidePanelOpen = (itemId: string) => {
363 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
366 toggleSidePanelActive = (itemId: string) => {
367 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
369 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
370 if (panelItem && panelItem.activeAction) {
371 panelItem.activeAction(this.props.dispatch, this.props.authService.getUuid());
375 handleProjectCreationDialogOpen = (itemUuid: string) => {
376 this.props.dispatch(reset(PROJECT_CREATE_DIALOG));
377 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
380 handleCollectionCreationDialogOpen = (itemUuid: string) => {
381 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
382 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
385 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
386 event.preventDefault();
388 contextMenuActions.OPEN_CONTEXT_MENU({
389 position: { x: event.clientX, y: event.clientY },
395 toggleCurrentTokenModal = () => {
396 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });