From 69d652f3cc4b6071a004ba816c52a503812853ba Mon Sep 17 00:00:00 2001 From: Prasetya Aria Wibawa Date: Fri, 4 Mar 2022 15:15:17 +0700 Subject: [PATCH] use relations.ownedBy for filter params in getEntities Signed-off-by: Prasetya Aria Wibawa --- .../OwnershipCard/useAggregatedEntities.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/org/src/components/Cards/OwnershipCard/useAggregatedEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useAggregatedEntities.ts index e6ef55b32b..52390cccef 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useAggregatedEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useAggregatedEntities.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { Entity, RELATION_PARENT_OF } from '@backstage/catalog-model'; +import { + Entity, + RELATION_PARENT_OF, + stringifyEntityRef, +} from '@backstage/catalog-model'; import { catalogApiRef, getEntityRelations, @@ -33,10 +37,12 @@ type EntityTypeProps = { }; const getQueryParams = ( - owners: string[], + ownerEntitiesRef: string[], selectedEntity: EntityTypeProps, ): string => { const { kind, type } = selectedEntity; + // removing 'group:default/' from the string entity ref 'group:default/team-a' + const owners = ownerEntitiesRef.map(owner => owner.split('/')[1]); const filters = { kind, type, @@ -104,7 +110,13 @@ export function useAggregatedEntities( ), ); requestedEntities.shift(); - processedEntities.add(currentEntity.metadata.name); + processedEntities.add( + stringifyEntityRef({ + kind: currentEntity.kind, + namespace: currentEntity.metadata.namespace, + name: currentEntity.metadata.name, + }), + ); // always set currentEntity to the first element of array requestedEntities currentEntity = requestedEntities[0]; } @@ -114,7 +126,7 @@ export function useAggregatedEntities( filter: [ { kind: kinds, - 'spec.owner': owners, + 'relations.ownedBy': owners, }, ], fields: [