You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by kg...@apache.org on 2023/04/03 10:32:02 UTC

[superset] branch master updated: fix(plugin-chart-table): Include time control (#23533)

This is an automated email from the ASF dual-hosted git repository.

kgabryje 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 13ffb4b7c2 fix(plugin-chart-table): Include time control (#23533)
13ffb4b7c2 is described below

commit 13ffb4b7c203cfa8ebec602fc7c25103eebc019f
Author: Kamil Gabryjelski <ka...@gmail.com>
AuthorDate: Mon Apr 3 12:31:33 2023 +0200

    fix(plugin-chart-table): Include time control (#23533)
---
 .../src/query/extractQueryFields.ts                |  3 ++-
 .../plugin-chart-table/src/controlPanel.tsx        | 30 ++++++++++++----------
 .../src/explore/actions/hydrateExplore.ts          | 20 +++++++++++++++
 3 files changed, 39 insertions(+), 14 deletions(-)

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 860753405e..bef7537257 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 9ca5ce63b1..8630dc78b6 100644
--- a/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx
+++ b/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx
@@ -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: {
diff --git a/superset-frontend/src/explore/actions/hydrateExplore.ts b/superset-frontend/src/explore/actions/hydrateExplore.ts
index f9adc2fe05..e259f62671 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;
     }