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';
53 const DRAWER_WITDH = 240;
54 const APP_BAR_HEIGHT = 100;
56 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
58 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
69 zIndex: theme.zIndex.drawer + 1,
77 flexDirection: 'column',
80 backgroundColor: theme.palette.background.default,
84 paddingTop: APP_BAR_HEIGHT
87 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
92 toolbar: theme.mixins.toolbar
95 interface WorkbenchDataProps {
96 projects: Array<TreeItem<ProjectResource>>;
97 currentProjectId: string;
99 currentToken?: string;
100 sidePanelItems: SidePanelItem[];
103 interface WorkbenchServiceProps {
104 authService: AuthService;
107 interface WorkbenchActionProps {
110 type WorkbenchProps = WorkbenchDataProps & WorkbenchServiceProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
112 interface NavBreadcrumb extends Breadcrumb {
116 interface NavMenuItem extends MainAppBarMenuItem {
120 interface WorkbenchState {
121 isCurrentTokenDialogOpen: boolean;
125 accountMenu: NavMenuItem[],
126 helpMenu: NavMenuItem[],
127 anonymousMenu: NavMenuItem[]
131 export const Workbench = withStyles(styles)(
132 connect<WorkbenchDataProps>(
133 (state: RootState) => ({
134 projects: state.projects.items,
135 currentProjectId: state.projects.currentItemId,
136 user: state.auth.user,
137 currentToken: state.auth.apiToken,
138 sidePanelItems: state.sidePanel
141 class extends React.Component<WorkbenchProps, WorkbenchState> {
143 isCreationDialogOpen: false,
144 isCurrentTokenDialogOpen: false,
151 label: 'Current token',
152 action: () => this.toggleCurrentTokenModal()
156 action: () => this.props.dispatch(logout())
160 action: () => this.props.dispatch(push("/my-account"))
166 action: () => this.props.dispatch(push("/help"))
172 action: () => this.props.dispatch(login())
179 const path = getTreePath(this.props.projects, this.props.currentProjectId);
180 const breadcrumbs = path.map(item => ({
181 label: item.data.name,
182 itemId: item.data.uuid,
186 const { classes, user } = this.props;
188 <div className={classes.root}>
189 <div className={classes.appBar}>
191 breadcrumbs={breadcrumbs}
192 searchText={this.state.searchText}
193 user={this.props.user}
194 menuItems={this.state.menuItems}
195 {...this.mainAppBarActions} />
201 paper: classes.drawerPaper,
203 <div className={classes.toolbar} />
205 toggleOpen={this.toggleSidePanelOpen}
206 toggleActive={this.toggleSidePanelActive}
207 sidePanelItems={this.props.sidePanelItems}
208 onContextMenu={(event) => this.openContextMenu(event, {
209 uuid: this.props.authService.getUuid() || "",
211 kind: ContextMenuKind.ROOT_PROJECT
214 projects={this.props.projects}
215 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
216 onContextMenu={(event, item) => this.openContextMenu(event, {
217 uuid: item.data.uuid,
218 name: item.data.name,
219 kind: ContextMenuKind.PROJECT
221 toggleActive={itemId => {
222 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
223 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
227 <main className={classes.contentWrapper}>
228 <div className={classes.content}>
230 <Route path='/' exact render={() => <Redirect to={`/projects/${this.props.authService.getUuid()}`} />} />
231 <Route path="/projects/:id" render={this.renderProjectPanel} />
232 <Route path="/favorites" render={this.renderFavoritePanel} />
233 <Route path="/collections/:id" render={this.renderCollectionPanel} />
236 {user && <DetailsPanel />}
240 <CreateProjectDialog />
241 <CreateCollectionDialog />
243 <DialogCollectionCreateWithSelectedFile />
245 <MultipleFilesRemoveDialog />
246 <UpdateCollectionDialog />
247 <UpdateProjectDialog />
249 currentToken={this.props.currentToken}
250 open={this.state.isCurrentTokenDialogOpen}
251 handleClose={this.toggleCurrentTokenModal} />
256 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
257 onItemRouteChange={(collectionId) => {
258 this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION));
259 this.props.dispatch<any>(loadCollectionTags(collectionId));
261 onContextMenu={(event, item) => {
262 this.openContextMenu(event, {
265 description: item.description,
266 kind: ContextMenuKind.COLLECTION
271 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
272 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
273 onContextMenu={(event, item) => {
274 let kind: ContextMenuKind;
276 if (item.kind === ResourceKind.PROJECT) {
277 kind = ContextMenuKind.PROJECT;
278 } else if (item.kind === ResourceKind.COLLECTION) {
279 kind = ContextMenuKind.COLLECTION_RESOURCE;
281 kind = ContextMenuKind.RESOURCE;
284 this.openContextMenu(event, {
287 description: item.description,
291 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
292 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
293 onItemClick={item => {
294 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
296 onItemDoubleClick={item => {
298 case ResourceKind.COLLECTION:
299 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
300 this.props.dispatch(push(getCollectionUrl(item.uuid)));
302 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
303 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
309 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
310 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
311 onContextMenu={(event, item) => {
312 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
313 this.openContextMenu(event, {
319 onDialogOpen={this.handleProjectCreationDialogOpen}
320 onItemClick={item => {
321 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
323 onItemDoubleClick={item => {
325 case ResourceKind.COLLECTION:
326 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
327 this.props.dispatch(push(getCollectionUrl(item.uuid)));
329 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
330 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
336 mainAppBarActions: MainAppBarActionProps = {
337 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
338 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
339 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
341 onSearch: searchText => {
342 this.setState({ searchText });
343 this.props.dispatch(push(`/search?q=${searchText}`));
345 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
346 onDetailsPanelToggle: () => {
347 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
349 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
350 this.openContextMenu(event, {
351 uuid: breadcrumb.itemId,
352 name: breadcrumb.label,
353 kind: ContextMenuKind.PROJECT
358 toggleSidePanelOpen = (itemId: string) => {
359 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
362 toggleSidePanelActive = (itemId: string) => {
363 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
365 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
366 if (panelItem && panelItem.activeAction) {
367 panelItem.activeAction(this.props.dispatch, this.props.authService.getUuid());
371 handleProjectCreationDialogOpen = (itemUuid: string) => {
372 this.props.dispatch(reset(PROJECT_CREATE_DIALOG));
373 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
376 handleCollectionCreationDialogOpen = (itemUuid: string) => {
377 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
378 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
381 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
382 event.preventDefault();
384 contextMenuActions.OPEN_CONTEXT_MENU({
385 position: { x: event.clientX, y: event.clientY },
391 toggleCurrentTokenModal = () => {
392 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });