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 } 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 { SidePanelIdentifiers } from '~/store/side-panel/side-panel-reducer';
33 import { ProjectResource } from '~/models/project';
34 import { ResourceKind } from '~/models/resource';
35 import { ContextMenu, ContextMenuKind } from "~/views-components/context-menu/context-menu";
36 import { FavoritePanel } from "../favorite-panel/favorite-panel";
37 import { CurrentTokenDialog } from '~/views-components/current-token-dialog/current-token-dialog';
38 import { Snackbar } from '~/views-components/snackbar/snackbar';
39 import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action';
40 import { CreateCollectionDialog } from '~/views-components/create-collection-dialog/create-collection-dialog';
41 import { CollectionPanel } from '../collection-panel/collection-panel';
42 import { loadCollection, loadCollectionTags } from '~/store/collection-panel/collection-panel-action';
43 import { getCollectionUrl } from '~/models/collection';
44 import { UpdateCollectionDialog } from '~/views-components/update-collection-dialog/update-collection-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`,
91 toolbar: theme.mixins.toolbar
94 interface WorkbenchDataProps {
95 projects: Array<TreeItem<ProjectResource>>;
96 currentProjectId: string;
98 currentToken?: string;
99 sidePanelItems: SidePanelItem[];
102 interface WorkbenchServiceProps {
103 authService: AuthService;
106 interface WorkbenchActionProps {
109 type WorkbenchProps = WorkbenchDataProps & WorkbenchServiceProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
111 interface NavBreadcrumb extends Breadcrumb {
115 interface NavMenuItem extends MainAppBarMenuItem {
119 interface WorkbenchState {
120 isCurrentTokenDialogOpen: boolean;
124 accountMenu: NavMenuItem[],
125 helpMenu: NavMenuItem[],
126 anonymousMenu: NavMenuItem[]
130 export const Workbench = withStyles(styles)(
131 connect<WorkbenchDataProps>(
132 (state: RootState) => ({
133 projects: state.projects.items,
134 currentProjectId: state.projects.currentItemId,
135 user: state.auth.user,
136 currentToken: state.auth.apiToken,
137 sidePanelItems: state.sidePanel
140 class extends React.Component<WorkbenchProps, WorkbenchState> {
142 isCreationDialogOpen: false,
143 isCurrentTokenDialogOpen: false,
150 label: 'Current token',
151 action: () => this.toggleCurrentTokenModal()
155 action: () => this.props.dispatch(logout())
159 action: () => this.props.dispatch(push("/my-account"))
165 action: () => this.props.dispatch(push("/help"))
171 action: () => this.props.dispatch(login())
178 const path = getTreePath(this.props.projects, this.props.currentProjectId);
179 const breadcrumbs = path.map(item => ({
180 label: item.data.name,
181 itemId: item.data.uuid,
185 const { classes, user } = this.props;
187 <div className={classes.root}>
188 <div className={classes.appBar}>
190 breadcrumbs={breadcrumbs}
191 searchText={this.state.searchText}
192 user={this.props.user}
193 menuItems={this.state.menuItems}
194 {...this.mainAppBarActions} />
200 paper: classes.drawerPaper,
202 <div className={classes.toolbar} />
204 toggleOpen={this.toggleSidePanelOpen}
205 toggleActive={this.toggleSidePanelActive}
206 sidePanelItems={this.props.sidePanelItems}
207 onContextMenu={(event) => this.openContextMenu(event, {
208 uuid: this.props.authService.getUuid() || "",
210 kind: ContextMenuKind.ROOT_PROJECT
213 projects={this.props.projects}
214 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
215 onContextMenu={(event, item) => this.openContextMenu(event, {
216 uuid: item.data.uuid,
217 name: item.data.name,
218 kind: ContextMenuKind.PROJECT
220 toggleActive={itemId => {
221 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
222 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
223 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
227 <main className={classes.contentWrapper}>
228 <div className={classes.content}>
230 <Route path="/projects/:id" render={this.renderProjectPanel} />
231 <Route path="/favorites" render={this.renderFavoritePanel} />
232 <Route path="/collections/:id" render={this.renderCollectionPanel} />
235 {user && <DetailsPanel />}
239 <CreateProjectDialog />
240 <CreateCollectionDialog />
242 <DialogCollectionCreateWithSelectedFile />
244 <MultipleFilesRemoveDialog />
245 <UpdateCollectionDialog />
247 currentToken={this.props.currentToken}
248 open={this.state.isCurrentTokenDialogOpen}
249 handleClose={this.toggleCurrentTokenModal} />
254 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
255 onItemRouteChange={(collectionId) => {
256 this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION));
257 this.props.dispatch<any>(loadCollectionTags(collectionId));
259 onContextMenu={(event, item) => {
260 this.openContextMenu(event, {
263 description: item.description,
264 kind: ContextMenuKind.COLLECTION
269 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
270 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
271 onContextMenu={(event, item) => {
272 let kind: ContextMenuKind;
274 if (item.kind === ResourceKind.PROJECT) {
275 kind = ContextMenuKind.PROJECT;
276 } else if (item.kind === ResourceKind.COLLECTION) {
277 kind = ContextMenuKind.COLLECTION_RESOURCE;
279 kind = ContextMenuKind.RESOURCE;
282 this.openContextMenu(event, {
285 description: item.description,
289 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
290 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
291 onItemClick={item => {
292 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
294 onItemDoubleClick={item => {
296 case ResourceKind.COLLECTION:
297 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
298 this.props.dispatch(push(getCollectionUrl(item.uuid)));
300 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
301 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
307 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
308 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
309 onContextMenu={(event, item) => {
310 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
311 this.openContextMenu(event, {
317 onDialogOpen={this.handleProjectCreationDialogOpen}
318 onItemClick={item => {
319 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
321 onItemDoubleClick={item => {
323 case ResourceKind.COLLECTION:
324 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
325 this.props.dispatch(push(getCollectionUrl(item.uuid)));
327 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
328 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
329 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
335 mainAppBarActions: MainAppBarActionProps = {
336 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
337 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
338 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
340 onSearch: searchText => {
341 this.setState({ searchText });
342 this.props.dispatch(push(`/search?q=${searchText}`));
344 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
345 onDetailsPanelToggle: () => {
346 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
348 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
349 this.openContextMenu(event, {
350 uuid: breadcrumb.itemId,
351 name: breadcrumb.label,
352 kind: ContextMenuKind.PROJECT
357 toggleSidePanelOpen = (itemId: string) => {
358 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
361 toggleSidePanelActive = (itemId: string) => {
362 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
363 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
364 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
365 if (panelItem && panelItem.activeAction) {
366 panelItem.activeAction(this.props.dispatch);
370 handleProjectCreationDialogOpen = (itemUuid: string) => {
371 this.props.dispatch(reset(PROJECT_CREATE_DIALOG));
372 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
375 handleCollectionCreationDialogOpen = (itemUuid: string) => {
376 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
377 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
380 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
381 event.preventDefault();
383 contextMenuActions.OPEN_CONTEXT_MENU({
384 position: { x: event.clientX, y: event.clientY },
390 toggleCurrentTokenModal = () => {
391 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });