X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a3f3b01052abf62ac96bb841747a657268498ad0..b0de143e088973715681f7eb6c41f2dccb648c2b:/src/views/workbench/workbench.tsx?ds=sidebyside

diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx
index 3b8b00e219..b2bdac802f 100644
--- a/src/views/workbench/workbench.tsx
+++ b/src/views/workbench/workbench.tsx
@@ -6,9 +6,8 @@ import * as React from 'react';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
 import Drawer from '@material-ui/core/Drawer';
 import { connect, DispatchProp } from "react-redux";
-import { Route, Switch, RouteComponentProps, withRouter } from "react-router";
+import { Route, Switch, RouteComponentProps } from "react-router";
 import authActions from "../../store/auth/auth-action";
-import dataExplorerActions from "../../store/data-explorer/data-explorer-action";
 import { User } from "../../models/user";
 import { RootState } from "../../store/store";
 import MainAppBar, {
@@ -19,19 +18,23 @@ import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
 import { push } from 'react-router-redux';
 import ProjectTree from '../../views-components/project-tree/project-tree';
 import { TreeItem } from "../../components/tree/tree";
-import { Project } from "../../models/project";
-import { getTreePath, findTreeItem } from '../../store/project/project-reducer';
+import { getTreePath } from '../../store/project/project-reducer';
 import sidePanelActions from '../../store/side-panel/side-panel-action';
 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
-import { ResourceKind } from "../../models/resource";
 import { ItemMode, setProjectItem } from "../../store/navigation/navigation-action";
 import projectActions from "../../store/project/project-action";
 import ProjectPanel from "../project-panel/project-panel";
-import { sidePanelData } from '../../store/side-panel/side-panel-reducer';
 import DetailsPanel from '../../views-components/details-panel/details-panel';
 import { ArvadosTheme } from '../../common/custom-theme';
-import ContextMenu from '../../components/context-menu/context-menu';
+import ContextMenu, { ContextMenuAction } from '../../components/context-menu/context-menu';
 import { mockAnchorFromMouseEvent } from '../../components/popover/helpers';
+import DialogProjectCreate from "../../views-components/create-project-dialog/create-project-dialog";
+import { authService } from '../../services/services';
+
+import detailsPanelActions, { loadDetails } from "../../store/details-panel/details-panel-action";
+import { SidePanelIdentifiers } from '../../store/side-panel/side-panel-reducer';
+import { ProjectResource } from '../../models/project';
+import { ResourceKind } from '../../models/resource';
 
 const drawerWidth = 240;
 const appBarHeight = 100;
@@ -75,7 +78,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 });
 
 interface WorkbenchDataProps {
-    projects: Array<TreeItem<Project>>;
+    projects: Array<TreeItem<ProjectResource>>;
     currentProjectId: string;
     user?: User;
     sidePanelItems: SidePanelItem[];
@@ -97,8 +100,8 @@ interface NavMenuItem extends MainAppBarMenuItem {
 interface WorkbenchState {
     contextMenu: {
         anchorEl?: HTMLElement;
+        itemUuid?: string;
     };
-    isCreationDialogOpen: boolean;
     anchorEl: any;
     searchText: string;
     menuItems: {
@@ -106,13 +109,14 @@ interface WorkbenchState {
         helpMenu: NavMenuItem[],
         anonymousMenu: NavMenuItem[]
     };
-    isDetailsPanelOpened: boolean;
 }
 
+
 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
     state = {
         contextMenu: {
-            anchorEl: undefined
+            anchorEl: undefined,
+            itemUuid: undefined
         },
         isCreationDialogOpen: false,
         anchorEl: null,
@@ -141,13 +145,13 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                     action: () => this.props.dispatch(authActions.LOGIN())
                 }
             ]
-        },
-        isDetailsPanelOpened: false
+        }
     };
 
     mainAppBarActions: MainAppBarActionProps = {
         onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
             this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
+            this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
         },
         onSearch: searchText => {
             this.setState({ searchText });
@@ -155,10 +159,10 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         },
         onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
         onDetailsPanelToggle: () => {
-            this.setState(prev => ({ isDetailsPanelOpened: !prev.isDetailsPanelOpened }));
+            this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
         },
-        onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: Breadcrumb) => {
-            this.openContextMenu(event, breadcrumb);
+        onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
+            this.openContextMenu(event, breadcrumb.itemId);
         }
     };
 
