From b759a21c96ef61f1b70c5af1f48ac6e3a40359f2 Mon Sep 17 00:00:00 2001 From: Prasetya Aria Wibawa Date: Wed, 2 Mar 2022 16:56:32 +0700 Subject: [PATCH] change isOwnerOf to use filter relations.ownedBy Signed-off-by: Prasetya Aria Wibawa --- .../Cards/OwnershipCard/useDirectEntities.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/org/src/components/Cards/OwnershipCard/useDirectEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useDirectEntities.ts index 9ad4843040..da50842fea 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useDirectEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useDirectEntities.ts @@ -14,12 +14,15 @@ * limitations under the License. */ -import { Entity, RELATION_MEMBER_OF } from '@backstage/catalog-model'; +import { + Entity, + RELATION_MEMBER_OF, + stringifyEntityRef, +} from '@backstage/catalog-model'; import { useApi } from '@backstage/core-plugin-api'; import { catalogApiRef, formatEntityRefTitle, - isOwnerOf, getEntityRelations, } from '@backstage/plugin-catalog-react'; import qs from 'qs'; @@ -80,10 +83,13 @@ export function useDirectEntities( value: componentsWithCounters, } = useAsync(async () => { const kinds = entityFilterKind ?? ['Component', 'API', 'System']; - const entitiesList = await catalogApi.getEntities({ - filter: { - kind: kinds, - }, + const ownedEntitiesListResponse = await catalogApi.getEntities({ + filter: [ + { + kind: kinds, + 'relations.ownedBy': [stringifyEntityRef(entity)], + }, + ], fields: [ 'kind', 'metadata.name', @@ -93,11 +99,7 @@ export function useDirectEntities( ], }); - const ownedEntitiesList = entitiesList.items.filter(component => - isOwnerOf(entity, component), - ); - - const counts = ownedEntitiesList.reduce( + const counts = ownedEntitiesListResponse.items.reduce( (acc: EntityTypeProps[], ownedEntity) => { const match = acc.find( x =>