Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(explore): support saving undefined time grain #22565

Merged
merged 3 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting rid of this option.

"PT1S": __("Second"),
"PT5S": __("5 second"),
"PT30S": __("30 second"),
Expand Down