diff --git a/.changeset/weak-schools-wash.md b/.changeset/weak-schools-wash.md new file mode 100644 index 0000000000..86f3111d93 --- /dev/null +++ b/.changeset/weak-schools-wash.md @@ -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)`. diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 08252b0fc5..c42bfdf8aa 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -6,7 +6,6 @@ /// 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'; @@ -26,7 +25,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: ({ @@ -536,9 +534,6 @@ export function useEntityTypeFilter(): { setSelectedTypes: (types: string[]) => void; }; -// @public @deprecated -export function useOwnUser(): AsyncState; - // @public (undocumented) export function useRelatedEntities( entity: Entity, diff --git a/plugins/catalog-react/src/hooks/index.ts b/plugins/catalog-react/src/hooks/index.ts index d90e0eb06e..445ed8c5af 100644 --- a/plugins/catalog-react/src/hooks/index.ts +++ b/plugins/catalog-react/src/hooks/index.ts @@ -35,7 +35,6 @@ export type { } from './useEntityListProvider'; export { useEntityTypeFilter } from './useEntityTypeFilter'; export { useEntityKinds } from './useEntityKinds'; -export { useOwnUser } from './useOwnUser'; export { useRelatedEntities } from './useRelatedEntities'; export { useStarredEntities } from './useStarredEntities'; export { useStarredEntity } from './useStarredEntity'; diff --git a/plugins/catalog-react/src/hooks/useOwnUser.ts b/plugins/catalog-react/src/hooks/useOwnUser.ts deleted file mode 100644 index 211321afdf..0000000000 --- a/plugins/catalog-react/src/hooks/useOwnUser.ts +++ /dev/null @@ -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 { - 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; - }, [catalogApi, identityApi]); -} diff --git a/plugins/techdocs/src/home/components/DefaultTechDocsHome.test.tsx b/plugins/techdocs/src/home/components/DefaultTechDocsHome.test.tsx index 14fdb88395..48c1fa248c 100644 --- a/plugins/techdocs/src/home/components/DefaultTechDocsHome.test.tsx +++ b/plugins/techdocs/src/home/components/DefaultTechDocsHome.test.tsx @@ -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 () => ({ diff --git a/plugins/techdocs/src/home/components/LegacyTechDocsHome.test.tsx b/plugins/techdocs/src/home/components/LegacyTechDocsHome.test.tsx index 16d8d48bc3..4c33f69fb7 100644 --- a/plugins/techdocs/src/home/components/LegacyTechDocsHome.test.tsx +++ b/plugins/techdocs/src/home/components/LegacyTechDocsHome.test.tsx @@ -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 () => ({ diff --git a/plugins/techdocs/src/home/components/TechDocsCustomHome.test.tsx b/plugins/techdocs/src/home/components/TechDocsCustomHome.test.tsx index 2088dbf4fc..6f09a70b5e 100644 --- a/plugins/techdocs/src/home/components/TechDocsCustomHome.test.tsx +++ b/plugins/techdocs/src/home/components/TechDocsCustomHome.test.tsx @@ -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 () => ({