Merge pull request #9992 from backstage/jhaals/rem-useEntityKinds
catalog-react: Remove useEntityKinds
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-react': minor
|
||||
---
|
||||
|
||||
**BREAKING**: Removed the `useEntityKinds` hook, use `catalogApi.getEntityFacets({ facets: ['kind'] })` instead.
|
||||
@@ -500,13 +500,6 @@ export function useEntity<TEntity extends Entity = Entity>(): {
|
||||
refresh?: VoidFunction;
|
||||
};
|
||||
|
||||
// @public @deprecated
|
||||
export function useEntityKinds(): {
|
||||
error: Error | undefined;
|
||||
loading: boolean;
|
||||
kinds: string[] | undefined;
|
||||
};
|
||||
|
||||
// @public
|
||||
export function useEntityList<
|
||||
EntityFilters extends DefaultEntityFilters = DefaultEntityFilters,
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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<CatalogApi> = {
|
||||
getEntityFacets: jest.fn().mockResolvedValue({
|
||||
facets: {
|
||||
kind: [
|
||||
{ value: 'Template', count: 2 },
|
||||
{ value: 'System', count: 1 },
|
||||
{ value: 'Component', count: 3 },
|
||||
],
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const wrapper = ({ children }: PropsWithChildren<{}>) => {
|
||||
return (
|
||||
<TestApiProvider apis={[[catalogApiRef, mockCatalogApi]]}>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
);
|
||||
};
|
||||
|
||||
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']);
|
||||
});
|
||||
});
|
||||
@@ -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 };
|
||||
}
|
||||
Reference in New Issue
Block a user