-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ const CoursesFilterMenu = ({ | |
menuItems, | ||
onItemMenuSelected, | ||
defaultItemSelectedText, | ||
menuType, | ||
}) => { | ||
const [itemMenuSelected, setItemMenuSelected] = useState(defaultItemSelectedText); | ||
const { cleanFilters } = useSelector(getStudioHomeCoursesParams); | ||
|
@@ -26,6 +27,13 @@ const CoursesFilterMenu = ({ | |
if (cleanFilters) { | ||
setItemMenuSelected(defaultItemSelectedText); | ||
} | ||
if (menuType !== 'courseTypes') { | ||
return; | ||
} | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( | ||
|
@@ -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)} | ||
|
@@ -57,6 +65,7 @@ const CoursesFilterMenu = ({ | |
CoursesFilterMenu.defaultProps = { | ||
defaultItemSelectedText: '', | ||
menuItems: [], | ||
menuType: '', | ||
}; | ||
|
||
CoursesFilterMenu.propTypes = { | ||
|
@@ -70,6 +79,7 @@ CoursesFilterMenu.propTypes = { | |
value: PropTypes.string.isRequired, | ||
}), | ||
), | ||
menuType: PropTypes.string, | ||
}; | ||
|
||
export default CoursesFilterMenu; |
There was a problem hiding this comment.
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:There was a problem hiding this comment.
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.