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

diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx
index 959025bfbe..b2bdac802f 100644
--- a/src/views/workbench/workbench.tsx
+++ b/src/views/workbench/workbench.tsx
@@ -18,7 +18,6 @@ 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 } from '../../store/project/project-reducer';
 import sidePanelActions from '../../store/side-panel/side-panel-action';
 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
@@ -27,8 +26,15 @@ import projectActions from "../../store/project/project-action";
 import ProjectPanel from "../project-panel/project-panel";
 import DetailsPanel from '../../views-components/details-panel/details-panel';
 import { ArvadosTheme } from '../../common/custom-theme';
+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 { ResourceKind } from '../../models/kinds';
+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;
@@ -72,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[];
@@ -92,6 +98,10 @@ interface NavMenuItem extends MainAppBarMenuItem {
 }
 
 interface WorkbenchState {
+    contextMenu: {
+        anchorEl?: HTMLElement;
+        itemUuid?: string;
+    };
     anchorEl: any;
     searchText: string;
     menuItems: {
@@ -104,6 +114,11 @@ interface WorkbenchState {
 
 class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
     state = {
+        contextMenu: {
+            anchorEl: undefined,
+            itemUuid: undefined
+        },
+        isCreationDialogOpen: false,
         anchorEl: null,
         searchText: "",
         breadcrumbs: [],
@@ -145,6 +160,9 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
         onDetailsPanelToggle: () => {
             this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
+        },
+        onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
+            this.openContextMenu(event, breadcrumb.itemId);
         }
     };
 
@@ -155,6 +173,34 @@ 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 = (itemUuid: string) => {
+        this.closeContextMenu();
+        this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
+    }
+
+
+    openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string) => {
+        event.preventDefault();
+        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() {
@@ -174,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
@@ -187,15 +232,17 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                         <SidePanel
                             toggleOpen={this.toggleSidePanelOpen}
                             toggleActive={this.toggleSidePanelActive}
-                            sidePanelItems={this.props.sidePanelItems}>
+                            sidePanelItems={this.props.sidePanelItems}
+                            onContextMenu={(event) => this.openContextMenu(event, authService.getUuid() || "")}>
                             <ProjectTree
                                 projects={this.props.projects}
                                 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
+                                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}>
@@ -206,12 +253,20 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                     </div>
                     <DetailsPanel />
                 </main>
+                <ContextMenu
+                    anchorEl={this.state.contextMenu.anchorEl}
+                    actions={contextMenuActions}
+                    onActionClick={this.openCreateDialog}
+                    onClose={this.closeContextMenu} />
+                <DialogProjectCreate />
             </div>
         );
     }
 
     renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
         onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
+        onContextMenu={(event, item) => this.openContextMenu(event, item.uuid)}
+        onDialogOpen={this.handleCreationDialogOpen}
         onItemClick={item => {
             this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
         }}
@@ -220,8 +275,35 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
             this.props.dispatch<any>(loadDetails(item.uuid, ResourceKind.Project));
         }}
         {...props} />
+}
 
+const contextMenuActions = [[{
+    icon: "fas fa-plus fa-fw",
+    name: "New project",
+    openCreateDialog: true
+}, {
+    icon: "fas fa-users fa-fw",
+    name: "Share"
+}, {
+    icon: "fas fa-sign-out-alt fa-fw",
+    name: "Move to"
+}, {
+    icon: "fas fa-star fa-fw",
+    name: "Add to favourite"
+}, {
+    icon: "fas fa-edit fa-fw",
+    name: "Rename"
+}, {
+    icon: "fas fa-copy fa-fw",
+    name: "Make a copy"
+}, {
+    icon: "fas fa-download fa-fw",
+    name: "Download"
+}], [{
+    icon: "fas fa-trash-alt fa-fw",
+    name: "Remove"
 }
+]];
 
 export default connect<WorkbenchDataProps>(
     (state: RootState) => ({
