Skip to content

Commit

Permalink
fix(explore): support saving undefined time grain (#22565)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Jan 3, 2023
1 parent 38d02a1 commit a7a4561
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,17 @@ const granularity: SharedControlConfig<'SelectControl'> = {
const time_grain_sqla: SharedControlConfig<'SelectControl'> = {
type: 'SelectControl',
label: TIME_FILTER_LABELS.time_grain_sqla,
placeholder: t('None'),
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
// If a chart is a new one that isn't saved, metadata is null. In this
// case we want to default P1D. If the chart has been saved, we want
// to use whichever value was chosen, either nothing or valid a time grain.
return state?.metadata || 'time_grain_sqla' in (state?.form_data ?? {})
? state?.form_data?.time_grain_sqla
: 'P1D';
},
description: t(
Expand Down Expand Up @@ -264,6 +267,7 @@ const limit: SharedControlConfig<'SelectControl'> = {
type: 'SelectControl',
freeForm: true,
label: t('Series limit'),
placeholder: t('None'),
validators: [legacyValidateInteger],
choices: formatSelectOptions(SERIES_LIMITS),
clearable: true,
Expand All @@ -279,6 +283,7 @@ const series_limit: SharedControlConfig<'SelectControl'> = {
type: 'SelectControl',
freeForm: true,
label: t('Series limit'),
placeholder: t('None'),
validators: [legacyValidateInteger],
choices: formatSelectOptions(SERIES_LIMITS),
description: t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface ControlPanelState {
datasource: Dataset | QueryResponse | null;
controls: ControlStateMapping;
common: JsonObject;
metadata?: JsonObject | null;
}

/**
Expand Down
1 change: 0 additions & 1 deletion superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class TimeGrain(NamedTuple):


builtin_time_grains: Dict[Optional[str], str] = {
None: __("Original value"),
"PT1S": __("Second"),
"PT5S": __("5 second"),
"PT30S": __("30 second"),
Expand Down

0 comments on commit a7a4561

Please sign in to comment.