From 460561b1693410f59b0423b271eb4a3c94f61edb Mon Sep 17 00:00:00 2001 From: CTomlyn Date: Tue, 16 Jan 2024 09:47:54 -0800 Subject: [PATCH] #1662 Missing action from submenu causes multiple context-menu cascade menus to appear (#1663) --- .../src/context-menu/common-context-menu.jsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/canvas_modules/common-canvas/src/context-menu/common-context-menu.jsx b/canvas_modules/common-canvas/src/context-menu/common-context-menu.jsx index b90c3e6f3e..fe80037312 100644 --- a/canvas_modules/common-canvas/src/context-menu/common-context-menu.jsx +++ b/canvas_modules/common-canvas/src/context-menu/common-context-menu.jsx @@ -258,6 +258,19 @@ class CommonContextMenu extends React.Component { return subMenuPosStyle; } + // Returns the menu definition array passed in making sure any + // submenu items have an action. Note: some applications forget + // to do provide an action because for the submenu it is only + // used by the context menu code. + ensureAllSubMenuItemsHaveAction(menuDef) { + return menuDef.map((item, index) => { + if (item.submenu && typeof item.action === "undefined") { + return { ...item, action: "submenu_" + index }; + } + return item; + }); + } + render() { // Reposition contextMenu so that it does not show off the screen const menuSize = this.calculateMenuSize(this.props.menuDefinition); @@ -267,7 +280,8 @@ class CommonContextMenu extends React.Component { top: menuPos.y + "px" }; - const menuItems = this.buildMenu(this.props.menuDefinition, menuSize, menuPos, this.props.canvasRect); + const menuDefinition = this.ensureAllSubMenuItemsHaveAction(this.props.menuDefinition); + const menuItems = this.buildMenu(menuDefinition, menuSize, menuPos, this.props.canvasRect); return (