mirror of
https://github.com/apache/superset.git
synced 2024-09-06 13:57:40 -04:00
fix: time grain can't be removed in explore (#21644)
This commit is contained in:
parent
1d70079f71
commit
4c17f0e71e
@ -46,6 +46,7 @@ import {
|
|||||||
isAdhocColumn,
|
isAdhocColumn,
|
||||||
isPhysicalColumn,
|
isPhysicalColumn,
|
||||||
ensureIsArray,
|
ensureIsArray,
|
||||||
|
isDefined,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -183,7 +184,16 @@ 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,
|
||||||
default: 'P1D',
|
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
|
||||||
|
: 'P1D';
|
||||||
|
},
|
||||||
description: t(
|
description: t(
|
||||||
'The time granularity for the visualization. This ' +
|
'The time granularity for the visualization. This ' +
|
||||||
'applies a date transformation to alter ' +
|
'applies a date transformation to alter ' +
|
||||||
@ -192,7 +202,7 @@ const time_grain_sqla: SharedControlConfig<'SelectControl'> = {
|
|||||||
'engine basis in the Superset source code.',
|
'engine basis in the Superset source code.',
|
||||||
),
|
),
|
||||||
mapStateToProps: ({ datasource }) => ({
|
mapStateToProps: ({ datasource }) => ({
|
||||||
choices: (datasource as Dataset)?.time_grain_sqla || null,
|
choices: (datasource as Dataset)?.time_grain_sqla || [],
|
||||||
}),
|
}),
|
||||||
visibility: ({ controls }) => {
|
visibility: ({ controls }) => {
|
||||||
if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
|
if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user