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
16 changes: 15 additions & 1 deletion src/pages/settings/Profile/TimezoneSelectPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,21 @@ 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) =>
_.every(
searchText
.toLowerCase()
.replace(/[^a-z0-9]/g, ' ')
.split(' '),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
searchText
.toLowerCase()
.replace(/[^a-z0-9]/g, ' ')
.split(' '),
searchText.toLowerCase().match(/[a-z0-9]+/g) || []

This can be simplified, Can we move to a local const to avoid repeating the same normalization process multiple times within the filter loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yees, of course! Hope I got it right.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, It is still included in the filter loop, and should be moved outside the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦 Sorry about that... Should be ok now

(word) =>
tz.text
.toLowerCase()
.replace(/[^a-z0-9]/g, ' ')
.indexOf(word) > -1,
),
),
);
};

return (
Expand Down
Loading