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 460742b4d975d5a0e9030415fc10a8668c3448f2
Author: Antonio Rivero <[email protected]>
AuthorDate: Thu Apr 25 13:26:59 2024 +0200

    Table with Time Comparison:
    
    - When calling the time range method ensure we pass an array so we can 
remove the array check and follow the method signature
---
 .../superset-ui-core/src/time-comparison/fetchTimeRange.ts     | 10 ++++------
 .../src/explore/components/controls/ComparisonRangeLabel.tsx   |  8 ++++++--
 2 files changed, 10 insertions(+), 8 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 8a130e225e..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,12 +64,10 @@ export const fetchTimeRange = async (
   let query;
   let endpoint;
   if (shifts && !isEmpty(shifts)) {
-    const timeRanges = (Array.isArray(shifts) ? shifts : [shifts])?.map(
-      shift => ({
-        timeRange,
-        shift,
-      }),
-    );
+    const timeRanges = shifts?.map(shift => ({
+      timeRange,
+      shift,
+    }));
     query = rison.encode_uri([{ timeRange }, ...timeRanges]);
     endpoint = `/api/v1/time_range/?q=${query}`;
   } else {
diff --git 
a/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx 
b/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx
index 18a2e3186a..3f3029b35b 100644
--- a/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx
+++ b/superset-frontend/src/explore/components/controls/ComparisonRangeLabel.tsx
@@ -24,6 +24,7 @@ import moment, { Moment } from 'moment';
 import {
   BinaryAdhocFilter,
   css,
+  ensureIsArray,
   fetchTimeRange,
   SimpleAdhocFilter,
   t,
@@ -103,7 +104,6 @@ export const ComparisonRangeLabel = ({
   const shifts = useSelector<RootState, string[]>(
     state => state.explore.form_data.time_compare,
   );
-  console.log('lily shifts', shifts);
   const startDate = useSelector<RootState, string>(
     state => state.explore.form_data.start_date_offset,
   );
@@ -137,7 +137,11 @@ export const ComparisonRangeLabel = ({
           newShifts = [`${inInheritShift} days ago`];
         }
 
-        return fetchTimeRange(filter.comparator, filter.subject, newShifts);
+        return fetchTimeRange(
+          filter.comparator,
+          filter.subject,
+          ensureIsArray(newShifts),
+        );
       });
       Promise.all(promises).then(res => {
         // access the value property inside the res and set the labels with it 
in the state

Reply via email to