LuisSanchez commented on code in PR #36486:
URL: https://github.com/apache/superset/pull/36486#discussion_r2665619818
##########
superset-frontend/packages/superset-ui-core/src/components/TimezoneSelector/index.tsx:
##########
@@ -45,118 +60,142 @@ const offsetsToName = {
'060': ['GMT Standard Time - London', 'British Summer Time'],
};
-export type TimezoneSelectorProps = {
- onTimezoneChange: (value: string) => void;
- timezone?: string | null;
- minWidth?: string;
-};
+function getOffsetKey(timezoneName: string): string {
+ return (
+ JANUARY_REF.tz(timezoneName).utcOffset().toString() +
+ JULY_REF.tz(timezoneName).utcOffset().toString()
+ );
+}
+
+const timezoneCache = new TimezoneOptionsCache(getOffsetKey, offsetsToName);
+
+// Export function to check if options are cached (for parent components)
+export function areTimezoneOptionsCached(): boolean {
+ return timezoneCache.isCached();
+}
+
+function getTimezoneOptionsAsync(): Promise<TimezoneOption[]> {
+ return timezoneCache.getOptionsAsync();
+}
Review Comment:
There is already a singleton instance:
`const timezoneCache = new TimezoneOptionsCache(getOffsetKey,
offsetsToName);`
on
`superset-frontend/packages/superset-ui-core/src/components/TimezoneSelector/index.tsx::70`
If I'm not mistaken, exporting the class would require consumers to create
instances, which I think isn't needed.
Also there's a problem: `TimezoneOptionsCache` requires `getOffsetKey` and
`offsetsToName` as constructor parameters, which are defined in
**`index.tsx`**, and we cannot be used on **`AlertReportModal.tsx`**.
Maybe what we can do is:
- Move singleton creation to `TimezoneOptionsCache.tsx`.
- Move `getOffsetKey`, `offsetsToName`, and related constants to
`TimezoneOptionsCache.tsx`.
- Create and export the `singleton` there.
- Import it in `index.tsx`.
I think it will solve keep the cache and its dependencies together, makes
the singleton the single source of truth and simplifies the API by just
importing the singleton.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]