From 8048fe0cd2bc9861406544d02c232d460ddcd4bd Mon Sep 17 00:00:00 2001 From: Mark Dunphy Date: Mon, 7 Apr 2025 17:35:20 -0400 Subject: [PATCH] avoid exporting MUI types, update click handler to support async and sync functions. ensure onClick handler passed to MenuItem is sync Signed-off-by: Mark Dunphy --- .../EntityContextMenuItemBlueprint.tsx | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.tsx b/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.tsx index 75e8d1ff47..2e46e38c2a 100644 --- a/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.tsx +++ b/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.tsx @@ -20,15 +20,26 @@ import { createExtensionDataRef, ExtensionBoundary, } from '@backstage/frontend-plugin-api'; -import MenuItem, { MenuItemProps } from '@material-ui/core/MenuItem'; +import MenuItem from '@material-ui/core/MenuItem'; import ListItemIcon from '@material-ui/core/ListItemIcon'; import ListItemText from '@material-ui/core/ListItemText'; +/** @alpha */ +export type UseProps = () => + | { + title: React.ReactNode; + href: string; + disabled?: boolean; + } + | { + title: React.ReactNode; + onClick: () => void | Promise; + disabled?: boolean; + }; + /** @alpha */ export type EntityContextMenuItemParams = { - useProps: () => Omit & { - onClick?: () => Promise; - }; + useProps: UseProps; icon: React.JSX.Element; }; @@ -56,24 +67,22 @@ export const EntityContextMenuItemBlueprint = createExtensionBlueprint({ *factory(params: EntityContextMenuItemParams, { node }) { const loader = async (): Promise => { return ({ onClose }) => { - const { - children, - button, - title, - onClick: onClickProp, - ...menuItemProps - } = params.useProps(); - let onClick; + const { title, ...menuItemProps } = params.useProps(); + let handleClick = undefined; - if (onClickProp !== undefined) { - onClick = async () => { - await onClickProp(); - onClose(); + if ('onClick' in menuItemProps) { + handleClick = () => { + const result = menuItemProps.onClick(); + if (result instanceof Promise) { + result.then(onClose); + } else { + onClose(); + } }; } return ( - + {params.icon}