From 5ed70bf42eba2f0ce29618e1a5e1c4559e70ff01 Mon Sep 17 00:00:00 2001 From: Mark Dunphy Date: Tue, 8 Apr 2025 08:06:57 -0400 Subject: [PATCH] Add example to changeset, remove instanceof Promise check Signed-off-by: Mark Dunphy --- .changeset/proud-dots-fry.md | 33 ++++++++++++++++++- .../EntityContextMenuItemBlueprint.tsx | 4 +-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.changeset/proud-dots-fry.md b/.changeset/proud-dots-fry.md index 2b75355332..2895f3d720 100644 --- a/.changeset/proud-dots-fry.md +++ b/.changeset/proud-dots-fry.md @@ -3,4 +3,35 @@ '@backstage/plugin-catalog': minor --- -Adds `EntityContextMenuItemBlueprint` to enable extending the entity page's context menu +Adds `EntityContextMenuItemBlueprint` to enable extending the entity page's context menu with user defined items. + +For example: + +```ts +import { EntityContextMenuItemBlueprint } from '@backstage/plugin-catalog-react/alpha'; + +const myCustomHref = EntityContextMenuItemBlueprint.make({ + name: 'test-href', + params: { + icon: Example Icon, + useProps: () => ({ + title: 'Example Href', + href: '/example-path', + disabled: false, + component: 'a', + }), + }, +}); + +const myCustomOnClick = EntityContextMenuItemBlueprint.make({ + name: 'test-click', + params: { + icon: Test Icon, + useProps: () => ({ + title: 'Example onClick', + onClick: () => window.alert('Hello world!'), + disabled: false, + }), + }, +}); +``` diff --git a/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.tsx b/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.tsx index 2e46e38c2a..e76830eaf6 100644 --- a/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.tsx +++ b/plugins/catalog-react/src/alpha/blueprints/EntityContextMenuItemBlueprint.tsx @@ -73,8 +73,8 @@ export const EntityContextMenuItemBlueprint = createExtensionBlueprint({ if ('onClick' in menuItemProps) { handleClick = () => { const result = menuItemProps.onClick(); - if (result instanceof Promise) { - result.then(onClose); + if (result && 'finally' in result) { + result.finally(onClose); } else { onClose(); }