From 5606d6065b07e1efc4debd31b7703df65b29f3e9 Mon Sep 17 00:00:00 2001 From: Prasetya Aria Wibawa Date: Wed, 2 Mar 2022 16:34:10 +0700 Subject: [PATCH] use getEntityRelations to get all memberOf groups Signed-off-by: Prasetya Aria Wibawa --- .../Cards/OwnershipCard/useDirectEntities.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/org/src/components/Cards/OwnershipCard/useDirectEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useDirectEntities.ts index 48e6c9d74b..9ad4843040 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useDirectEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useDirectEntities.ts @@ -14,12 +14,13 @@ * limitations under the License. */ -import { Entity, UserEntity } from '@backstage/catalog-model'; +import { Entity, RELATION_MEMBER_OF } 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'; import useAsync from 'react-use/lib/useAsync'; @@ -43,8 +44,11 @@ const getQueryParams = ( user: 'all', }; if (owner.kind === 'User') { - const user = owner as UserEntity; - filters.owners = [...filters.owners, ...user.spec.memberOf]; + const ownerGroups = getEntityRelations(owner, RELATION_MEMBER_OF, { + kind: 'Group', + }); + const ownerGroupsName = ownerGroups.map(ownerGroup => ownerGroup.name); + filters.owners = [...filters.owners, ...ownerGroupsName]; } const queryParams = qs.stringify({ filters,