You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/06/15 09:06:34 UTC

[GitHub] [superset] MatanBobi commented on a change in pull request #15147: refactor(explore): remove side effect in render from CalendarFrame for DatePicker

MatanBobi commented on a change in pull request #15147:
URL: https://github.com/apache/superset/pull/15147#discussion_r651598039



##########
File path: superset-frontend/src/explore/components/controls/DateFilterControl/components/CalendarFrame.tsx
##########
@@ -29,12 +29,15 @@ import {
   FrameComponentProps,
 } from '../types';
 
-export function CalendarFrame(props: FrameComponentProps) {
-  let calendarRange = PreviousCalendarWeek;
-  if (CALENDAR_RANGE_SET.has(props.value as CalendarRangeType)) {
-    calendarRange = props.value;
-  } else {
-    props.onChange(calendarRange);
+export function CalendarFrame({ onChange, value }: FrameComponentProps) {
+  useEffect(() => {
+    if (!CALENDAR_RANGE_SET.has(value as CalendarRangeType)) {
+      onChange(PreviousCalendarWeek);
+    }
+  }, [onChange, value]);
+
+  if (!CALENDAR_RANGE_SET.has(value as CalendarRangeType)) {
+    return null;

Review comment:
       The whole purpose of this PR is to change the "default value" approach because it was broken.
   What I'm doing here is if the initial value isn't one of the calendar range options, I'm returning `null` so in the next render I'll get the correct value.




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org