X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a781af5eae4f4e7f6e07a2b205ad4e54e9e8ec7a..3ee31ce16470660d90fb870e048c2de9fcde6e47:/src/views-components/context-menu/context-menu.tsx

diff --git a/src/views-components/context-menu/context-menu.tsx b/src/views-components/context-menu/context-menu.tsx
index 93cb644a68..4ec7029141 100644
--- a/src/views-components/context-menu/context-menu.tsx
+++ b/src/views-components/context-menu/context-menu.tsx
@@ -2,21 +2,22 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { connect, Dispatch, DispatchProp } from "react-redux";
+import { connect } from "react-redux";
 import { RootState } from "../../store/store";
-import actions from "../../store/context-menu/context-menu-actions";
-import ContextMenu, { ContextMenuProps, ContextMenuItem } from "../../components/context-menu/context-menu";
+import { contextMenuActions } from "../../store/context-menu/context-menu-actions";
+import { ContextMenu as ContextMenuComponent, ContextMenuProps, ContextMenuItem } from "../../components/context-menu/context-menu";
 import { createAnchorAt } from "../../components/popover/helpers";
 import { ContextMenuResource } from "../../store/context-menu/context-menu-reducer";
-import { ContextMenuItemSet } from "./context-menu-item-set";
-import { emptyItemSet } from "./empty-item-set";
+import { ContextMenuActionSet, ContextMenuAction } from "./context-menu-action-set";
+import { Dispatch } from "redux";
 
-type DataProps = Pick<ContextMenuProps, "anchorEl" | "items"> & { resource?: ContextMenuResource };
+type DataProps = Pick<ContextMenuProps, "anchorEl" | "items" | "open"> & { resource?: ContextMenuResource };
 const mapStateToProps = (state: RootState): DataProps => {
-    const { position, resource } = state.contextMenu;
+    const { open, position, resource } = state.contextMenu;
     return {
         anchorEl: resource ? createAnchorAt(position) : undefined,
-        items: getMenuItemSet(resource).getItems(),
+        items: getMenuActionSet(resource),
+        open,
         resource
     };
 };
@@ -24,12 +25,12 @@ const mapStateToProps = (state: RootState): DataProps => {
 type ActionProps = Pick<ContextMenuProps, "onClose"> & { onItemClick: (item: ContextMenuItem, resource?: ContextMenuResource) => void };
 const mapDispatchToProps = (dispatch: Dispatch): ActionProps => ({
     onClose: () => {
-        dispatch(actions.CLOSE_CONTEXT_MENU());
+        dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
     },
-    onItemClick: (item: ContextMenuItem, resource?: ContextMenuResource) => {
-        dispatch(actions.CLOSE_CONTEXT_MENU());
+    onItemClick: (action: ContextMenuAction, resource?: ContextMenuResource) => {
+        dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
         if (resource) {
-            getMenuItemSet(resource).handleItem(dispatch, item, resource);
+            action.execute(dispatch, resource);
         }
     }
 });
@@ -42,15 +43,22 @@ const mergeProps = ({ resource, ...dataProps }: DataProps, actionProps: ActionPr
     }
 });
 
-export const ContextMenuHOC = connect(mapStateToProps, mapDispatchToProps, mergeProps)(ContextMenu);
+export const ContextMenu = connect(mapStateToProps, mapDispatchToProps, mergeProps)(ContextMenuComponent);
 
-const menuItemSets = new Map<string, ContextMenuItemSet>();
+const menuActionSets = new Map<string, ContextMenuActionSet>();
 
-export const addMenuItemsSet = (name: string, itemSet: ContextMenuItemSet) => {
-    menuItemSets.set(name, itemSet);
+export const addMenuActionSet = (name: string, itemSet: ContextMenuActionSet) => {
+    menuActionSets.set(name, itemSet);
 };
 
-const getMenuItemSet = (resource?: ContextMenuResource): ContextMenuItemSet => {
-    return resource ? menuItemSets.get(resource.kind) || emptyItemSet : emptyItemSet;
+const getMenuActionSet = (resource?: ContextMenuResource): ContextMenuActionSet => {
+    return resource ? menuActionSets.get(resource.kind) || [] : [];
 };
 
+export enum ContextMenuKind {
+    ROOT_PROJECT = "RootProject",
+    PROJECT = "Project",
+    RESOURCE = "Resource",
+    FAVORITE = "Favorite",
+    COLLECTION = 'Collection'
+}
