diff --git a/.changeset/tasty-carpets-fold.md b/.changeset/tasty-carpets-fold.md new file mode 100644 index 0000000000..a1e62413bc --- /dev/null +++ b/.changeset/tasty-carpets-fold.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-react': minor +--- + +**BREAKING**: Removed the `useEntityKinds` hook, use `catalogApi.getEntityFacets({ facets: ['kind'] })` instead. diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index c42bfdf8aa..e85f8d3c63 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -500,13 +500,6 @@ export function useEntity(): { refresh?: VoidFunction; }; -// @public @deprecated -export function useEntityKinds(): { - error: Error | undefined; - loading: boolean; - kinds: string[] | undefined; -}; - // @public export function useEntityList< EntityFilters extends DefaultEntityFilters = DefaultEntityFilters, diff --git a/plugins/catalog-react/src/hooks/index.ts b/plugins/catalog-react/src/hooks/index.ts index 445ed8c5af..40183c1035 100644 --- a/plugins/catalog-react/src/hooks/index.ts +++ b/plugins/catalog-react/src/hooks/index.ts @@ -34,7 +34,6 @@ export type { EntityListContextProps, } from './useEntityListProvider'; export { useEntityTypeFilter } from './useEntityTypeFilter'; -export { useEntityKinds } from './useEntityKinds'; export { useRelatedEntities } from './useRelatedEntities'; export { useStarredEntities } from './useStarredEntities'; export { useStarredEntity } from './useStarredEntity'; diff --git a/plugins/catalog-react/src/hooks/useEntityKinds.test.tsx b/plugins/catalog-react/src/hooks/useEntityKinds.test.tsx deleted file mode 100644 index c96301b3c4..0000000000 --- a/plugins/catalog-react/src/hooks/useEntityKinds.test.tsx +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2021 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 React, { PropsWithChildren } from 'react'; -import { CatalogApi } from '@backstage/catalog-client'; -import { catalogApiRef } from '../api'; -import { renderHook } from '@testing-library/react-hooks'; -import { useEntityKinds } from './useEntityKinds'; -import { TestApiProvider } from '@backstage/test-utils'; - -const mockCatalogApi: Partial = { - getEntityFacets: jest.fn().mockResolvedValue({ - facets: { - kind: [ - { value: 'Template', count: 2 }, - { value: 'System', count: 1 }, - { value: 'Component', count: 3 }, - ], - }, - }), -}; - -const wrapper = ({ children }: PropsWithChildren<{}>) => { - return ( - - {children} - - ); -}; - -describe('useEntityKinds', () => { - it('gets entity kinds', async () => { - const { result, waitForValueToChange } = renderHook( - () => useEntityKinds(), - { wrapper }, - ); - await waitForValueToChange(() => result.current); - expect(result.current.kinds).toEqual(['Component', 'System', 'Template']); - }); -}); diff --git a/plugins/catalog-react/src/hooks/useEntityKinds.ts b/plugins/catalog-react/src/hooks/useEntityKinds.ts deleted file mode 100644 index 3dfc31eb88..0000000000 --- a/plugins/catalog-react/src/hooks/useEntityKinds.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2021 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 useAsync from 'react-use/lib/useAsync'; -import { useApi } from '@backstage/core-plugin-api'; -import { catalogApiRef } from '../api'; - -/** - * Retrieve a list of unique entity kinds present in the catalog - * @public - * @deprecated and will be removed due to low utility value. - */ -export function useEntityKinds() { - const catalogApi = useApi(catalogApiRef); - - const { - error, - loading, - value: kinds, - } = useAsync(async () => { - return await catalogApi - .getEntityFacets({ facets: ['kind'] }) - .then(response => response.facets.kind?.map(f => f.value).sort() || []); - }); - return { error, loading, kinds }; -}