Merge pull request #15058 from wayfair-contribs/smedeiros_filters
Fix owner and lifecycle picker
This commit is contained in:
+19
@@ -169,6 +169,7 @@ describe('<EntityLifecyclePicker/>', () => {
|
||||
value={{
|
||||
updateFilters,
|
||||
queryParameters: { lifecycles: ['experimental'] },
|
||||
backendEntities: sampleEntities,
|
||||
}}
|
||||
>
|
||||
<EntityLifecyclePicker />
|
||||
@@ -182,6 +183,7 @@ describe('<EntityLifecyclePicker/>', () => {
|
||||
value={{
|
||||
updateFilters,
|
||||
queryParameters: { lifecycles: ['production'] },
|
||||
backendEntities: sampleEntities,
|
||||
}}
|
||||
>
|
||||
<EntityLifecyclePicker />
|
||||
@@ -191,4 +193,21 @@ describe('<EntityLifecyclePicker/>', () => {
|
||||
lifecycles: new EntityLifecycleFilter(['production']),
|
||||
});
|
||||
});
|
||||
it('removes lifecycles from filters if there are no available lifecycles', () => {
|
||||
const updateFilters = jest.fn();
|
||||
render(
|
||||
<MockEntityListContextProvider
|
||||
value={{
|
||||
updateFilters,
|
||||
queryParameters: { lifecycles: ['experimental'] },
|
||||
backendEntities: [],
|
||||
}}
|
||||
>
|
||||
<EntityLifecyclePicker />
|
||||
</MockEntityListContextProvider>,
|
||||
);
|
||||
expect(updateFilters).toHaveBeenLastCalledWith({
|
||||
lifecycles: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+9
-8
@@ -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 (
|
||||
|
||||
@@ -183,6 +183,7 @@ describe('<EntityOwnerPicker/>', () => {
|
||||
value={{
|
||||
updateFilters,
|
||||
queryParameters: { owners: ['team-a'] },
|
||||
backendEntities: sampleEntities,
|
||||
}}
|
||||
>
|
||||
<EntityOwnerPicker />
|
||||
@@ -196,6 +197,7 @@ describe('<EntityOwnerPicker/>', () => {
|
||||
value={{
|
||||
updateFilters,
|
||||
queryParameters: { owners: ['team-b'] },
|
||||
backendEntities: sampleEntities,
|
||||
}}
|
||||
>
|
||||
<EntityOwnerPicker />
|
||||
@@ -205,4 +207,21 @@ describe('<EntityOwnerPicker/>', () => {
|
||||
owners: new EntityOwnerFilter(['team-b']),
|
||||
});
|
||||
});
|
||||
it('removes owners from filters if there are none available', () => {
|
||||
const updateFilters = jest.fn();
|
||||
render(
|
||||
<MockEntityListContextProvider
|
||||
value={{
|
||||
updateFilters,
|
||||
queryParameters: { owners: ['team-a'] },
|
||||
backendEntities: [],
|
||||
}}
|
||||
>
|
||||
<EntityOwnerPicker />
|
||||
</MockEntityListContextProvider>,
|
||||
);
|
||||
expect(updateFilters).toHaveBeenLastCalledWith({
|
||||
owners: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user