From 75a532fbe9aa7db6a00d73a343933aaa77c6771a Mon Sep 17 00:00:00 2001 From: Prasetya Aria Wibawa Date: Mon, 12 Jul 2021 20:34:30 +0700 Subject: [PATCH] add unstable prop for disabling unregister entity Signed-off-by: Prasetya Aria Wibawa --- .changeset/angry-rules-fail.md | 5 +++++ .../EntityContextMenu/EntityContextMenu.tsx | 11 +++++++++++ .../src/components/EntityLayout/EntityLayout.tsx | 8 ++++++++ .../components/EntityPageLayout/EntityPageLayout.tsx | 8 ++++++++ 4 files changed, 32 insertions(+) create mode 100644 .changeset/angry-rules-fail.md diff --git a/.changeset/angry-rules-fail.md b/.changeset/angry-rules-fail.md new file mode 100644 index 0000000000..cc52d4478e --- /dev/null +++ b/.changeset/angry-rules-fail.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': patch +--- + +Add unstable prop for disabling unregister entity menu diff --git a/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx b/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx index 05d93078b4..f8a724c9d7 100644 --- a/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx +++ b/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx @@ -44,13 +44,20 @@ type ExtraContextMenuItem = { onClick: () => void; }; +// unstable context menu option, eg: disable the unregister entity menu +type contextMenuOptions = { + disableUnregister: boolean; +}; + type Props = { UNSTABLE_extraContextMenuItems?: ExtraContextMenuItem[]; + UNSTABLE_contextMenuOptions?: contextMenuOptions; onUnregisterEntity: () => void; }; export const EntityContextMenu = ({ UNSTABLE_extraContextMenuItems, + UNSTABLE_contextMenuOptions, onUnregisterEntity, }: Props) => { const [anchorEl, setAnchorEl] = useState(); @@ -82,6 +89,9 @@ export const EntityContextMenu = ({ , ]; + const disableUnregister = + UNSTABLE_contextMenuOptions?.disableUnregister ?? false; + return ( <> diff --git a/plugins/catalog/src/components/EntityLayout/EntityLayout.tsx b/plugins/catalog/src/components/EntityLayout/EntityLayout.tsx index 9513050400..9cb0b7c961 100644 --- a/plugins/catalog/src/components/EntityLayout/EntityLayout.tsx +++ b/plugins/catalog/src/components/EntityLayout/EntityLayout.tsx @@ -132,8 +132,14 @@ type ExtraContextMenuItem = { onClick: () => void; }; +// unstable context menu option, eg: disable the unregister entity menu +type contextMenuOptions = { + disableUnregister: boolean; +}; + type EntityLayoutProps = { UNSTABLE_extraContextMenuItems?: ExtraContextMenuItem[]; + UNSTABLE_contextMenuOptions?: contextMenuOptions; children?: React.ReactNode; }; @@ -154,6 +160,7 @@ type EntityLayoutProps = { */ export const EntityLayout = ({ UNSTABLE_extraContextMenuItems, + UNSTABLE_contextMenuOptions, children, }: EntityLayoutProps) => { const { kind, namespace, name } = useEntityCompoundName(); @@ -210,6 +217,7 @@ export const EntityLayout = ({ diff --git a/plugins/catalog/src/components/EntityPageLayout/EntityPageLayout.tsx b/plugins/catalog/src/components/EntityPageLayout/EntityPageLayout.tsx index 99052e51f0..4abac4e01b 100644 --- a/plugins/catalog/src/components/EntityPageLayout/EntityPageLayout.tsx +++ b/plugins/catalog/src/components/EntityPageLayout/EntityPageLayout.tsx @@ -112,14 +112,21 @@ type ExtraContextMenuItem = { onClick: () => void; }; +// unstable context menu option, eg: disable the unregister entity menu +type contextMenuOptions = { + disableUnregister: boolean; +}; + type EntityPageLayoutProps = { UNSTABLE_extraContextMenuItems?: ExtraContextMenuItem[]; + UNSTABLE_contextMenuOptions?: contextMenuOptions; children?: React.ReactNode; }; export const EntityPageLayout = ({ children, UNSTABLE_extraContextMenuItems, + UNSTABLE_contextMenuOptions, }: EntityPageLayoutProps) => { const { kind, namespace, name } = useEntityCompoundName(); const { entity, loading, error } = useContext(EntityContext); @@ -152,6 +159,7 @@ export const EntityPageLayout = ({