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 { dataExplorerActions } from '../../store/data-explorer/data-explorer-action';
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 } from '../../store/collection-panel/collection-panel-action';
43 import { getCollectionUrl } from '../../models/collection';
44 import { RemoveDialog } from '../../views-components/remove-dialog/remove-dialog';
45 import { RenameDialog } from '../../views-components/rename-dialog/rename-dialog';
46 import { UpdateCollectionDialog } from '../../views-components/update-collection-dialog/update-collection-dialog.';
47 import { AuthService } from "../../services/auth-service/auth-service";
49 const DRAWER_WITDH = 240;
50 const APP_BAR_HEIGHT = 100;
52 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
54 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
65 zIndex: theme.zIndex.drawer + 1,
73 flexDirection: 'column',
76 backgroundColor: theme.palette.background.default,
80 paddingTop: APP_BAR_HEIGHT
83 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
87 toolbar: theme.mixins.toolbar
90 interface WorkbenchDataProps {
91 projects: Array<TreeItem<ProjectResource>>;
92 currentProjectId: string;
94 currentToken?: string;
95 sidePanelItems: SidePanelItem[];
98 interface WorkbenchServiceProps {
99 authService: AuthService;
102 interface WorkbenchActionProps {
105 type WorkbenchProps = WorkbenchDataProps & WorkbenchServiceProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
107 interface NavBreadcrumb extends Breadcrumb {
111 interface NavMenuItem extends MainAppBarMenuItem {
115 interface WorkbenchState {
116 isCurrentTokenDialogOpen: boolean;
120 accountMenu: NavMenuItem[],
121 helpMenu: NavMenuItem[],
122 anonymousMenu: NavMenuItem[]
126 export const Workbench = withStyles(styles)(
127 connect<WorkbenchDataProps>(
128 (state: RootState) => ({
129 projects: state.projects.items,
130 currentProjectId: state.projects.currentItemId,
131 user: state.auth.user,
132 currentToken: state.auth.apiToken,
133 sidePanelItems: state.sidePanel
136 class extends React.Component<WorkbenchProps, WorkbenchState> {
138 isCreationDialogOpen: false,
139 isCurrentTokenDialogOpen: false,
146 label: 'Current token',
147 action: () => this.toggleCurrentTokenModal()
151 action: () => this.props.dispatch(logout())
155 action: () => this.props.dispatch(push("/my-account"))
161 action: () => this.props.dispatch(push("/help"))
167 action: () => this.props.dispatch(login())
174 const path = getTreePath(this.props.projects, this.props.currentProjectId);
175 const breadcrumbs = path.map(item => ({
176 label: item.data.name,
177 itemId: item.data.uuid,
181 const { classes, user } = this.props;
183 <div className={classes.root}>
184 <div className={classes.appBar}>
186 breadcrumbs={breadcrumbs}
187 searchText={this.state.searchText}
188 user={this.props.user}
189 menuItems={this.state.menuItems}
190 {...this.mainAppBarActions} />
196 paper: classes.drawerPaper,
198 <div className={classes.toolbar} />
200 toggleOpen={this.toggleSidePanelOpen}
201 toggleActive={this.toggleSidePanelActive}
202 sidePanelItems={this.props.sidePanelItems}
203 onContextMenu={(event) => this.openContextMenu(event, {
204 uuid: this.props.authService.getUuid() || "",
206 kind: ContextMenuKind.ROOT_PROJECT
209 projects={this.props.projects}
210 toggleOpen={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.OPEN))}
211 onContextMenu={(event, item) => this.openContextMenu(event, {
212 uuid: item.data.uuid,
213 name: item.data.name,
214 kind: ContextMenuKind.PROJECT
216 toggleActive={itemId => {
217 this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
218 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
219 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
223 <main className={classes.contentWrapper}>
224 <div className={classes.content}>
226 <Route path="/projects/:id" render={this.renderProjectPanel} />
227 <Route path="/favorites" render={this.renderFavoritePanel} />
228 <Route path="/collections/:id" render={this.renderCollectionPanel} />
231 {user && <DetailsPanel />}
235 <CreateProjectDialog />
236 <CreateCollectionDialog />
239 <UpdateCollectionDialog />
241 currentToken={this.props.currentToken}
242 open={this.state.isCurrentTokenDialogOpen}
243 handleClose={this.toggleCurrentTokenModal} />
248 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
249 onItemRouteChange={(collectionId) => this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION))}
250 onContextMenu={(event, item) => {
251 this.openContextMenu(event, {
254 kind: ContextMenuKind.COLLECTION
259 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
260 onItemRouteChange={itemId => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))}
261 onContextMenu={(event, item) => {
263 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
264 this.openContextMenu(event, {
270 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
271 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
272 onItemClick={item => {
273 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
275 onItemDoubleClick={item => {
277 case ResourceKind.COLLECTION:
278 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
279 this.props.dispatch(push(getCollectionUrl(item.uuid)));
281 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
282 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
288 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
289 onItemRouteChange={() => this.props.dispatch(favoritePanelActions.REQUEST_ITEMS())}
290 onContextMenu={(event, item) => {
291 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
292 this.openContextMenu(event, {
298 onDialogOpen={this.handleProjectCreationDialogOpen}
299 onItemClick={item => {
300 this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind));
302 onItemDoubleClick={item => {
304 case ResourceKind.COLLECTION:
305 this.props.dispatch(loadCollection(item.uuid, item.kind as ResourceKind));
306 this.props.dispatch(push(getCollectionUrl(item.uuid)));
308 this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
309 this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
310 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
316 mainAppBarActions: MainAppBarActionProps = {
317 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
318 this.props.dispatch(setProjectItem(itemId, ItemMode.BOTH));
319 this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
321 onSearch: searchText => {
322 this.setState({ searchText });
323 this.props.dispatch(push(`/search?q=${searchText}`));
325 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
326 onDetailsPanelToggle: () => {
327 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
329 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
330 this.openContextMenu(event, {
331 uuid: breadcrumb.itemId,
332 name: breadcrumb.label,
333 kind: ContextMenuKind.PROJECT
338 toggleSidePanelOpen = (itemId: string) => {
339 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
342 toggleSidePanelActive = (itemId: string) => {
343 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
344 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
345 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
346 if (panelItem && panelItem.activeAction) {
347 panelItem.activeAction(this.props.dispatch);
351 handleProjectCreationDialogOpen = (itemUuid: string) => {
352 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
355 handleCollectionCreationDialogOpen = (itemUuid: string) => {
356 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
359 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; kind: ContextMenuKind; }) => {
360 event.preventDefault();
362 contextMenuActions.OPEN_CONTEXT_MENU({
363 position: { x: event.clientX, y: event.clientY },
369 toggleCurrentTokenModal = () => {
370 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });