villebro commented on code in PR #21644:
URL: https://github.com/apache/superset/pull/21644#discussion_r984531451


##########
superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx:
##########
@@ -183,7 +184,16 @@ const granularity: SharedControlConfig<'SelectControl'> = {
 const time_grain_sqla: SharedControlConfig<'SelectControl'> = {
   type: 'SelectControl',
   label: TIME_FILTER_LABELS.time_grain_sqla,
-  default: 'P1D',
+  initialValue: (control: ControlState, state: ControlPanelState) => {
+    if (!isDefined(state)) {
+      // If a chart is in a Dashboard, the ControlPanelState is empty.
+      return control.value;
+    }
+    // If a chart is a new one that isn't saved, the 'time_grain_sqla' isn't 
in the form_data.
+    return 'time_grain_sqla' in (state?.form_data ?? {})
+      ? state.form_data?.time_grain_sqla
+      : 'P1D';

Review Comment:
   Is there some reason we're not just doing `state.form_data?.time_grain_sqla 
|| 'P1D'` here?



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

Reply via email to