X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e7253b56d761c939f1bc890a6b8c4087eab1410d..c27efd822acfd3bd93fc3e2e3e24a24146811eb7:/src/views-components/context-menu/context-menu.tsx?ds=sidebyside

diff --git a/src/views-components/context-menu/context-menu.tsx b/src/views-components/context-menu/context-menu.tsx
index bfd833a8..30ecc981 100644
--- a/src/views-components/context-menu/context-menu.tsx
+++ b/src/views-components/context-menu/context-menu.tsx
@@ -2,36 +2,34 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { connect, Dispatch, DispatchProp } from "react-redux";
-import { RootState } from "../../store/store";
-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, ContextMenuKind } from "../../store/context-menu/context-menu-reducer";
+import { connect } from "react-redux";
+import { RootState } from "~/store/store";
+import { contextMenuActions, ContextMenuResource } 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 { ContextMenuActionSet, ContextMenuAction } from "./context-menu-action-set";
+import { Dispatch } from "redux";
 
-
-type DataProps = Pick<ContextMenuProps, "anchorEl" | "actions"> & { 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,
-        actions: resource ? menuActions[resource.kind] : [],
+        items: getMenuActionSet(resource),
+        open,
         resource
     };
 };
 
-type ActionProps = Pick<ContextMenuProps, "onClose"> & { onActionClick: (action: ContextMenuAction, resource?: ContextMenuResource) => void };
+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());
     },
-    onActionClick: (action: ContextMenuAction, resource?: ContextMenuResource) => {
-        dispatch(actions.CLOSE_CONTEXT_MENU());
+    onItemClick: (action: ContextMenuAction, resource?: ContextMenuResource) => {
+        dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
         if (resource) {
-            if (action.name === "New project") {
-                dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: resource.uuid }));
-            }
+            action.execute(dispatch, resource);
         }
     }
 });
@@ -39,65 +37,37 @@ const mapDispatchToProps = (dispatch: Dispatch): ActionProps => ({
 const mergeProps = ({ resource, ...dataProps }: DataProps, actionProps: ActionProps): ContextMenuProps => ({
     ...dataProps,
     ...actionProps,
-    onActionClick: (action: ContextMenuAction) => {
-        actionProps.onActionClick(action, resource);
+    onItemClick: item => {
+        actionProps.onItemClick(item, resource);
     }
 });
 
-export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ContextMenu);
+export const ContextMenu = connect(mapStateToProps, mapDispatchToProps, mergeProps)(ContextMenuComponent);
 
-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"
-    }
-    ]]
+const menuActionSets = new Map<string, ContextMenuActionSet>();
+
+export const addMenuActionSet = (name: string, itemSet: ContextMenuActionSet) => {
+    menuActionSets.set(name, itemSet);
 };
+
+const getMenuActionSet = (resource?: ContextMenuResource): ContextMenuActionSet => {
+    return resource ? menuActionSets.get(resource.menuKind) || [] : [];
+};
+
+export enum ContextMenuKind {
+    ROOT_PROJECT = "RootProject",
+    PROJECT = "Project",
+    RESOURCE = "Resource",
+    FAVORITE = "Favorite",
+    TRASH = "Trash",
+    COLLECTION_FILES = "CollectionFiles",
+    COLLECTION_FILES_ITEM = "CollectionFilesItem",
+    COLLECTION_FILES_NOT_SELECTED = "CollectionFilesNotSelected",
+    COLLECTION = 'Collection',
+    COLLECTION_RESOURCE = 'CollectionResource',
+    TRASHED_COLLECTION = 'TrashedCollection',
+    PROCESS = "Process",
+    PROCESS_RESOURCE = 'ProcessResource',
+    PROCESS_LOGS = "ProcessLogs",
+    REPOSITORY = "Repository"
+}
