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 { ProjectTree } from '../../views-components/project-tree/project-tree';
17 import { TreeItem } from "../../components/tree/tree";
18 import { getTreePath } from '../../store/project/project-reducer';
19 import { sidePanelActions } from '../../store/side-panel/side-panel-action';
20 import { SidePanel, SidePanelItem } from '../../components/side-panel/side-panel';
21 import { ItemMode, setProjectItem } from "../../store/navigation/navigation-action";
22 import { projectActions } from "../../store/project/project-action";
23 import { collectionCreateActions } from '../../store/collections/creator/collection-creator-action';
24 import { ProjectPanel } from "../project-panel/project-panel";
25 import { DetailsPanel } from '../../views-components/details-panel/details-panel';
26 import { ArvadosTheme } from '../../common/custom-theme';
27 import { CreateProjectDialog } from "../../views-components/create-project-dialog/create-project-dialog";
29 import { detailsPanelActions, loadDetails } from "../../store/details-panel/details-panel-action";
30 import { contextMenuActions } from "../../store/context-menu/context-menu-actions";
31 import { SidePanelIdentifiers } from '../../store/side-panel/side-panel-reducer';
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 { AuthService } from "../../services/auth-service/auth-service";
45 import { RenameFileDialog } from '../../views-components/rename-file-dialog/rename-file-dialog';
46 import { FileRemoveDialog } from '../../views-components/file-remove-dialog/file-remove-dialog';
47 import { MultipleFilesRemoveDialog } from '../../views-components/file-remove-dialog/multiple-files-remove-dialog';
48 import { DialogCollectionCreateWithSelectedFile } from '../../views-components/create-collection-dialog-with-selected/create-collection-dialog-with-selected';
49 import { MoveToProjectDialog } from '../../views-components/move-to-dialog/move-to-dialog';
51 const DRAWER_WITDH = 240;
52 const APP_BAR_HEIGHT = 100;
54 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
56 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
67 zIndex: theme.zIndex.drawer + 1,
75 flexDirection: 'column',
78 backgroundColor: theme.palette.background.default,
82 paddingTop: APP_BAR_HEIGHT
85 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
89 toolbar: theme.mixins.toolbar
92 interface WorkbenchDataProps {
93 projects: Array<TreeItem<ProjectResource>>;
94 currentProjectId: string;
96 currentToken?: string;
97 sidePanelItems: SidePanelItem[];
100 interface WorkbenchServiceProps {
101 authService: AuthService;
104 interface WorkbenchActionProps {
107 type WorkbenchProps = WorkbenchDataProps & WorkbenchServiceProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
109 interface NavBreadcrumb extends Breadcrumb {
113 interface NavMenuItem extends MainAppBarMenuItem {
117 interface WorkbenchState {
118 isCurrentTokenDialogOpen: boolean;
122 accountMenu: NavMenuItem[],
123 helpMenu: NavMenuItem[],
124 anonymousMenu: NavMenuItem[]
128 export const Workbench = withStyles(styles)(
129 connect<WorkbenchDataProps>(
130 (state: RootState) => ({
131 projects: state.projects.items,
132 currentProjectId: state.projects.currentItemId,
133 user: state.auth.user,
134 currentToken: state.auth.apiToken,
135 sidePanelItems: state.sidePanel
138 class extends React.Component<WorkbenchProps, WorkbenchState> {
140 isCreationDialogOpen: false,
141 isCurrentTokenDialogOpen: false,
148 label: 'Current token',
149 action: () => this.toggleCurrentTokenModal()
153 action: () => this.props.dispatch(logout())
157 action: () => this.props.dispatch(push("/my-account"))
163 action: () => this.props.dispatch(push("/help"))
169 action: () => this.props.dispatch(login())
176 const path = getTreePath(this.props.projects, this.props.currentProjectId);
177 const breadcrumbs = path.map(item => ({
178 label: item.data.name,
179 itemId: item.data.uuid,
183 const { classes, user } = this.props;
185 <div className={classes.root}>
186 <div className={classes.appBar}>
188 breadcrumbs={breadcrumbs}
189 searchText={this.state.searchText}
190 user={this.props.user}
191 menuItems={this.state.menuItems}
192 {...this.mainAppBarActions} />
198 paper: classes.drawerPaper,
200 <div className={classes.toolbar} />
202 toggleOpen={this.toggleSidePanelOpen}
203 toggleActive={this.toggleSidePanelActive}
204 sidePanelItems={this.props.sidePanelItems}
205 onContextMenu={(event) => this.openContextMenu(event, {
206 uuid: this.props.authService.getUuid() || "",
208 kind: ContextMenuKind.ROOT_PROJECT
211 projects={this.props.projects}
212 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
213 onContextMenu={(event, item) => this.openContextMenu(event, {
214 uuid: item.data.uuid,
215 name: item.data.name,
216 kind: ContextMenuKind.PROJECT
218 toggleActive={itemId => {
219 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
220 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
221 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
225 <main className={classes.contentWrapper}>
226 <div className={classes.content}>
228 <Route path="/projects/:id" render={this.renderProjectPanel} />
229 <Route path="/favorites" render={this.renderFavoritePanel} />
230 <Route path="/collections/:id" render={this.renderCollectionPanel} />
233 {user && <DetailsPanel />}
237 <CreateProjectDialog />
238 <CreateCollectionDialog />
240 <MoveToProjectDialog />
241 <DialogCollectionCreateWithSelectedFile />
243 <MultipleFilesRemoveDialog />
244 <UpdateCollectionDialog />
246 currentToken={this.props.currentToken}
247 open={this.state.isCurrentTokenDialogOpen}
248 handleClose={this.toggleCurrentTokenModal} />
253 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
254 onItemRouteChange={(collectionId) => {
255 this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION));
256 this.props.dispatch<any>(loadCollectionTags(collectionId));
258 onContextMenu={(event, item) => {
259 this.openContextMenu(event, {
262 description: item.description,
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) => {
271 let kind: ContextMenuKind;
273 if (item.kind === ResourceKind.PROJECT) {
274 kind = ContextMenuKind.PROJECT;
275 } else if (item.kind === ResourceKind.COLLECTION) {
276 kind = ContextMenuKind.COLLECTION_RESOURCE;
278 kind = ContextMenuKind.RESOURCE;
281 this.openContextMenu(event, {
284 description: item.description,
288 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
289 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
290 onItemClick={item => {
291 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
293 onItemDoubleClick={item => {
295 case ResourceKind.COLLECTION:
296 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
297 this.props.dispatch(push(getCollectionUrl(item.uuid)));
299 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
300 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
306 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
307 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
308 onContextMenu={(event, item) => {
309 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
310 this.openContextMenu(event, {
316 onDialogOpen={this.handleProjectCreationDialogOpen}
317 onItemClick={item => {
318 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
320 onItemDoubleClick={item => {
322 case ResourceKind.COLLECTION:
323 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
324 this.props.dispatch(push(getCollectionUrl(item.uuid)));
326 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
327 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
328 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
334 mainAppBarActions: MainAppBarActionProps = {
335 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
336 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
337 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
339 onSearch: searchText => {
340 this.setState({ searchText });
341 this.props.dispatch(push(`/search?q=${searchText}`));
343 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
344 onDetailsPanelToggle: () => {
345 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
347 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
348 this.openContextMenu(event, {
349 uuid: breadcrumb.itemId,
350 name: breadcrumb.label,
351 kind: ContextMenuKind.PROJECT
356 toggleSidePanelOpen = (itemId: string) => {
357 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
360 toggleSidePanelActive = (itemId: string) => {
361 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
362 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
363 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
364 if (panelItem && panelItem.activeAction) {
365 panelItem.activeAction(this.props.dispatch);
369 handleProjectCreationDialogOpen = (itemUuid: string) => {
370 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
373 handleCollectionCreationDialogOpen = (itemUuid: string) => {
374 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
377 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => {
378 event.preventDefault();
380 contextMenuActions.OPEN_CONTEXT_MENU({
381 position: { x: event.clientX, y: event.clientY },
387 toggleCurrentTokenModal = () => {
388 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });