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'> = {
|
const time_grain_sqla: SharedControlConfig<'SelectControl'> = {
|
||||||
type: 'SelectControl',
|
type: 'SelectControl',
|
||||||
label: TIME_FILTER_LABELS.time_grain_sqla,
|
label: TIME_FILTER_LABELS.time_grain_sqla,
|
||||||
|
placeholder: t('None'),
|
||||||
initialValue: (control: ControlState, state: ControlPanelState) => {
|
initialValue: (control: ControlState, state: ControlPanelState) => {
|
||||||
if (!isDefined(state)) {
|
if (!isDefined(state)) {
|
||||||
// If a chart is in a Dashboard, the ControlPanelState is empty.
|
// If a chart is in a Dashboard, the ControlPanelState is empty.
|
||||||
return control.value;
|
return control.value;
|
||||||
}
|
}
|
||||||
// If a chart is a new one that isn't saved, the 'time_grain_sqla' isn't in the form_data.
|
// If a chart is a new one that isn't saved, metadata is null. In this
|
||||||
return 'time_grain_sqla' in (state?.form_data ?? {})
|
// case we want to default P1D. If the chart has been saved, we want
|
||||||
? state.form_data?.time_grain_sqla
|
// 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';
|
: 'P1D';
|
||||||
},
|
},
|
||||||
description: t(
|
description: t(
|
||||||
|
@ -264,6 +267,7 @@ const limit: SharedControlConfig<'SelectControl'> = {
|
||||||
type: 'SelectControl',
|
type: 'SelectControl',
|
||||||
freeForm: true,
|
freeForm: true,
|
||||||
label: t('Series limit'),
|
label: t('Series limit'),
|
||||||
|
placeholder: t('None'),
|
||||||
validators: [legacyValidateInteger],
|
validators: [legacyValidateInteger],
|
||||||
choices: formatSelectOptions(SERIES_LIMITS),
|
choices: formatSelectOptions(SERIES_LIMITS),
|
||||||
clearable: true,
|
clearable: true,
|
||||||
|
@ -279,6 +283,7 @@ const series_limit: SharedControlConfig<'SelectControl'> = {
|
||||||
type: 'SelectControl',
|
type: 'SelectControl',
|
||||||
freeForm: true,
|
freeForm: true,
|
||||||
label: t('Series limit'),
|
label: t('Series limit'),
|
||||||
|
placeholder: t('None'),
|
||||||
validators: [legacyValidateInteger],
|
validators: [legacyValidateInteger],
|
||||||
choices: formatSelectOptions(SERIES_LIMITS),
|
choices: formatSelectOptions(SERIES_LIMITS),
|
||||||
description: t(
|
description: t(
|
||||||
|
|
|
@ -88,6 +88,7 @@ export interface ControlPanelState {
|
||||||
datasource: Dataset | QueryResponse | null;
|
datasource: Dataset | QueryResponse | null;
|
||||||
controls: ControlStateMapping;
|
controls: ControlStateMapping;
|
||||||
common: JsonObject;
|
common: JsonObject;
|
||||||
|
metadata?: JsonObject | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -97,7 +97,6 @@ class TimeGrain(NamedTuple):
|
||||||
|
|
||||||
|
|
||||||
builtin_time_grains: Dict[Optional[str], str] = {
|
builtin_time_grains: Dict[Optional[str], str] = {
|
||||||
None: __("Original value"),
|
|
||||||
"PT1S": __("Second"),
|
"PT1S": __("Second"),
|
||||||
"PT5S": __("5 second"),
|
"PT5S": __("5 second"),
|
||||||
"PT30S": __("30 second"),
|
"PT30S": __("30 second"),
|
||||||
|
|
Loading…
Reference in New Issue