Merge pull request #6438 from prasaria/disable-menu-unregister-entity

add unstable prop for disabling unregister entity
This commit is contained in:
Ben Lambert
2021-07-12 17:52:02 +02:00
committed by GitHub
4 changed files with 32 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': patch
---
Add unstable prop for disabling unregister entity menu
@@ -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<HTMLButtonElement>();
@@ -82,6 +89,9 @@ export const EntityContextMenu = ({
<Divider key="the divider is here!" />,
];
const disableUnregister =
UNSTABLE_contextMenuOptions?.disableUnregister ?? false;
return (
<>
<IconButton
@@ -108,6 +118,7 @@ export const EntityContextMenu = ({
onClose();
onUnregisterEntity();
}}
disabled={disableUnregister}
>
<ListItemIcon>
<Cancel fontSize="small" />
@@ -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 = ({
<EntityLabels entity={entity} />
<EntityContextMenu
UNSTABLE_extraContextMenuItems={UNSTABLE_extraContextMenuItems}
UNSTABLE_contextMenuOptions={UNSTABLE_contextMenuOptions}
onUnregisterEntity={showRemovalDialog}
/>
</>
@@ -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 = ({
<EntityLabels entity={entity} />
<EntityContextMenu
UNSTABLE_extraContextMenuItems={UNSTABLE_extraContextMenuItems}
UNSTABLE_contextMenuOptions={UNSTABLE_contextMenuOptions}
onUnregisterEntity={showRemovalDialog}
/>
</>