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

[23543] Multi words zones now work while searching for timezones. #25569

Merged
merged 8 commits into from
Aug 29, 2023
8 changes: 7 additions & 1 deletion src/pages/settings/Profile/TimezoneSelectPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ function TimezoneSelectPage(props) {
*/
const filterShownTimezones = (searchText) => {
setTimezoneInputText(searchText);
setTimezoneOptions(_.filter(allTimezones.current, (tz) => tz.text.toLowerCase().includes(searchText.trim().toLowerCase())));
setTimezoneOptions(_.filter(allTimezones.current, (tz) => {
let shouldShow = true;
searchText.toLowerCase().replace(/[^a-z0-9]/g, ' ').split(' ').forEach((word) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can sanitize the searchText before checking :

const searchWords = searchText.toLowerCase().replace(/[^a-z0-9\+\-\s+/]/g, '').split(/\s+/);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we keep the current regex, this won't be needed, otherwise, I'll update as suggested.

if (tz.text.toLowerCase().replace(/[^a-z0-9]/g, ' ').indexOf(word) < 0) shouldShow = false;
})
return shouldShow;
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a lint here.

Can't we use Array.prototype.every() instead of .forEach, I think this will simplify the code and make it more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Run npm run prettier, fixed several lint issues & used Array.prototype.every() instead of .forEach.

}));
};

return (
Expand Down