catalog-react: removed useOwnUser

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-03-04 16:03:51 +01:00
parent 3d31da90c9
commit fc6290a76d
7 changed files with 5 additions and 79 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-react': minor
---
**BREAKING**: Removed the deprecated `useOwnUser` hook. Existing usage can be replaced with `identityApi.getBackstageIdentity()`, followed by a call to `catalogClient.getEntityByRef(identity.userEntityRef)`.
-5
View File
@@ -6,7 +6,6 @@
/// <reference types="react" />
import { ApiRef } from '@backstage/core-plugin-api';
import { AsyncState } from 'react-use/lib/useAsync';
import { CATALOG_FILTER_EXISTS } from '@backstage/catalog-client';
import { CatalogApi } from '@backstage/catalog-client';
import { ComponentEntity } from '@backstage/catalog-model';
@@ -27,7 +26,6 @@ import { ScmIntegrationRegistry } from '@backstage/integration';
import { StyleRules } from '@material-ui/core/styles/withStyles';
import { SystemEntity } from '@backstage/catalog-model';
import { TableColumn } from '@backstage/core-components';
import { UserEntity } from '@backstage/catalog-model';
// @public
export const AsyncEntityProvider: ({
@@ -555,9 +553,6 @@ export function useOwnedEntities(allowedKinds?: string[]): {
ownedEntities: GetEntitiesResponse | undefined;
};
// @public @deprecated
export function useOwnUser(): AsyncState<UserEntity | undefined>;
// @public (undocumented)
export function useRelatedEntities(
entity: Entity,
-1
View File
@@ -37,7 +37,6 @@ export type {
export { useEntityTypeFilter } from './useEntityTypeFilter';
export type { EntityTypeReturn } from './useEntityTypeFilter';
export { useEntityKinds } from './useEntityKinds';
export { useOwnUser } from './useOwnUser';
export { useRelatedEntities } from './useRelatedEntities';
export { useStarredEntities } from './useStarredEntities';
export { useStarredEntity } from './useStarredEntity';
@@ -1,49 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
DEFAULT_NAMESPACE,
parseEntityRef,
UserEntity,
} from '@backstage/catalog-model';
import useAsync, { AsyncState } from 'react-use/lib/useAsync';
import { catalogApiRef } from '../api';
import { identityApiRef, useApi } from '@backstage/core-plugin-api';
/**
* Get the catalog User entity (if any) that matches the logged-in user.
* @public
* @deprecated due to low external usage.
*/
export function useOwnUser(): AsyncState<UserEntity | undefined> {
const catalogApi = useApi(catalogApiRef);
const identityApi = useApi(identityApiRef);
return useAsync(async () => {
const identity = await identityApi.getBackstageIdentity();
// 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,
}),
) as Promise<UserEntity | undefined>;
}, [catalogApi, identityApi]);
}
@@ -36,14 +36,6 @@ import React from 'react';
import { rootDocsRouteRef } from '../../routes';
import { DefaultTechDocsHome } from './DefaultTechDocsHome';
jest.mock('@backstage/plugin-catalog-react', () => {
const actual = jest.requireActual('@backstage/plugin-catalog-react');
return {
...actual,
useOwnUser: () => 'test-user',
};
});
const mockCatalogApi = {
getEntityByRef: () => Promise.resolve(),
getEntities: async () => ({
@@ -24,14 +24,6 @@ import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import { ConfigApi, configApiRef } from '@backstage/core-plugin-api';
import { rootDocsRouteRef } from '../../routes';
jest.mock('@backstage/plugin-catalog-react', () => {
const actual = jest.requireActual('@backstage/plugin-catalog-react');
return {
...actual,
useOwnUser: () => 'test-user',
};
});
const mockCatalogApi = {
getEntityByRef: jest.fn(),
getEntities: async () => ({
@@ -22,14 +22,6 @@ import { TechDocsCustomHome, PanelType } from './TechDocsCustomHome';
import { ApiProvider } from '@backstage/core-app-api';
import { rootDocsRouteRef } from '../../routes';
jest.mock('@backstage/plugin-catalog-react', () => {
const actual = jest.requireActual('@backstage/plugin-catalog-react');
return {
...actual,
useOwnUser: () => 'test-user',
};
});
const mockCatalogApi = {
getEntityByRef: jest.fn(),
getEntities: async () => ({