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 { authActions } 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";
28 import { authService } from '../../services/services';
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, FAVORITE_PANEL_ID } from "../favorite-panel/favorite-panel";
37 import { CurrentTokenDialog } from '../../views-components/current-token-dialog/current-token-dialog';
38 import { dataExplorerActions } from '../../store/data-explorer/data-explorer-action';
39 import { Snackbar } from '../../views-components/snackbar/snackbar';
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';
47 const drawerWidth = 240;
48 const appBarHeight = 100;
50 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
52 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
63 zIndex: theme.zIndex.drawer + 1,
71 flexDirection: 'column',
74 backgroundColor: theme.palette.background.default,
78 paddingTop: appBarHeight
81 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
85 toolbar: theme.mixins.toolbar
88 interface WorkbenchDataProps {
89 projects: Array<TreeItem<ProjectResource>>;
90 currentProjectId: string;
92 currentToken?: string;
93 sidePanelItems: SidePanelItem[];
96 interface WorkbenchActionProps {
99 type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
101 interface NavBreadcrumb extends Breadcrumb {
105 interface NavMenuItem extends MainAppBarMenuItem {
109 interface WorkbenchState {
110 isCurrentTokenDialogOpen: boolean;
114 accountMenu: NavMenuItem[],
115 helpMenu: NavMenuItem[],
116 anonymousMenu: NavMenuItem[]
120 export const Workbench = withStyles(styles)(
121 connect<WorkbenchDataProps>(
122 (state: RootState) => ({
123 projects: state.projects.items,
124 currentProjectId: state.projects.currentItemId,
125 user: state.auth.user,
126 currentToken: state.auth.apiToken,
127 sidePanelItems: state.sidePanel
130 class extends React.Component<WorkbenchProps, WorkbenchState> {
132 isCreationDialogOpen: false,
133 isCurrentTokenDialogOpen: false,
140 label: 'Current token',
141 action: () => this.toggleCurrentTokenModal()
145 action: () => this.props.dispatch(authActions.LOGOUT())
149 action: () => this.props.dispatch(push("/my-account"))
155 action: () => this.props.dispatch(push("/help"))
161 action: () => this.props.dispatch(authActions.LOGIN())
168 const path = getTreePath(this.props.projects, this.props.currentProjectId);
169 const breadcrumbs = path.map(item => ({
170 label: item.data.name,
171 itemId: item.data.uuid,
175 const { classes, user } = this.props;
177 <div className={classes.root}>
178 <div className={classes.appBar}>
180 breadcrumbs={breadcrumbs}
181 searchText={this.state.searchText}
182 user={this.props.user}
183 menuItems={this.state.menuItems}
184 {...this.mainAppBarActions} />
190 paper: classes.drawerPaper,
192 <div className={classes.toolbar} />
194 toggleOpen={this.toggleSidePanelOpen}
195 toggleActive={this.toggleSidePanelActive}
196 sidePanelItems={this.props.sidePanelItems}
197 onContextMenu={(event) => this.openContextMenu(event, {
198 uuid: authService.getUuid() || "",
200 kind: ContextMenuKind.ROOT_PROJECT
203 projects={this.props.projects}
204 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
205 onContextMenu={(event, item) => this.openContextMenu(event, {
206 uuid: item.data.uuid,
207 name: item.data.name,
208 kind: ContextMenuKind.PROJECT
210 toggleActive={itemId => {
211 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE));
212 this.props.dispatch<any>(loadDetails(itemId, ResourceKind.PROJECT));
213 this.props.dispatch<any>(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
217 <main className={classes.contentWrapper}>
218 <div className={classes.content}>
220 <Route path="/projects/:id" render={this.renderProjectPanel} />
221 <Route path="/favorites" render={this.renderFavoritePanel} />
222 <Route path="/collections/:id" render={this.renderCollectionPanel} />
225 {user && <DetailsPanel />}
229 <CreateProjectDialog />
230 <CreateCollectionDialog />
234 currentToken={this.props.currentToken}
235 open={this.state.isCurrentTokenDialogOpen}
236 handleClose={this.toggleCurrentTokenModal} />
241 renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
242 onItemRouteChange={(collectionId) => this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION))}
243 onContextMenu={(event, item) => {
244 this.openContextMenu(event, {
247 kind: ContextMenuKind.COLLECTION
252 renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
253 onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
254 onContextMenu={(event, item) => {
256 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
257 this.openContextMenu(event, {
263 onProjectCreationDialogOpen={this.handleProjectCreationDialogOpen}
264 onCollectionCreationDialogOpen={this.handleCollectionCreationDialogOpen}
265 onItemClick={item => {
266 this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
268 onItemDoubleClick={item => {
270 case ResourceKind.COLLECTION:
271 this.props.dispatch<any>(loadCollection(item.uuid, item.kind as ResourceKind));
272 this.props.dispatch(push(getCollectionUrl(item.uuid)));
274 this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
275 this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
281 renderFavoritePanel = (props: RouteComponentProps<{ id: string }>) => <FavoritePanel
282 onItemRouteChange={() => this.props.dispatch<any>(dataExplorerActions.REQUEST_ITEMS({ id: FAVORITE_PANEL_ID }))}
283 onContextMenu={(event, item) => {
284 const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE;
285 this.openContextMenu(event, {
291 onDialogOpen={this.handleProjectCreationDialogOpen}
292 onItemClick={item => {
293 this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
295 onItemDoubleClick={item => {
297 case ResourceKind.COLLECTION:
298 this.props.dispatch<any>(loadCollection(item.uuid, item.kind as ResourceKind));
299 this.props.dispatch(push(getCollectionUrl(item.uuid)));
301 this.props.dispatch<any>(loadDetails(item.uuid, ResourceKind.PROJECT));
302 this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
303 this.props.dispatch<any>(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
309 mainAppBarActions: MainAppBarActionProps = {
310 onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
311 this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
312 this.props.dispatch<any>(loadDetails(itemId, ResourceKind.PROJECT));
314 onSearch: searchText => {
315 this.setState({ searchText });
316 this.props.dispatch(push(`/search?q=${searchText}`));
318 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
319 onDetailsPanelToggle: () => {
320 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
322 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
323 this.openContextMenu(event, {
324 uuid: breadcrumb.itemId,
325 name: breadcrumb.label,
326 kind: ContextMenuKind.PROJECT
331 toggleSidePanelOpen = (itemId: string) => {
332 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
335 toggleSidePanelActive = (itemId: string) => {
336 this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
337 this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
338 const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);
339 if (panelItem && panelItem.activeAction) {
340 panelItem.activeAction(this.props.dispatch);
344 handleProjectCreationDialogOpen = (itemUuid: string) => {
345 this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
348 handleCollectionCreationDialogOpen = (itemUuid: string) => {
349 this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid }));
352 openContextMenu = (event: React.MouseEvent<HTMLElement>, resource: { name: string; uuid: string; kind: ContextMenuKind; }) => {
353 event.preventDefault();
355 contextMenuActions.OPEN_CONTEXT_MENU({
356 position: { x: event.clientX, y: event.clientY },
362 toggleCurrentTokenModal = () => {
363 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });