From 3fa000ba0bc1772305c43f4e6801d486caab8dce Mon Sep 17 00:00:00 2001 From: Jacobdavis12 Date: Wed, 8 Jul 2026 01:46:06 +0100 Subject: [PATCH] fix(chart): allow custom date format for week range in Big Number with Trendline (#35752) --- .../src/BigNumber/utils.ts | 2 +- .../test/BigNumber/transformProps.test.ts | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/utils.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/utils.ts index 29fd193bbd3..bfb3f2061be 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/utils.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/utils.ts @@ -49,7 +49,7 @@ export const getDateFormatter = ( ) => timeFormat === SMART_DATE_ID ? getTimeFormatterForGranularity(granularity) - : getTimeFormatter(timeFormat ?? fallbackFormat); + : getTimeFormatter(timeFormat ?? fallbackFormat, granularity); export function getOriginalLabel( metric: QueryFormMetric, diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/BigNumber/transformProps.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/BigNumber/transformProps.test.ts index 7bd49f2c36f..32f4173bc6d 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/test/BigNumber/transformProps.test.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/test/BigNumber/transformProps.test.ts @@ -134,10 +134,34 @@ describe('BigNumberWithTrendline', () => { // bigNumberFallback is only set when bigNumber is null after aggregation expect(transformed.bigNumberFallback).toBeNull(); - // should successfully formatTime by granularity + // granularity (QUARTER) is honored, so the default format renders the + // full quarter range rather than only the start date // @ts-expect-error expect(transformed.formatTime(new Date('2020-01-01'))).toStrictEqual( - '2020-01-01 00:00:00', + '2020 Q1', + ); + }); + + test('should format the week range with a custom date format', () => { + // Regression test for #35636: a custom date format combined with a Week + // time grain should render the full week range, not just the start date. + const propsWithWeekGranularity = { + ...props, + rawFormData: { + ...rawFormData, + time_grain_sqla: TimeGranularity.WEEK, + }, + formData: { + ...props.formData, + timeGrainSqla: TimeGranularity.WEEK, + timeFormat: '%d-%m-%Y', + }, + } as unknown as BigNumberWithTrendlineChartProps; + + const transformed = transformProps(propsWithWeekGranularity); + // @ts-expect-error + expect(transformed.formatTime(new Date('2025-10-13'))).toStrictEqual( + '13-10-2025 — 19-10-2025', ); });