From 672a3dd102a5b014bb20906b79d3b6889cc6a966 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Thu, 8 Jul 2021 16:38:39 +0300 Subject: [PATCH] [Cases] Fix recent cases filter (#104826) (#104846) --- .../components/recent_cases/filters/index.tsx | 1 + .../components/recent_cases/index.test.tsx | 17 +++++++++++++++++ .../public/components/recent_cases/index.tsx | 2 +- .../components/recent_cases/recent_cases.tsx | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/cases/public/components/recent_cases/filters/index.tsx b/x-pack/plugins/cases/public/components/recent_cases/filters/index.tsx index cc37a826e18b9..b42ed968e78c5 100644 --- a/x-pack/plugins/cases/public/components/recent_cases/filters/index.tsx +++ b/x-pack/plugins/cases/public/components/recent_cases/filters/index.tsx @@ -39,6 +39,7 @@ export const RecentCasesFilters = React.memo<{ : toggleButtonIcons.filter((x) => x.id !== MY_RECENTLY_REPORTED_ID), [showMyRecentlyReported] ); + const onChange = useCallback( (filterMode: string) => { setFilterBy(filterMode as FilterMode); diff --git a/x-pack/plugins/cases/public/components/recent_cases/index.test.tsx b/x-pack/plugins/cases/public/components/recent_cases/index.test.tsx index 77413f72fbfb1..f3094a8b80307 100644 --- a/x-pack/plugins/cases/public/components/recent_cases/index.test.tsx +++ b/x-pack/plugins/cases/public/components/recent_cases/index.test.tsx @@ -101,4 +101,21 @@ describe('RecentCases', () => { userEvent.click(element); expect(setFilters).toHaveBeenCalled(); }); + + it('it resets the reporters when changing from my recently reported cases to recent cases', () => { + const { getByTestId } = render( + + + + ); + + const myRecentCasesElement = getByTestId('myRecentlyReported'); + const recentCasesElement = getByTestId('recentlyCreated'); + userEvent.click(myRecentCasesElement); + userEvent.click(recentCasesElement); + + const mockCalls = setFilters.mock.calls; + expect(mockCalls[0][0].reporters.length).toBeGreaterThan(0); + expect(mockCalls[1][0]).toEqual({ reporters: [] }); + }); }); diff --git a/x-pack/plugins/cases/public/components/recent_cases/index.tsx b/x-pack/plugins/cases/public/components/recent_cases/index.tsx index 056d402619ece..607583ff8cf8a 100644 --- a/x-pack/plugins/cases/public/components/recent_cases/index.tsx +++ b/x-pack/plugins/cases/public/components/recent_cases/index.tsx @@ -49,7 +49,7 @@ const RecentCasesComponent = ({ }, ], } - : {}, + : { reporters: [] }, [currentUser, recentCasesFilterBy] ); diff --git a/x-pack/plugins/cases/public/components/recent_cases/recent_cases.tsx b/x-pack/plugins/cases/public/components/recent_cases/recent_cases.tsx index e08c629913258..961353206ccfa 100644 --- a/x-pack/plugins/cases/public/components/recent_cases/recent_cases.tsx +++ b/x-pack/plugins/cases/public/components/recent_cases/recent_cases.tsx @@ -42,6 +42,7 @@ const usePrevious = (value: Partial) => { }); return ref.current; }; + export const RecentCasesComp = ({ caseDetailsNavigation, createCaseNavigation,