Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-chart-table): Include time control #23533

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
FormDataResidual,
QueryMode,
} from './types/QueryFormData';
import { hasGenericChartAxes } from './getXAxis';

/**
* Extra SQL query related fields from chart form data.
Expand Down Expand Up @@ -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);
}

Expand Down
30 changes: 17 additions & 13 deletions superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,24 @@ const config: ControlPanelConfig = {
},
},
],
!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: '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: 'order_desc',
config: {
Expand Down
20 changes: 20 additions & 0 deletions superset-frontend/src/explore/actions/hydrateExplore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import { Dispatch } from 'redux';
import {
ensureIsArray,
getCategoricalSchemeRegistry,
getColumnLabel,
getSequentialSchemeRegistry,
hasGenericChartAxes,
NO_TIME_RANGE,
QueryFormColumn,
} from '@superset-ui/core';
import {
getFormDataFromControls,
Expand Down Expand Up @@ -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;
}
Expand Down