You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/04/26 02:45:04 UTC
[superset] branch master updated: fix: pivot v2 charts created before `GENERIC_CHART_AXES` is enabled (#23731)
This is an automated email from the ASF dual-hosted git repository.
beto 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 314987f32d fix: pivot v2 charts created before `GENERIC_CHART_AXES` is enabled (#23731)
314987f32d is described below
commit 314987f32dee789d7aa6af14943727af979ee30b
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue Apr 25 19:44:50 2023 -0700
fix: pivot v2 charts created before `GENERIC_CHART_AXES` is enabled (#23731)
---
.../src/plugin/buildQuery.ts | 6 ++++-
.../plugins/plugin-chart-pivot-table/src/types.ts | 2 ++
.../test/plugin/buildQuery.test.ts | 27 ++++++++++++++++++++++
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/buildQuery.ts b/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/buildQuery.ts
index 6e33b41cc7..ac2ddcd332 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/buildQuery.ts
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/buildQuery.ts
@@ -42,7 +42,11 @@ export default function buildQuery(formData: PivotTableQueryFormData) {
isPhysicalColumn(col) &&
formData.time_grain_sqla &&
hasGenericChartAxes &&
- formData?.temporal_columns_lookup?.[col]
+ /* Charts created before `GENERIC_CHART_AXES` is enabled have a different
+ * form data, with `granularity_sqla` set instead.
+ */
+ (formData?.temporal_columns_lookup?.[col] ||
+ formData.granularity_sqla === col)
) {
return {
timeGrain: formData.time_grain_sqla,
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts b/superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
index 8cf9a12ea3..e011f45931 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
@@ -80,6 +80,8 @@ interface PivotTableCustomizeProps {
filters?: ContextMenuFilters,
) => void;
timeGrainSqla?: TimeGranularity;
+ time_grain_sqla?: TimeGranularity;
+ granularity_sqla?: string;
}
export type PivotTableQueryFormData = QueryFormData &
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts b/superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts
index a602bd4048..770cb9849b 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts
@@ -17,6 +17,8 @@
* under the License.
*/
+import { TimeGranularity } from '@superset-ui/core';
+import * as supersetCoreModule from '@superset-ui/core';
import buildQuery from '../../src/plugin/buildQuery';
import { PivotTableQueryFormData } from '../../src/types';
@@ -55,4 +57,29 @@ describe('PivotTableChart buildQuery', () => {
const [query] = queryContext.queries;
expect(query.columns).toEqual(['col1', 'col2', 'row1', 'row2']);
});
+
+ it('should work with old charts after GENERIC_CHART_AXES is enabled', () => {
+ Object.defineProperty(supersetCoreModule, 'hasGenericChartAxes', {
+ value: true,
+ });
+ const modifiedFormData = {
+ ...formData,
+ time_grain_sqla: TimeGranularity.MONTH,
+ granularity_sqla: 'col1',
+ };
+ const queryContext = buildQuery(modifiedFormData);
+ const [query] = queryContext.queries;
+ expect(query.columns).toEqual([
+ {
+ timeGrain: 'P1M',
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'col1',
+ label: 'col1',
+ expressionType: 'SQL',
+ },
+ 'col2',
+ 'row1',
+ 'row2',
+ ]);
+ });
});