update to use getEntityByRef

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-03-03 11:26:42 +01:00
parent a52f69987a
commit 899f196af5
41 changed files with 157 additions and 111 deletions
@@ -45,7 +45,7 @@ jest.mock('@backstage/plugin-catalog-react', () => {
});
const mockCatalogApi = {
getEntityByName: () => Promise.resolve(),
getEntityByRef: () => Promise.resolve(),
getEntities: async () => ({
items: [
{
@@ -33,7 +33,7 @@ jest.mock('@backstage/plugin-catalog-react', () => {
});
const mockCatalogApi = {
getEntityByName: jest.fn(),
getEntityByRef: jest.fn(),
getEntities: async () => ({
items: [
{
@@ -31,7 +31,7 @@ jest.mock('@backstage/plugin-catalog-react', () => {
});
const mockCatalogApi = {
getEntityByName: jest.fn(),
getEntityByRef: jest.fn(),
getEntities: async () => ({
items: [
{
@@ -232,7 +232,12 @@ function useOwnUser(): AsyncState<UserEntity | undefined> {
return useAsync(async () => {
const identity = await identityApi.getBackstageIdentity();
return catalogApi.getEntityByName(
// TODO(freben): Defensively parse with defaults even though getEntityByRef
// supports the string form, since some auth resolvers have been known to
// return incomplete refs (just the name part) historically. This can be
// simplified in the future to just pass the ref immediately to
// getEntityByRef.
return catalogApi.getEntityByRef(
parseEntityRef(identity.userEntityRef, {
defaultKind: 'User',
defaultNamespace: DEFAULT_NAMESPACE,