Skip to content

Commit 855e32d

Browse files
committed
Wizard: extract normalizeTimezoneString for timezone filtering
Extract repeated normalization logic into a reusable function and simplify the useMemo filtering code.
1 parent 105ae46 commit 855e32d

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/Components/CreateImageWizard/steps/Timezone/components/TimezoneDropDown.tsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,17 @@ const TimezoneDropDown = () => {
5656
}
5757
};
5858

59+
const normalizeTimezoneString = (value: string): string =>
60+
value.toLowerCase().replace(/[_/]/g, ' ').replace(/\s+/g, ' ').trim();
61+
5962
const sortedTimezones = useMemo(() => {
60-
let filtered = timezones;
61-
62-
if (searchValue) {
63-
const normalizedFilter = searchValue
64-
.toLowerCase()
65-
.replace(/[_/]/g, ' ')
66-
.replace(/\s+/g, ' ')
67-
.trim();
68-
69-
filtered = timezones.filter((tz) => {
70-
const normalizedTimezone = tz
71-
.toLowerCase()
72-
.replace(/[_/]/g, ' ')
73-
.replace(/\s+/g, ' ');
74-
return normalizedTimezone.includes(normalizedFilter);
75-
});
76-
}
63+
const normalizedFilter = normalizeTimezoneString(searchValue);
64+
65+
const filtered = normalizedFilter
66+
? timezones.filter((tz) =>
67+
normalizeTimezoneString(tz).includes(normalizedFilter),
68+
)
69+
: timezones;
7770

7871
return [...filtered].sort((a, b) => {
7972
if (a === DEFAULT_TIMEZONE) return -1;

0 commit comments

Comments
 (0)