Merge pull request #9538 from backstage/vinzscam/fix-catalog-owned-filter
Fix Catalog page showing all components when owned filter was pre-selected
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-react': patch
|
||||
---
|
||||
|
||||
Fix CatalogPage showing all components when owned filter was pre-selected
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
identityApiRef,
|
||||
storageApiRef,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { useEntityOwnership } from '../../hooks';
|
||||
|
||||
const mockUser: UserEntity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
@@ -81,9 +82,9 @@ jest.mock('../../hooks', () => {
|
||||
const actual = jest.requireActual('../../hooks');
|
||||
return {
|
||||
...actual,
|
||||
useEntityOwnership: () => ({
|
||||
useEntityOwnership: jest.fn(() => ({
|
||||
isOwnedEntity: mockIsOwnedEntity,
|
||||
}),
|
||||
})),
|
||||
useStarredEntities: () => ({
|
||||
isStarredEntity: mockIsStarredEntity,
|
||||
}),
|
||||
@@ -327,6 +328,19 @@ describe('<UserListPicker />', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not reset the filter while owned entities are loading', () => {
|
||||
const isOwnedEntity = jest.fn(() => false);
|
||||
(useEntityOwnership as jest.Mock).mockReturnValueOnce({
|
||||
loading: true,
|
||||
isOwnedEntity,
|
||||
});
|
||||
|
||||
render(picker({ loading: false }));
|
||||
expect(updateFilters).not.toHaveBeenCalledWith({
|
||||
user: new UserListFilter('all', isOwnedEntity, mockIsStarredEntity),
|
||||
});
|
||||
});
|
||||
|
||||
it('resets the filter to "all" when entities are loaded', () => {
|
||||
render(picker({ loading: false }));
|
||||
|
||||
|
||||
@@ -130,8 +130,13 @@ export const UserListPicker = ({
|
||||
const classes = useStyles();
|
||||
const configApi = useApi(configApiRef);
|
||||
const orgName = configApi.getOptionalString('organization.name') ?? 'Company';
|
||||
const { filters, updateFilters, backendEntities, queryParameters, loading } =
|
||||
useEntityListProvider();
|
||||
const {
|
||||
filters,
|
||||
updateFilters,
|
||||
backendEntities,
|
||||
queryParameters,
|
||||
loading: loadingBackendEntities,
|
||||
} = useEntityListProvider();
|
||||
|
||||
// Remove group items that aren't in availableFilters and exclude
|
||||
// any now-empty groups.
|
||||
@@ -149,7 +154,10 @@ export const UserListPicker = ({
|
||||
.filter(({ items }) => !!items.length);
|
||||
|
||||
const { isStarredEntity } = useStarredEntities();
|
||||
const { isOwnedEntity } = useEntityOwnership();
|
||||
const { isOwnedEntity, loading: loadingEntityOwnership } =
|
||||
useEntityOwnership();
|
||||
|
||||
const loading = loadingBackendEntities || loadingEntityOwnership;
|
||||
|
||||
// Static filters; used for generating counts of potentially unselected kinds
|
||||
const ownedFilter = useMemo(
|
||||
|
||||
Reference in New Issue
Block a user