@@ -169,26 +173,36 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
     toggleSidePanelActive = (itemId: string) => {
         this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
         this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
+        this.props.dispatch(push("/"));
     }
 
-    handleCreationDialogOpen = () => {
-        this.setState({ isCreationDialogOpen: true });
+    handleCreationDialogOpen = (itemUuid: string) => {
+        this.closeContextMenu();
+        this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
     }
 
-    handleCreationDialogClose = () => {
-        this.setState({ isCreationDialogOpen: false });
-    }
 
-    openContextMenu = (event: React.MouseEvent<HTMLElement>, item: any) => {
+    openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string) => {
         event.preventDefault();
-        this.setState({ contextMenu: { anchorEl: mockAnchorFromMouseEvent(event) } });
-        console.log(item);
+        this.setState({
+            contextMenu: {
+                anchorEl: mockAnchorFromMouseEvent(event),
+                itemUuid
+            }
+        });
     }
 
     closeContextMenu = () => {
         this.setState({ contextMenu: {} });
     }
 
+    openCreateDialog = (item: ContextMenuAction) => {
+        const { itemUuid } = this.state.contextMenu;
+        if (item.openCreateDialog && itemUuid) {
+            this.handleCreationDialogOpen(itemUuid);
+        }
+    }
+
     render() {
         const path = getTreePath(this.props.projects, this.props.currentProjectId);
         const breadcrumbs = path.map(item => ({
@@ -206,8 +220,7 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                         searchText={this.state.searchText}
                         user={this.props.user}
                         menuItems={this.state.menuItems}
-                        {...this.mainAppBarActions}
-                    />
+                        {...this.mainAppBarActions} />
                 </div>
                 {user &&
                     <Drawer
@@ -220,15 +233,16 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                             toggleOpen={this.toggleSidePanelOpen}
                             toggleActive={this.toggleSidePanelActive}
                             sidePanelItems={this.props.sidePanelItems}
-                            handleCreationDialogOpen={this.handleCreationDialogOpen}
-                            handleCreationDialogClose={this.handleCreationDialogClose}>
+                            onContextMenu={(event) => this.openContextMenu(event, authService.getUuid() || "")}>
                             <ProjectTree
                                 projects={this.props.projects}
                                 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
-                                toggleActive={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
-                                handleCreationDialogOpen={this.handleCreationDialogOpen}
-                                handleCreationDialogClose={this.handleCreationDialogClose}
-                            />
+                                onContextMenu={(event, item) => this.openContextMenu(event, item.data.uuid)}
+                                toggleActive={itemId => {
+                                    this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE));
+                                    this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
+                                    this.props.dispatch<any>(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.Projects));
+                                }} />
                         </SidePanel>
                     </Drawer>}
                 <main className={classes.contentWrapper}>
@@ -237,33 +251,36 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                             <Route path="/projects/:id" render={this.renderProjectPanel} />
                         </Switch>
                     </div>
-                    <DetailsPanel
-                        isOpened={this.state.isDetailsPanelOpened}
-                        onCloseDrawer={this.mainAppBarActions.onDetailsPanelToggle} />
+                    <DetailsPanel />
                 </main>
                 <ContextMenu
                     anchorEl={this.state.contextMenu.anchorEl}
                     actions={contextMenuActions}
-                    onActionClick={console.log}
+                    onActionClick={this.openCreateDialog}
                     onClose={this.closeContextMenu} />
+                <DialogProjectCreate />
             </div>
         );
     }
 
     renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
         onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
-        onItemClick={item => this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE))}
-        onContextMenu={this.openContextMenu}
-        handleCreationDialogOpen={this.handleCreationDialogOpen}
-        handleCreationDialogClose={this.handleCreationDialogClose}
-        isCreationDialogOpen={this.state.isCreationDialogOpen}
+        onContextMenu={(event, item) => this.openContextMenu(event, item.uuid)}
+        onDialogOpen={this.handleCreationDialogOpen}
+        onItemClick={item => {
+            this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
+        }}
+        onItemDoubleClick={item => {
+            this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
+            this.props.dispatch<any>(loadDetails(item.uuid, ResourceKind.Project));
+        }}
         {...props} />
-
 }
 
 const contextMenuActions = [[{
     icon: "fas fa-plus fa-fw",
-    name: "New project"
+    name: "New project",
+    openCreateDialog: true
 }, {
     icon: "fas fa-users fa-fw",
     name: "Share"
