mirror of https://github.com/apache/superset.git
fix(explore): support saving undefined time grain (#22565)
This commit is contained in:
parent
38d02a10b5
commit
a7a4561550
|
@ -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(
|
||||
|
@ -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,
|
||||
|
@ -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(
|
||||
|
|
|
@ -88,6 +88,7 @@ export interface ControlPanelState {
|
|||
datasource: Dataset | QueryResponse | null;
|
||||
controls: ControlStateMapping;
|
||||
common: JsonObject;
|
||||
metadata?: JsonObject | null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in New Issue