You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2023/01/03 08:53:50 UTC
[superset] branch master updated: fix(explore): support saving undefined time grain (#22565)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new a7a4561550 fix(explore): support saving undefined time grain (#22565)
a7a4561550 is described below
commit a7a4561550e06bad11ef6d5a50af1ae1af173790
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Tue Jan 3 08:53:42 2023 +0000
fix(explore): support saving undefined time grain (#22565)
---
.../src/shared-controls/sharedControls.tsx | 11 ++++++++---
.../packages/superset-ui-chart-controls/src/types.ts | 1 +
superset/db_engine_specs/base.py | 1 -
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx
index 11c4a48490..45ca968c7e 100644
--- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx
+++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx
@@ -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(
diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts
index 60cda2ede8..8df72011c4 100644
--- a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts
+++ b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts
@@ -88,6 +88,7 @@ export interface ControlPanelState {
datasource: Dataset | QueryResponse | null;
controls: ControlStateMapping;
common: JsonObject;
+ metadata?: JsonObject | null;
}
/**
diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py
index 0f124de34a..921b82bc30 100644
--- a/superset/db_engine_specs/base.py
+++ b/superset/db_engine_specs/base.py
@@ -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"),