You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by en...@apache.org on 2026/06/23 15:05:49 UTC
(superset) branch master updated: fix(big-number): respect extra_form_data.time_compare in Big Number with Time Comparison (#41342)
This is an automated email from the ASF dual-hosted git repository.
EnxDev 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 3ff90bd532c fix(big-number): respect extra_form_data.time_compare in Big Number with Time Comparison (#41342)
3ff90bd532c is described below
commit 3ff90bd532c903347dd81ad612aa347c2f31cc12
Author: Enzo Martellucci <52...@users.noreply.github.com>
AuthorDate: Tue Jun 23 17:05:42 2026 +0200
fix(big-number): respect extra_form_data.time_compare in Big Number with Time Comparison (#41342)
---
.../BigNumberPeriodOverPeriod/buildQuery.ts | 18 ++++--
.../BigNumberPeriodOverPeriod/transformProps.ts | 6 +-
.../BigNumberPeriodOverPeriod/buildQuery.test.ts | 73 ++++++++++++++++++++++
3 files changed, 92 insertions(+), 5 deletions(-)
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/buildQuery.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/buildQuery.ts
index e230097e266..cb185ef8540 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/buildQuery.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/buildQuery.ts
@@ -29,7 +29,7 @@ import {
import { isEmpty } from 'lodash';
export default function buildQuery(formData: QueryFormData) {
- const { cols: groupby } = formData;
+ const { cols: groupby, extra_form_data } = formData;
const queryContextA = buildQueryContext(formData, baseQueryObject => {
const postProcessing: PostProcessingRule[] = [];
@@ -58,14 +58,24 @@ export default function buildQuery(formData: QueryFormData) {
timeOffsets = timeOffsets.concat(['inherit']);
}
}
+
+ if (
+ extra_form_data?.time_compare &&
+ !timeOffsets.includes(extra_form_data.time_compare)
+ ) {
+ timeOffsets = [extra_form_data.time_compare];
+ }
+
return [
{
...baseQueryObject,
groupby,
post_processing: postProcessing,
- time_offsets: isTimeComparison(formData, baseQueryObject)
- ? ensureIsArray(timeOffsets)
- : [],
+ time_offsets:
+ isTimeComparison(formData, baseQueryObject) ||
+ extra_form_data?.time_compare
+ ? ensureIsArray(timeOffsets)
+ : [],
},
];
});
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts
index b610d5b35de..70e8702fb8d 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts
@@ -111,7 +111,11 @@ export default function transformProps(chartProps: ChartProps) {
const metrics = chartProps.datasource?.metrics || [];
const originalLabel = getOriginalLabel(metric, metrics);
const showMetricName = chartProps.rawFormData?.show_metric_name ?? false;
- const timeComparison = ensureIsArray(chartProps.rawFormData?.time_compare)[0];
+
+ const dashboardTimeCompare = formData?.extraFormData?.time_compare;
+ const timeComparison =
+ dashboardTimeCompare ||
+ ensureIsArray(chartProps.rawFormData?.time_compare)[0];
const startDateOffset = chartProps.rawFormData?.start_date_offset;
const currentTimeRangeFilter = chartProps.rawFormData?.adhoc_filters?.filter(
(adhoc_filter: SimpleAdhocFilter) =>
diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/BigNumber/BigNumberPeriodOverPeriod/buildQuery.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/BigNumber/BigNumberPeriodOverPeriod/buildQuery.test.ts
new file mode 100644
index 00000000000..ed541ecdadc
--- /dev/null
+++ b/superset-frontend/plugins/plugin-chart-echarts/test/BigNumber/BigNumberPeriodOverPeriod/buildQuery.test.ts
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { QueryFormData } from '@superset-ui/core';
+import buildQuery from '../../../src/BigNumber/BigNumberPeriodOverPeriod/buildQuery';
+
+describe('BigNumberPeriodOverPeriod buildQuery', () => {
+ const baseFormData: QueryFormData = {
+ datasource: '1__table',
+ viz_type: 'pop_kpi',
+ metric: 'count',
+ cols: [],
+ adhoc_filters: [
+ {
+ clause: 'WHERE',
+ subject: 'order_date',
+ operator: 'TEMPORAL_RANGE',
+ comparator: '2003-07-01 : 2004-01-01',
+ expressionType: 'SIMPLE',
+ },
+ ],
+ };
+
+ test('flows extra_form_data.time_compare override into time_offsets', () => {
+ const queryContext = buildQuery({
+ ...baseFormData,
+ extra_form_data: { time_compare: '1 year ago' },
+ });
+
+ expect(queryContext.queries[0].time_offsets).toEqual(['1 year ago']);
+ });
+
+ test('requests offsets from the override even without the chart time_compare control', () => {
+ const queryContext = buildQuery({
+ ...baseFormData,
+ time_compare: undefined,
+ extra_form_data: { time_compare: '1 year ago' },
+ });
+
+ expect(queryContext.queries[0].time_offsets).toEqual(['1 year ago']);
+ });
+
+ test('does not duplicate the offset when it already matches time_compare', () => {
+ const queryContext = buildQuery({
+ ...baseFormData,
+ time_compare: ['1 year ago'],
+ extra_form_data: { time_compare: '1 year ago' },
+ });
+
+ expect(queryContext.queries[0].time_offsets).toEqual(['1 year ago']);
+ });
+
+ test('omits time_offsets when neither the control nor the override is set', () => {
+ const queryContext = buildQuery(baseFormData);
+
+ expect(queryContext.queries[0].time_offsets).toEqual([]);
+ });
+});