-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
fix: update values for default timezone selector #17124
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,12 +17,16 @@ | |||||
* under the License. | ||||||
*/ | ||||||
|
||||||
import React, { useEffect, useRef } from 'react'; | ||||||
import React, { useEffect, useRef, useCallback } from 'react'; | ||||||
import moment from 'moment-timezone'; | ||||||
import { t } from '@superset-ui/core'; | ||||||
import { Select } from 'src/components'; | ||||||
|
||||||
const DEFAULT_TIMEZONE = 'GMT Standard Time'; | ||||||
const DEFAULT_TIMEZONE = { | ||||||
name: 'GMT Standard Time', | ||||||
value: 'Africa/Abidjan', | ||||||
}; | ||||||
|
||||||
const MIN_SELECT_WIDTH = '400px'; | ||||||
|
||||||
const offsetsToName = { | ||||||
|
@@ -37,7 +41,7 @@ const offsetsToName = { | |||||
'-540-480': ['Alaska Standard Time', 'Alaska Daylight Time'], | ||||||
'-600-600': ['Hawaii Standard Time', 'Hawaii Daylight Time'], | ||||||
'60120': ['Central European Time', 'Central European Daylight Time'], | ||||||
'00': [DEFAULT_TIMEZONE, DEFAULT_TIMEZONE], | ||||||
'00': [DEFAULT_TIMEZONE.name, DEFAULT_TIMEZONE.name], | ||||||
'060': ['GMT Standard Time - London', 'British Summer Time'], | ||||||
}; | ||||||
|
||||||
|
@@ -96,28 +100,31 @@ const TimezoneSelector = ({ onTimezoneChange, timezone }: TimezoneProps) => { | |||||
const prevTimezone = useRef(timezone); | ||||||
const matchTimezoneToOptions = (timezone: string) => | ||||||
TIMEZONE_OPTIONS.find(option => option.offsets === getOffsetKey(timezone)) | ||||||
?.value || DEFAULT_TIMEZONE; | ||||||
?.value || DEFAULT_TIMEZONE.value; | ||||||
|
||||||
const updateTimezone = (tz: string) => { | ||||||
// update the ref to track changes | ||||||
prevTimezone.current = tz; | ||||||
// the parent component contains the state for the value | ||||||
onTimezoneChange(tz); | ||||||
}; | ||||||
const updateTimezone = useCallback( | ||||||
(tz: string) => { | ||||||
// update the ref to track changes | ||||||
prevTimezone.current = tz; | ||||||
// the parent component contains the state for the value | ||||||
onTimezoneChange(tz); | ||||||
}, | ||||||
[onTimezoneChange], | ||||||
); | ||||||
|
||||||
useEffect(() => { | ||||||
const updatedTz = matchTimezoneToOptions(timezone || moment.tz.guess()); | ||||||
if (prevTimezone.current !== updatedTz) { | ||||||
updateTimezone(updatedTz); | ||||||
} | ||||||
}, [timezone]); | ||||||
}, [timezone, updateTimezone]); | ||||||
|
||||||
return ( | ||||||
<Select | ||||||
ariaLabel={t('Timezone')} | ||||||
ariaLabel={t('Timezone Selector')} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super nit. I think we agreed that the convention should be Timezone selector
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you for pointing that out. 👍 |
||||||
css={{ minWidth: MIN_SELECT_WIDTH }} // smallest size for current values | ||||||
onChange={onTimezoneChange} | ||||||
value={timezone || DEFAULT_TIMEZONE} | ||||||
value={timezone || DEFAULT_TIMEZONE.value} | ||||||
options={TIMEZONE_OPTIONS} | ||||||
/> | ||||||
); | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
GMT
here instead? It's an official IANA time zone identifier.If not, it might be good to say here that the
Africa/Abidjan
timezone has no daylight saving, so it will be identical to GMT all year long.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, the reason that this value is used is because when we dedupe the time zone list, we choose the first value, which happens to be this one. The user never sees the value, just the label, and it has the same exact time zone match as GMT (no daylight savings time). Do you think this might pose a problem somewhere? Many of the other time zones do the same thing. PT for example is actually Vancouver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. I think it's fine. Maybe leave a comment saying that timezones are deduped by the first alphabetical value?