diff --git a/.changeset/strong-suns-hope.md b/.changeset/strong-suns-hope.md new file mode 100644 index 0000000000..876f5f1618 --- /dev/null +++ b/.changeset/strong-suns-hope.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-react': minor +--- + +Removing the `EntityName` path for the `useEntityOwnership` as it has never worked correctly. Please pass in an entire `Entity` instead. diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 9468074455..78ad5d4b97 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -549,7 +549,7 @@ export function useEntityListProvider< // @public export function useEntityOwnership(): { loading: boolean; - isOwnedEntity: (entity: Entity | EntityName) => boolean; + isOwnedEntity: (entity: Entity) => boolean; }; // @alpha diff --git a/plugins/catalog-react/src/hooks/useEntityOwnership.ts b/plugins/catalog-react/src/hooks/useEntityOwnership.ts index 77f6c4bf24..de3eca9dab 100644 --- a/plugins/catalog-react/src/hooks/useEntityOwnership.ts +++ b/plugins/catalog-react/src/hooks/useEntityOwnership.ts @@ -17,7 +17,6 @@ import { CatalogApi } from '@backstage/catalog-client'; import { Entity, - EntityName, parseEntityRef, RELATION_MEMBER_OF, RELATION_OWNED_BY, @@ -77,7 +76,7 @@ export async function loadCatalogOwnerRefs( */ export function useEntityOwnership(): { loading: boolean; - isOwnedEntity: (entity: Entity | EntityName) => boolean; + isOwnedEntity: (entity: Entity) => boolean; } { const identityApi = useApi(identityApiRef); const catalogApi = useApi(catalogApiRef); @@ -94,12 +93,10 @@ export function useEntityOwnership(): { const isOwnedEntity = useMemo(() => { const myOwnerRefs = new Set(refs ?? []); - return (entity: Entity | EntityName) => { - const entityOwnerRefs = ( - 'metadata' in entity - ? getEntityRelations(entity, RELATION_OWNED_BY) - : [entity] - ).map(stringifyEntityRef); + return (entity: Entity) => { + const entityOwnerRefs = getEntityRelations(entity, RELATION_OWNED_BY).map( + stringifyEntityRef, + ); for (const ref of entityOwnerRefs) { if (myOwnerRefs.has(ref)) { return true;