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
The following commit(s) were added to refs/heads/time_comparison_zeros by this
push:
new 82af406804 Time Comparison:
82af406804 is described below
commit 82af4068040da3d675505e1b7c9c28b4955faba5
Author: Antonio Rivero <[email protected]>
AuthorDate: Tue Aug 20 10:59:08 2024 +0200
Time Comparison:
- Render label when coming from inherit to custom without error
---
.../components/controls/ComparisonRangeLabel.tsx | 53 ++++++++++++++--------
1 file changed, 35 insertions(+), 18 deletions(-)
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