From 2657fa233bb9a1f579ada8b8e2862e514193a5de Mon Sep 17 00:00:00 2001 From: Danut Gavrus Date: Mon, 21 Aug 2023 12:50:39 +0300 Subject: [PATCH 1/6] [23543] Multi words zone now work while searching for timezones. --- src/pages/settings/Profile/TimezoneSelectPage.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/settings/Profile/TimezoneSelectPage.js b/src/pages/settings/Profile/TimezoneSelectPage.js index 1bed325c435a..204d9d3242f4 100644 --- a/src/pages/settings/Profile/TimezoneSelectPage.js +++ b/src/pages/settings/Profile/TimezoneSelectPage.js @@ -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) => { + if (tz.text.toLowerCase().replace(/[^a-z0-9]/g, ' ').indexOf(word) < 0) shouldShow = false; + }) + return shouldShow; + })); }; return ( From 757b43c6e4f2a0fd40f6dac74bad63d621610a5d Mon Sep 17 00:00:00 2001 From: Danut Gavrus Date: Tue, 22 Aug 2023 14:32:22 +0300 Subject: [PATCH 2/6] fix lint error --- .../settings/Profile/TimezoneSelectPage.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/pages/settings/Profile/TimezoneSelectPage.js b/src/pages/settings/Profile/TimezoneSelectPage.js index 92a9cf349fd6..099b662cb857 100644 --- a/src/pages/settings/Profile/TimezoneSelectPage.js +++ b/src/pages/settings/Profile/TimezoneSelectPage.js @@ -62,13 +62,25 @@ function TimezoneSelectPage(props) { */ const filterShownTimezones = (searchText) => { setTimezoneInputText(searchText); - setTimezoneOptions(_.filter(allTimezones.current, (tz) => { - let shouldShow = true; - searchText.toLowerCase().replace(/[^a-z0-9]/g, ' ').split(' ').forEach((word) => { - if (tz.text.toLowerCase().replace(/[^a-z0-9]/g, ' ').indexOf(word) < 0) shouldShow = false; - }) - return shouldShow; - })); + setTimezoneOptions( + _.filter(allTimezones.current, (tz) => { + let shouldShow = true; + searchText + .toLowerCase() + .replace(/[^a-z0-9]/g, ' ') + .split(' ') + .forEach((word) => { + if ( + tz.text + .toLowerCase() + .replace(/[^a-z0-9]/g, ' ') + .indexOf(word) < 0 + ) + shouldShow = false; + }); + return shouldShow; + }), + ); }; return ( From da64640015bef071116259b8fd83af9d0bcb40f3 Mon Sep 17 00:00:00 2001 From: Danut Gavrus Date: Tue, 22 Aug 2023 14:52:43 +0300 Subject: [PATCH 3/6] Replaced forEach with every. --- .../settings/Profile/TimezoneSelectPage.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/pages/settings/Profile/TimezoneSelectPage.js b/src/pages/settings/Profile/TimezoneSelectPage.js index 099b662cb857..6916d180f087 100644 --- a/src/pages/settings/Profile/TimezoneSelectPage.js +++ b/src/pages/settings/Profile/TimezoneSelectPage.js @@ -63,23 +63,20 @@ function TimezoneSelectPage(props) { const filterShownTimezones = (searchText) => { setTimezoneInputText(searchText); setTimezoneOptions( - _.filter(allTimezones.current, (tz) => { - let shouldShow = true; + _.filter(allTimezones.current, (tz) => searchText .toLowerCase() .replace(/[^a-z0-9]/g, ' ') .split(' ') - .forEach((word) => { - if ( + .filter((word) => word) + .every( + (word) => tz.text .toLowerCase() .replace(/[^a-z0-9]/g, ' ') - .indexOf(word) < 0 - ) - shouldShow = false; - }); - return shouldShow; - }), + .indexOf(word) > -1, + ), + ), ); }; From 6d85f2affe51a2cdc9b86da603ba455b448c4789 Mon Sep 17 00:00:00 2001 From: Danut Gavrus Date: Tue, 22 Aug 2023 15:08:54 +0300 Subject: [PATCH 4/6] Fixed prefer _.every() instead of native method. --- .../settings/Profile/TimezoneSelectPage.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pages/settings/Profile/TimezoneSelectPage.js b/src/pages/settings/Profile/TimezoneSelectPage.js index 6916d180f087..308a1e57bf23 100644 --- a/src/pages/settings/Profile/TimezoneSelectPage.js +++ b/src/pages/settings/Profile/TimezoneSelectPage.js @@ -64,18 +64,17 @@ function TimezoneSelectPage(props) { setTimezoneInputText(searchText); setTimezoneOptions( _.filter(allTimezones.current, (tz) => - searchText - .toLowerCase() - .replace(/[^a-z0-9]/g, ' ') - .split(' ') - .filter((word) => word) - .every( - (word) => - tz.text - .toLowerCase() - .replace(/[^a-z0-9]/g, ' ') - .indexOf(word) > -1, - ), + _.every( + searchText + .toLowerCase() + .replace(/[^a-z0-9]/g, ' ') + .split(' '), + (word) => + tz.text + .toLowerCase() + .replace(/[^a-z0-9]/g, ' ') + .indexOf(word) > -1, + ), ), ); }; From 818877cfb955adae90d79cefc18dc268b6059432 Mon Sep 17 00:00:00 2001 From: Danut Gavrus Date: Thu, 24 Aug 2023 12:17:05 +0300 Subject: [PATCH 5/6] Improved filter loop. Merged main. Run prettier. --- src/pages/settings/Profile/TimezoneSelectPage.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pages/settings/Profile/TimezoneSelectPage.js b/src/pages/settings/Profile/TimezoneSelectPage.js index ddac26e2e7f7..b00f32b16d8b 100644 --- a/src/pages/settings/Profile/TimezoneSelectPage.js +++ b/src/pages/settings/Profile/TimezoneSelectPage.js @@ -63,19 +63,17 @@ function TimezoneSelectPage(props) { const filterShownTimezones = (searchText) => { setTimezoneInputText(searchText); setTimezoneOptions( - _.filter(allTimezones.current, (tz) => - _.every( - searchText - .toLowerCase() - .replace(/[^a-z0-9]/g, ' ') - .split(' '), + _.filter(allTimezones.current, (tz) => { + const searchWords = searchText.toLowerCase().match(/[a-z0-9]+/g) || []; + return _.every( + searchWords, (word) => tz.text .toLowerCase() .replace(/[^a-z0-9]/g, ' ') .indexOf(word) > -1, - ), - ), + ); + }), ); }; From e747c1c263aa318f279ba3486357a5f1ff442365 Mon Sep 17 00:00:00 2001 From: Danut Gavrus Date: Thu, 24 Aug 2023 12:36:27 +0300 Subject: [PATCH 6/6] Moved normalization process out of the filter loop. --- src/pages/settings/Profile/TimezoneSelectPage.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/settings/Profile/TimezoneSelectPage.js b/src/pages/settings/Profile/TimezoneSelectPage.js index b00f32b16d8b..b6fbc36e3ef7 100644 --- a/src/pages/settings/Profile/TimezoneSelectPage.js +++ b/src/pages/settings/Profile/TimezoneSelectPage.js @@ -62,18 +62,18 @@ function TimezoneSelectPage(props) { */ const filterShownTimezones = (searchText) => { setTimezoneInputText(searchText); + const searchWords = searchText.toLowerCase().match(/[a-z0-9]+/g) || []; setTimezoneOptions( - _.filter(allTimezones.current, (tz) => { - const searchWords = searchText.toLowerCase().match(/[a-z0-9]+/g) || []; - return _.every( + _.filter(allTimezones.current, (tz) => + _.every( searchWords, (word) => tz.text .toLowerCase() .replace(/[^a-z0-9]/g, ' ') .indexOf(word) > -1, - ); - }), + ), + ), ); };