Implement base distinction between context menu kind
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Fri, 13 Jul 2018 13:02:33 +0000 (15:02 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Fri, 13 Jul 2018 13:02:33 +0000 (15:02 +0200)
Feature #13805

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/store/context-menu/context-menu-reducer.ts
src/views-components/context-menu/context-menu.tsx
src/views/workbench/workbench.tsx

index 69f9c9af703d2d61a8989c59748bf006f834351f..129c2af4763ed0556cdbb224046174ba5375fddb 100644 (file)
@@ -17,7 +17,13 @@ export interface ContextMenuPosition {
 
 export interface ContextMenuResource {
     uuid: string;
-    kind: ResourceKind;
+    kind: ContextMenuKind;
+}
+
+export enum ContextMenuKind {
+    RootProject = "RootProject",
+    Project = "Project",
+    Collection = "Collection"
 }
 
 const initialState = {
index 21d851df30ce75a797fb7ed36adf4b82b5d71cd7..bfd833a8e6fadf31c561fc72f86455731a079d63 100644 (file)
@@ -8,7 +8,7 @@ import actions from "../../store/context-menu/context-menu-actions";
 import ContextMenu, { ContextMenuAction, ContextMenuProps } from "../../components/context-menu/context-menu";
 import { createAnchorAt } from "../../components/popover/helpers";
 import projectActions from "../../store/project/project-action";
-import { ContextMenuResource } from "../../store/context-menu/context-menu-reducer";
+import { ContextMenuResource, ContextMenuKind } from "../../store/context-menu/context-menu-reducer";
 
 
 type DataProps = Pick<ContextMenuProps, "anchorEl" | "actions"> & { resource?: ContextMenuResource };
@@ -16,12 +16,12 @@ const mapStateToProps = (state: RootState): DataProps => {
     const { position, resource } = state.contextMenu;
     return {
         anchorEl: resource ? createAnchorAt(position) : undefined,
-        actions: contextMenuActions,
+        actions: resource ? menuActions[resource.kind] : [],
         resource
     };
 };
 
-type ActionProps = Pick<ContextMenuProps, "onClose"> & {onActionClick: (action: ContextMenuAction, resource?: ContextMenuResource) => void};
+type ActionProps = Pick<ContextMenuProps, "onClose"> & { onActionClick: (action: ContextMenuAction, resource?: ContextMenuResource) => void };
 const mapDispatchToProps = (dispatch: Dispatch): ActionProps => ({
     onClose: () => {
         dispatch(actions.CLOSE_CONTEXT_MENU());
@@ -46,29 +46,58 @@ const mergeProps = ({ resource, ...dataProps }: DataProps, actionProps: ActionPr
 
 export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ContextMenu);
 
-const contextMenuActions = [[{
-    icon: "fas fa-plus fa-fw",
-    name: "New project"
-}, {
-    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"
-}
-]];
\ No newline at end of file
+const menuActions = {
+    [ContextMenuKind.RootProject]: [[{
+        icon: "fas fa-plus fa-fw",
+        name: "New project"
+    }]],
+    [ContextMenuKind.Project]: [[{
+        icon: "fas fa-plus fa-fw",
+        name: "New project"
+    }, {
+        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"
+    }
+    ]],
+    [ContextMenuKind.Collection]: [[{
+        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"
+    }
+    ]]
+};
index afd9dfdd700e526b19d34cfe3ad80add07459faa..52332e8b161b4d965fbe418a875037696c050e12 100644 (file)
@@ -35,6 +35,7 @@ import contextMenuActions from "../../store/context-menu/context-menu-actions";
 import { SidePanelIdentifiers } from '../../store/side-panel/side-panel-reducer';
 import { ProjectResource } from '../../models/project';
 import { ResourceKind } from '../../models/resource';
+import { ContextMenuKind } from '../../store/context-menu/context-menu-reducer';
 
 const drawerWidth = 240;
 const appBarHeight = 100;
@@ -154,7 +155,7 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
             this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
         },
         onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
-            this.openContextMenu(event, breadcrumb.itemId);
+            this.openContextMenu(event, breadcrumb.itemId, ContextMenuKind.Project);
         }
     };
 
@@ -172,13 +173,12 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
     }
 
-
-    openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string) => {
+    openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string, kind: ContextMenuKind) => {
         event.preventDefault();
         this.props.dispatch(
             contextMenuActions.OPEN_CONTEXT_MENU({
                 position: { x: event.clientX, y: event.clientY },
-                resource: { uuid: itemUuid, kind: ResourceKind.Project }
+                resource: { uuid: itemUuid, kind }
             })
         );
     }
@@ -213,11 +213,11 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                             toggleOpen={this.toggleSidePanelOpen}
                             toggleActive={this.toggleSidePanelActive}
                             sidePanelItems={this.props.sidePanelItems}
-                            onContextMenu={(event) => this.openContextMenu(event, authService.getUuid() || "")}>
+                            onContextMenu={(event) => this.openContextMenu(event, authService.getUuid() || "", ContextMenuKind.RootProject)}>
                             <ProjectTree
                                 projects={this.props.projects}
                                 toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
-                                onContextMenu={(event, item) => this.openContextMenu(event, item.data.uuid)}
+                                onContextMenu={(event, item) => this.openContextMenu(event, item.data.uuid,  ContextMenuKind.Project)}
                                 toggleActive={itemId => {
                                     this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE));
                                     this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
@@ -241,7 +241,7 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
 
     renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
         onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
-        onContextMenu={(event, item) => this.openContextMenu(event, item.uuid)}
+        onContextMenu={(event, item) => this.openContextMenu(event, item.uuid, ContextMenuKind.Project)}
         onDialogOpen={this.handleCreationDialogOpen}
         onItemClick={item => {
             this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));