diff --git a/plugins/catalog-react/src/components/EntityLifecyclePicker/EntityLifecyclePicker.test.tsx b/plugins/catalog-react/src/components/EntityLifecyclePicker/EntityLifecyclePicker.test.tsx index f925625b23..ef77f7615f 100644 --- a/plugins/catalog-react/src/components/EntityLifecyclePicker/EntityLifecyclePicker.test.tsx +++ b/plugins/catalog-react/src/components/EntityLifecyclePicker/EntityLifecyclePicker.test.tsx @@ -169,6 +169,7 @@ describe('', () => { value={{ updateFilters, queryParameters: { lifecycles: ['experimental'] }, + backendEntities: sampleEntities, }} > @@ -182,6 +183,7 @@ describe('', () => { value={{ updateFilters, queryParameters: { lifecycles: ['production'] }, + backendEntities: sampleEntities, }} > @@ -191,4 +193,21 @@ describe('', () => { lifecycles: new EntityLifecycleFilter(['production']), }); }); + it('removes lifecycles from filters if there are no available lifecycles', () => { + const updateFilters = jest.fn(); + render( + + + , + ); + expect(updateFilters).toHaveBeenLastCalledWith({ + lifecycles: undefined, + }); + }); }); diff --git a/plugins/catalog-react/src/components/EntityLifecyclePicker/EntityLifecyclePicker.tsx b/plugins/catalog-react/src/components/EntityLifecyclePicker/EntityLifecyclePicker.tsx index f6e6b4eeaa..b941f94531 100644 --- a/plugins/catalog-react/src/components/EntityLifecyclePicker/EntityLifecyclePicker.tsx +++ b/plugins/catalog-react/src/components/EntityLifecyclePicker/EntityLifecyclePicker.tsx @@ -75,14 +75,6 @@ export const EntityLifecyclePicker = () => { } }, [queryParamLifecycles]); - useEffect(() => { - updateFilters({ - lifecycles: selectedLifecycles.length - ? new EntityLifecycleFilter(selectedLifecycles) - : undefined, - }); - }, [selectedLifecycles, updateFilters]); - const availableLifecycles = useMemo( () => [ @@ -95,6 +87,15 @@ export const EntityLifecyclePicker = () => { [backendEntities], ); + useEffect(() => { + updateFilters({ + lifecycles: + selectedLifecycles.length && availableLifecycles.length + ? new EntityLifecycleFilter(selectedLifecycles) + : undefined, + }); + }, [selectedLifecycles, updateFilters, availableLifecycles]); + if (!availableLifecycles.length) return null; return ( diff --git a/plugins/catalog-react/src/components/EntityOwnerPicker/EntityOwnerPicker.test.tsx b/plugins/catalog-react/src/components/EntityOwnerPicker/EntityOwnerPicker.test.tsx index c816810b10..b6e928b519 100644 --- a/plugins/catalog-react/src/components/EntityOwnerPicker/EntityOwnerPicker.test.tsx +++ b/plugins/catalog-react/src/components/EntityOwnerPicker/EntityOwnerPicker.test.tsx @@ -183,6 +183,7 @@ describe('', () => { value={{ updateFilters, queryParameters: { owners: ['team-a'] }, + backendEntities: sampleEntities, }} > @@ -196,6 +197,7 @@ describe('', () => { value={{ updateFilters, queryParameters: { owners: ['team-b'] }, + backendEntities: sampleEntities, }} > @@ -205,4 +207,21 @@ describe('', () => { owners: new EntityOwnerFilter(['team-b']), }); }); + it('removes owners from filters if there are none available', () => { + const updateFilters = jest.fn(); + render( + + + , + ); + expect(updateFilters).toHaveBeenLastCalledWith({ + owners: undefined, + }); + }); }); diff --git a/plugins/catalog-react/src/components/EntityOwnerPicker/EntityOwnerPicker.tsx b/plugins/catalog-react/src/components/EntityOwnerPicker/EntityOwnerPicker.tsx index 0a4a79857e..b067bda0f5 100644 --- a/plugins/catalog-react/src/components/EntityOwnerPicker/EntityOwnerPicker.tsx +++ b/plugins/catalog-react/src/components/EntityOwnerPicker/EntityOwnerPicker.tsx @@ -75,14 +75,6 @@ export const EntityOwnerPicker = () => { } }, [queryParamOwners]); - useEffect(() => { - updateFilters({ - owners: selectedOwners.length - ? new EntityOwnerFilter(selectedOwners) - : undefined, - }); - }, [selectedOwners, updateFilters]); - const availableOwners = useMemo( () => [ @@ -99,6 +91,15 @@ export const EntityOwnerPicker = () => { [backendEntities], ); + useEffect(() => { + updateFilters({ + owners: + selectedOwners.length && availableOwners.length + ? new EntityOwnerFilter(selectedOwners) + : undefined, + }); + }, [selectedOwners, updateFilters, availableOwners]); + if (!availableOwners.length) return null; return (