This is an automated email from the ASF dual-hosted git repository. arivero pushed a commit to branch table-time-comparison-offset in repository https://gitbox.apache.org/repos/asf/superset.git
commit 65e86e8d1a85bba01366b212c04aa7cd4920c191 Author: lilykuang <[email protected]> AuthorDate: Wed Apr 24 11:13:22 2024 -0700 fix time shift --- .../superset-ui-core/src/time-comparison/fetchTimeRange.ts | 2 +- .../explore/components/controls/ComparisonRangeLabel.tsx | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/time-comparison/fetchTimeRange.ts b/superset-frontend/packages/superset-ui-core/src/time-comparison/fetchTimeRange.ts index 2b344ae0d5..8dff2d9ac9 100644 --- a/superset-frontend/packages/superset-ui-core/src/time-comparison/fetchTimeRange.ts +++ b/superset-frontend/packages/superset-ui-core/src/time-comparison/fetchTimeRange.ts @@ -64,7 +64,7 @@ export const fetchTimeRange = async ( let query; let endpoint; if (shifts && !isEmpty(shifts)) { - const timeRanges = shifts.map(shift => ({ + const timeRanges = shifts?.map(shift => ({ timeRange, shift, })); diff --git a/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx b/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx index ff5008f2d2..616cb1698d 100644 --- a/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx +++ b/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx @@ -66,13 +66,18 @@ export const ComparisonRangeLabel = ({ setLabels([]); } else if (!isEmpty(shifts) || startDate) { const promises = currentTimeRangeFilters.map(filter => { - const startDateShift = moment( - (filter as any).comparator.split(' : ')[0], - ).diff(moment(startDate), 'days'); + const startDateShift = + startDate && + moment((filter as any).comparator.split(' : ')[0]).diff( + moment(startDate), + 'days', + ); const newshift = startDateShift ? [`${startDateShift} days ago`] : shifts - ? shifts.slice(0, 1) + ? Array.isArray(shifts) + ? shifts + : [shifts] : undefined; return fetchTimeRange(
