From 811ca4bbb282ebb6debfe81b9f816f2a12193281 Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Mon, 30 Nov 2020 21:54:55 +0100 Subject: [PATCH] Fix review comments --- .../catalog/src/components/isOwnerOf.test.ts | 2 +- plugins/catalog/src/components/isOwnerOf.ts | 4 ++-- plugins/catalog/src/components/useOwnUser.ts | 23 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/plugins/catalog/src/components/isOwnerOf.test.ts b/plugins/catalog/src/components/isOwnerOf.test.ts index 1cae1eb44a..dc1f2ab1a8 100644 --- a/plugins/catalog/src/components/isOwnerOf.test.ts +++ b/plugins/catalog/src/components/isOwnerOf.test.ts @@ -25,7 +25,7 @@ describe('isOwnerOf', () => { it('should be owned by user', () => { const ownerEntity = { kind: 'User', - metadata: { name: 'user' }, + metadata: { name: 'User', namespace: 'Default' }, } as Entity; const ownedEntity = { relations: [ diff --git a/plugins/catalog/src/components/isOwnerOf.ts b/plugins/catalog/src/components/isOwnerOf.ts index d095a77d91..455e06dc13 100644 --- a/plugins/catalog/src/components/isOwnerOf.ts +++ b/plugins/catalog/src/components/isOwnerOf.ts @@ -39,8 +39,8 @@ export function isOwnerOf(owner: Entity, owned: Entity) { possibleOwners.find( o => owner.kind.toLowerCase() === o.kind.toLowerCase() && - owner.namespace === o.namespace && - owner.name === o.name, + owner.namespace.toLowerCase() === o.namespace.toLowerCase() && + owner.name.toLowerCase() === o.name.toLowerCase(), ) !== undefined ) { return true; diff --git a/plugins/catalog/src/components/useOwnUser.ts b/plugins/catalog/src/components/useOwnUser.ts index 201366b4e8..a74b60481e 100644 --- a/plugins/catalog/src/components/useOwnUser.ts +++ b/plugins/catalog/src/components/useOwnUser.ts @@ -16,26 +16,25 @@ import { UserEntity } from '@backstage/catalog-model'; import { useAsync } from 'react-use'; +import { AsyncState } from 'react-use/lib/useAsync'; import { identityApiRef, useApi } from '@backstage/core'; import { catalogApiRef } from '../plugin'; /** * Get the group memberships of the logged-in user. */ -export function useOwnUser(): { - value?: UserEntity; - loading: boolean; - error?: Error; -} { +export function useOwnUser(): AsyncState { const catalogApi = useApi(catalogApiRef); const identityApi = useApi(identityApiRef); // TODO: get the full entity (or at least the full entity name) from the identityApi - return useAsync(async () => { - return (await catalogApi.getEntityByName({ - kind: 'User', - namespace: 'default', - name: identityApi.getUserId(), - })) as UserEntity; - }, [catalogApi, identityApi]); + return useAsync( + () => + catalogApi.getEntityByName({ + kind: 'User', + namespace: 'default', + name: identityApi.getUserId(), + }) as Promise, + [catalogApi, identityApi], + ); }