LuisSanchez commented on code in PR #36486:
URL: https://github.com/apache/superset/pull/36486#discussion_r2665411080
##########
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:
#### TL;DR;
The `areTimezoneOptionsCached()` function makes sense because it's exported
and provides a public API. `getTimezoneOptionsAsync()` is internal-only and
doesn't need a wrapper.
#### areTimezoneOptionsCached()
Basically it provides a focused, stable API that matches the current needs.
If more functionality is needed later, more functions is better rather than
exposing the class. This keeps the API simple and maintainable.
With the function instead of the class we gain encapsulation, it hides the
`TimezoneOptionsCache` instance and its dependencies. Consumers don't need to
know about `getOffsetKey` or `offsetsToName`.
Also principle of least privilege, it exposes only what's needed (a boolean
check) with the current usage only needs `isCached()`.
`areTimezoneOptionsCached()` is straightforward, no need to understand the
class structure.
#### getTimezoneOptionsAsync
We can certainly remove it since it is used internally and is a pass-through.
--
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]