This is an automated email from the ASF dual-hosted git repository. arivero pushed a commit to branch time_comparison_zeros in repository https://gitbox.apache.org/repos/asf/superset.git
commit 7e78a15e58a14378ce0a39775161f80ab614f162 Author: Antonio Rivero <[email protected]> AuthorDate: Tue Aug 20 11:11:15 2024 +0200 Time Comparison: - Render label when coming from inherit to custom without error - Custom date must not set hour to 00:00 --- .../src/time-comparison/getTimeOffset.ts | 3 -- .../components/controls/ComparisonRangeLabel.tsx | 53 ++++++++++++++-------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/time-comparison/getTimeOffset.ts b/superset-frontend/packages/superset-ui-core/src/time-comparison/getTimeOffset.ts index fbcbb8d5d4..f4f8b3b58b 100644 --- a/superset-frontend/packages/superset-ui-core/src/time-comparison/getTimeOffset.ts +++ b/superset-frontend/packages/superset-ui-core/src/time-comparison/getTimeOffset.ts @@ -154,9 +154,6 @@ export const computeCustomDateTime = ( let parsed: Date; if (dttm === 'now' || dttm === 'today') { parsed = new Date(); - if (dttm === 'today') { - parsed.setHours(0, 0, 0, 0); - } } else { parsed = new Date(dttm); } diff --git a/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx b/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx index 41f08654f1..f5ac1e961c 100644 --- a/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx +++ b/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx @@ -122,25 +122,42 @@ export const ComparisonRangeLabel = ({ ensureIsArray(newShifts), ); } - return fetchTimeRange(filter.comparator, filter.subject).then(res => { - const datePattern = /\d{4}-\d{2}-\d{2}/g; - const dates = res?.value?.match(datePattern); - const [startDate, endDate] = dates ?? []; - const postProcessedShifts = getTimeOffset({ - timeRangeFilter: { - ...filter, - comparator: `${startDate} : ${endDate}`, - }, - shifts: shiftsArray, - startDate: useStartDate, - includeFutureOffsets: false, // So we don't trigger requests for future dates + // Need to parse Human readable dates to actual dates + if ( + (ensureIsArray(shifts)[0] === 'custom' && startDate) || + ensureIsArray(shifts)[0] !== 'custom' + ) { + return fetchTimeRange(filter.comparator, filter.subject).then(res => { + const datePattern = /\d{4}-\d{2}-\d{2}/g; + const dates = res?.value?.match(datePattern); + const [parsedStartDate, parsedEndDate] = dates ?? []; + if (parsedStartDate) { + const parsedDateMoment = moment(parseDttmToDate(parsedStartDate)); + const startDateMoment = moment(parseDttmToDate(startDate)); + if ( + startDateMoment.isSameOrBefore(parsedDateMoment) || + !startDate + ) { + const postProcessedShifts = getTimeOffset({ + timeRangeFilter: { + ...filter, + comparator: `${parsedStartDate} : ${parsedEndDate}`, + }, + shifts: shiftsArray, + startDate: useStartDate, + includeFutureOffsets: false, // So we don't trigger requests for future dates + }); + return fetchTimeRange( + filter.comparator, + filter.subject, + ensureIsArray(postProcessedShifts), + ); + } + } + return Promise.resolve({ value: '' }); }); - return fetchTimeRange( - filter.comparator, - filter.subject, - ensureIsArray(postProcessedShifts), - ); - }); + } + return Promise.resolve({ value: '' }); }); Promise.all(promises).then(res => { // access the value property inside the res and set the labels with it in the state
