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, Switch, RouteComponentProps } 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 "../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 kind: ContextMenuKind.COLLECTION
268 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
269 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
270 onContextMenu={(event, item) => {
272 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
273 this.openContextMenu(event, {
279 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
280 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
281 onItemClick={item => {
282 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
284 onItemDoubleClick={item => {
286 case ResourceKind.COLLECTION:
287 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
288 this.props.dispatch(push(getCollectionUrl(item.uuid)));
290 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
291 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
297 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
298 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
299 onContextMenu={(event, item) => {
300 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
301 this.openContextMenu(event, {
307 onDialogOpen={this.handleProjectCreationDialogOpen}
308 onItemClick={item => {
309 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
311 onItemDoubleClick={item => {
313 case ResourceKind.COLLECTION:
314 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
315 this.props.dispatch(push(getCollectionUrl(item.uuid)));
317 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
318 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
319 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
325 mainAppBarActions: MainAppBarActionProps = {
326 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
327 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
328 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
330 onSearch: searchText => {
331 this.setState({ searchText });
332 this.props.dispatch(push(`/search?q=${searchText}`));
334 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
335 onDetailsPanelToggle: () => {
336 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
338 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
339 this.openContextMenu(event, {
340 uuid: breadcrumb.itemId,
341 name: breadcrumb.label,
342 kind: ContextMenuKind.PROJECT
347 toggleSidePanelOpen = (itemId: string) => {
348 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
351 toggleSidePanelActive = (itemId: string) => {
352 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
353 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
354 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
355 if (panelItem && panelItem.activeAction) {
356 panelItem.activeAction(this.props.dispatch);
360 handleProjectCreationDialogOpen = (itemUuid: string) => {
361 this.props.dispatch(reset(PROJECT_CREATE_DIALOG));
362 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
365 handleCollectionCreationDialogOpen = (itemUuid: string) => {
366 this.props.dispatch(reset(COLLECTION_CREATE_DIALOG));
367 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
370 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; kind: ContextMenuKind; }) => {
371 event.preventDefault();
373 contextMenuActions.OPEN_CONTEXT_MENU({
374 position: { x: event.clientX, y: event.clientY },
380 toggleCurrentTokenModal = () => {
381 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });