This is an automated email from the ASF dual-hosted git repository.
diegopucci pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 7383e4348b fix(timezoneselector): Correct the order to match names
first (#31941)
7383e4348b is described below
commit 7383e4348b1800b033b8f828a4af4c24286bf455
Author: Mehmet Salih Yavuz <[email protected]>
AuthorDate: Wed Jan 22 15:04:20 2025 +0300
fix(timezoneselector): Correct the order to match names first (#31941)
---
.../TimezoneSelector/TimezoneSelector.test.tsx | 5 ++---
.../src/components/TimezoneSelector/index.tsx | 21 +++++++++++++++++----
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git
a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx
b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx
index 0f9309b5a8..311c7e56d0 100644
---
a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx
+++
b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx
@@ -124,13 +124,12 @@ test('can update props and rerender with different
values', async () => {
timezone="Asia/Dubai"
/>,
);
- expect(screen.getByTitle('GMT +04:00 (Asia/Baku)')).toBeInTheDocument();
+ expect(screen.getByTitle('GMT +04:00 (Asia/Dubai)')).toBeInTheDocument();
rerender(
<TimezoneSelector
onTimezoneChange={onTimezoneChange}
timezone="Australia/Perth"
/>,
);
- expect(screen.getByTitle('GMT +08:00 (Asia/Brunei)')).toBeInTheDocument();
- expect(onTimezoneChange).toHaveBeenCalledTimes(2);
+ expect(screen.getByTitle('GMT +08:00
(Australia/Perth)')).toBeInTheDocument();
});
diff --git a/superset-frontend/src/components/TimezoneSelector/index.tsx
b/superset-frontend/src/components/TimezoneSelector/index.tsx
index 0584655b85..329ad34618 100644
--- a/superset-frontend/src/components/TimezoneSelector/index.tsx
+++ b/superset-frontend/src/components/TimezoneSelector/index.tsx
@@ -112,10 +112,23 @@ export default function TimezoneSelector({
// pre-sort timezone options by time offset
TIMEZONE_OPTIONS.sort(TIMEZONE_OPTIONS_SORT_COMPARATOR);
- const matchTimezoneToOptions = (timezone: string) =>
- TIMEZONE_OPTIONS.find(
- option => option.offsets === getOffsetKey(timezone),
- )?.value || DEFAULT_TIMEZONE.value;
+ const matchTimezoneToOptions = (timezone: string) => {
+ const offsetKey = getOffsetKey(timezone);
+ let fallbackValue: string | undefined;
+
+ for (const option of TIMEZONE_OPTIONS) {
+ if (
+ option.offsets === offsetKey &&
+ option.timezoneName === timezone
+ ) {
+ return option.value;
+ }
+ if (!fallbackValue && option.offsets === offsetKey) {
+ fallbackValue = option.value;
+ }
+ }
+ return fallbackValue || DEFAULT_TIMEZONE.value;
+ };
const validTimezone = matchTimezoneToOptions(
timezone || extendedDayjs.tz.guess(),