diff --git a/superset-frontend/packages/superset-ui-core/src/query/extractQueryFields.ts b/superset-frontend/packages/superset-ui-core/src/query/extractQueryFields.ts index 860753405e7ba..bef75372577d8 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/extractQueryFields.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/extractQueryFields.ts @@ -30,6 +30,7 @@ import { FormDataResidual, QueryMode, } from './types/QueryFormData'; +import { hasGenericChartAxes } from './getXAxis'; /** * Extra SQL query related fields from chart form data. @@ -105,7 +106,7 @@ export default function extractQueryFields( } }); - if (includeTime && !columns.includes(DTTM_ALIAS)) { + if (!hasGenericChartAxes && includeTime && !columns.includes(DTTM_ALIAS)) { columns.unshift(DTTM_ALIAS); } diff --git a/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx index 18436d8b30b47..ae98ef4018804 100644 --- a/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx @@ -31,7 +31,6 @@ import { QueryMode, smartDateFormatter, t, - validateNonEmpty, } from '@superset-ui/core'; import { ColumnOption, @@ -328,40 +327,23 @@ const config: ControlPanelConfig = { }, }, ], - [ - { - name: 'include_time', - config: { - type: 'CheckboxControl', - label: t('Include time'), - description: t( - 'Whether to include the time granularity as defined in the time section', - ), - default: false, - visibility: isAggMode, - resetOnHide: false, - }, - }, - ], - [ - { - name: 'granularity_sqla', - override: { - visibility: ({ controls }) => - !!(hasGenericChartAxes && controls.include_time.value), - validators: [validateNonEmpty], - }, - }, - ], - [ - { - name: 'time_grain_sqla', - override: { - visibility: ({ controls }) => - !!(hasGenericChartAxes && controls.include_time.value), - }, - }, - ], + !hasGenericChartAxes + ? [ + { + name: 'include_time', + config: { + type: 'CheckboxControl', + label: t('Include time'), + description: t( + 'Whether to include the time granularity as defined in the time section', + ), + default: false, + visibility: isAggMode, + resetOnHide: false, + }, + }, + ] + : [null], [ { name: 'order_desc', diff --git a/superset-frontend/src/explore/actions/hydrateExplore.ts b/superset-frontend/src/explore/actions/hydrateExplore.ts index f9adc2fe056f7..e259f62671c33 100644 --- a/superset-frontend/src/explore/actions/hydrateExplore.ts +++ b/superset-frontend/src/explore/actions/hydrateExplore.ts @@ -29,8 +29,11 @@ import { Dispatch } from 'redux'; import { ensureIsArray, getCategoricalSchemeRegistry, + getColumnLabel, getSequentialSchemeRegistry, + hasGenericChartAxes, NO_TIME_RANGE, + QueryFormColumn, } from '@superset-ui/core'; import { getFormDataFromControls, @@ -73,6 +76,23 @@ export const hydrateExplore = initialFormData.time_range = common?.conf?.DEFAULT_TIME_FILTER || NO_TIME_RANGE; } + if ( + hasGenericChartAxes && + initialFormData.include_time && + initialFormData.granularity_sqla && + !initialFormData.groupby?.some( + (col: QueryFormColumn) => + getColumnLabel(col) === + getColumnLabel(initialFormData.granularity_sqla!), + ) + ) { + initialFormData.groupby = [ + initialFormData.granularity_sqla, + ...ensureIsArray(initialFormData.groupby), + ]; + initialFormData.granularity_sqla = undefined; + } + if (dashboardId) { initialFormData.dashboardId = dashboardId; }