Skip to content

Commit

Permalink
fix: time grain can't be removed in explore (#21644)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie committed Sep 30, 2022
1 parent 1d70079 commit 4c17f0e
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
isAdhocColumn,
isPhysicalColumn,
ensureIsArray,
isDefined,
} from '@superset-ui/core';

import {
Expand Down Expand Up @@ -183,7 +184,16 @@ const granularity: SharedControlConfig<'SelectControl'> = {
const time_grain_sqla: SharedControlConfig<'SelectControl'> = {
type: 'SelectControl',
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(
'The time granularity for the visualization. This ' +
'applies a date transformation to alter ' +
Expand All @@ -192,7 +202,7 @@ const time_grain_sqla: SharedControlConfig<'SelectControl'> = {
'engine basis in the Superset source code.',
),
mapStateToProps: ({ datasource }) => ({
choices: (datasource as Dataset)?.time_grain_sqla || null,
choices: (datasource as Dataset)?.time_grain_sqla || [],
}),
visibility: ({ controls }) => {
if (!isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)) {
Expand Down

0 comments on commit 4c17f0e

Please sign in to comment.