Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BB-9101] Add missing default filter #65

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const CoursesFilterMenu = ({
menuItems,
onItemMenuSelected,
defaultItemSelectedText,
menuType,
}) => {
const [itemMenuSelected, setItemMenuSelected] = useState(defaultItemSelectedText);
const { cleanFilters } = useSelector(getStudioHomeCoursesParams);
Expand All @@ -26,6 +27,13 @@ const CoursesFilterMenu = ({
if (cleanFilters) {
setItemMenuSelected(defaultItemSelectedText);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkulkark Don't you just need to call the onItemMenuSelected here? Or even better:

Suggested change
setItemMenuSelected(defaultItemSelectedText);
const defaultItemSelectedValue = menuItems.find(item => item.name === defaultItemSelectedText);
handleCourseTypeSelected(defaultItemSelectedText, defaultItemSelectedValue);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cup0fCoffee I actually couldn't fully figure out how the cleanFilters option could be updated, so I didn't change the existing behaviour.

}
if (menuType !== 'courseTypes') {
return;
}
Comment on lines +30 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkulkark Why do we only make this behavior work for one type of the menu? Shouldn't default value work correctly for all menu types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cup0fCoffee It does, but since the same filter component is used for two different menus rendered one after another, the second one resets the first. And since we don't need to change the default behaviour of the second filter, I decided this option would be better. What do you think?

const defaultItem = menuItems.find(item => item.name === defaultItemSelectedText);
if (defaultItem) {
onItemMenuSelected(defaultItem.value);
}
}, [cleanFilters]);

return (
Expand All @@ -43,7 +51,7 @@ const CoursesFilterMenu = ({
{menuItems.map(({ id, name, value }) => (
<Dropdown.Item
key={id}
onClick={() => handleCourseTypeSelected(name, value)}
onSelect={() => handleCourseTypeSelected(name, value)}
data-testid={`item-menu-${id}`}
>
{name} {courseTypeSelectedIcon(name)}
Expand All @@ -57,6 +65,7 @@ const CoursesFilterMenu = ({
CoursesFilterMenu.defaultProps = {
defaultItemSelectedText: '',
menuItems: [],
menuType: '',
};

CoursesFilterMenu.propTypes = {
Expand All @@ -70,6 +79,7 @@ CoursesFilterMenu.propTypes = {
value: PropTypes.string.isRequired,
}),
),
menuType: PropTypes.string,
};

export default CoursesFilterMenu;
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const CoursesOrderFilterMenu = ({ onItemMenuSelected }) => {
menuItems={courseOrders}
onItemMenuSelected={handleCourseTypeSelected}
defaultItemSelectedText={intl.formatMessage(messages.coursesOrderFilterMenuAscendantCurses)}
menuType="courseOrders"
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const CoursesTypesFilterMenu = ({ onItemMenuSelected }) => {
menuItems={courseTypes}
onItemMenuSelected={handleCourseTypeSelected}
defaultItemSelectedText={intl.formatMessage(messages.coursesTypesFilterMenuActiveCurses)}
menuType="courseTypes"
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
Loading