From 9ceb989675505e9216ccea11ff8b1a6fc406cc35 Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Fri, 6 Sep 2024 11:35:36 -0400 Subject: [PATCH 1/3] fix: set default filter and use onSelect for dropdown --- .../courses-filters/courses-filter-menu/index.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-filter-menu/index.jsx b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-filter-menu/index.jsx index 9843b65330..b1afafbdae 100644 --- a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-filter-menu/index.jsx +++ b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-filter-menu/index.jsx @@ -26,6 +26,10 @@ const CoursesFilterMenu = ({ if (cleanFilters) { setItemMenuSelected(defaultItemSelectedText); } + const defaultItem = menuItems.find(item => item.name === defaultItemSelectedText); + if (defaultItem) { + onItemMenuSelected(defaultItem.value); + } }, [cleanFilters]); return ( @@ -43,7 +47,7 @@ const CoursesFilterMenu = ({ {menuItems.map(({ id, name, value }) => ( handleCourseTypeSelected(name, value)} + onSelect={() => handleCourseTypeSelected(name, value)} data-testid={`item-menu-${id}`} > {name} {courseTypeSelectedIcon(name)} From 1a1c8c23e65321abead148bf8f0767ea564950bc Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Fri, 6 Sep 2024 14:58:08 -0400 Subject: [PATCH 2/3] fix: fix failing test case --- .../tabs-section/courses-tab/courses-filters/index.test.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/studio-home/tabs-section/courses-tab/courses-filters/index.test.jsx b/src/studio-home/tabs-section/courses-tab/courses-filters/index.test.jsx index 02d69e284a..45f4b0820d 100644 --- a/src/studio-home/tabs-section/courses-tab/courses-filters/index.test.jsx +++ b/src/studio-home/tabs-section/courses-tab/courses-filters/index.test.jsx @@ -137,6 +137,8 @@ describe('CoursesFilters', () => { it('should not call dispatch when the search input contains only spaces', async () => { renderComponent(); + expect(dispatchMock).toHaveBeenCalled(); + dispatchMock.mockClear(); const searchInput = screen.getByRole('searchbox'); fireEvent.change(searchInput, { target: { value: ' ' } }); await waitFor(() => expect(dispatchMock).not.toHaveBeenCalled(), { timeout: 500 }); From fa800c95ab4ec3204605d266027194fa62b6d048 Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Mon, 9 Sep 2024 10:34:36 -0400 Subject: [PATCH 3/3] fix: only set default for coursetypes filter --- .../courses-filters/courses-filter-menu/index.jsx | 6 ++++++ .../courses-filters/courses-order-filter-menu/index.jsx | 1 + .../courses-filters/courses-types-filter-menu/index.jsx | 1 + 3 files changed, 8 insertions(+) diff --git a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-filter-menu/index.jsx b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-filter-menu/index.jsx index b1afafbdae..edd969d662 100644 --- a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-filter-menu/index.jsx +++ b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-filter-menu/index.jsx @@ -10,6 +10,7 @@ const CoursesFilterMenu = ({ menuItems, onItemMenuSelected, defaultItemSelectedText, + menuType, }) => { const [itemMenuSelected, setItemMenuSelected] = useState(defaultItemSelectedText); const { cleanFilters } = useSelector(getStudioHomeCoursesParams); @@ -26,6 +27,9 @@ const CoursesFilterMenu = ({ if (cleanFilters) { setItemMenuSelected(defaultItemSelectedText); } + if (menuType !== 'courseTypes') { + return; + } const defaultItem = menuItems.find(item => item.name === defaultItemSelectedText); if (defaultItem) { onItemMenuSelected(defaultItem.value); @@ -61,6 +65,7 @@ const CoursesFilterMenu = ({ CoursesFilterMenu.defaultProps = { defaultItemSelectedText: '', menuItems: [], + menuType: '', }; CoursesFilterMenu.propTypes = { @@ -74,6 +79,7 @@ CoursesFilterMenu.propTypes = { value: PropTypes.string.isRequired, }), ), + menuType: PropTypes.string, }; export default CoursesFilterMenu; diff --git a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-order-filter-menu/index.jsx b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-order-filter-menu/index.jsx index 837d11dca9..3c02fa55c9 100644 --- a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-order-filter-menu/index.jsx +++ b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-order-filter-menu/index.jsx @@ -45,6 +45,7 @@ const CoursesOrderFilterMenu = ({ onItemMenuSelected }) => { menuItems={courseOrders} onItemMenuSelected={handleCourseTypeSelected} defaultItemSelectedText={intl.formatMessage(messages.coursesOrderFilterMenuAscendantCurses)} + menuType="courseOrders" /> ); }; diff --git a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.jsx b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.jsx index f668a577b4..f655d47a58 100644 --- a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.jsx +++ b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.jsx @@ -40,6 +40,7 @@ const CoursesTypesFilterMenu = ({ onItemMenuSelected }) => { menuItems={courseTypes} onItemMenuSelected={handleCourseTypeSelected} defaultItemSelectedText={intl.formatMessage(messages.coursesTypesFilterMenuActiveCurses)} + menuType="courseTypes" /> ); };