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 2022/09/30 15:10:59 UTC
[GitHub] [superset] zhaoyongjie commented on a diff in pull request #21644: fix: time grain can't be removed in explore
zhaoyongjie commented on code in PR #21644:
URL: https://github.com/apache/superset/pull/21644#discussion_r984696114
##########
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:
When `Time Grain control` be set to "Original value" or just removal, the `time_grain_sqla` in the form_data will be `null`. If `time_grain_sqla` get a null value, the 'P1D' will always be set to control, in this case, the chart will never use an empty time grain value.
For instance:
1. make a Line Chart and set `Original value` to `Time Grain`, and then save it; next, go to chart list; then, reopen the chart.
2. if use `state.form_data?.time_grain_sqla || 'P1D'` the Time Grain will return `P1D`
--
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: notifications-unsubscribe@superset.apache.org
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