rusackas commented on code in PR #44527:
URL: https://github.com/apache/superset/pull/44527#discussion_r4087055936


##########
superset-frontend/src/filters/components/DateRange/utils.ts:
##########
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import dayjs, { Dayjs } from 'dayjs';
+
+export const DATE_FORMAT = 'YYYY-MM-DD';
+export const RANGE_SEPARATOR = ' : ';
+
+export type DateRangeValue = [Dayjs | null, Dayjs | null] | null;
+
+export function parseTimeRange(value?: string | null): DateRangeValue {
+  if (!value) return null;
+  const [start, end] = value.split(RANGE_SEPARATOR);
+  const startDate = dayjs(start);
+  const endDate = dayjs(end);
+  if (!startDate.isValid() || !endDate.isValid()) return null;

Review Comment:
   Fixed — `parseTimeRange` now checks `parts.length !== 2` and returns `null` 
before ever reaching `dayjs(undefined)`, so a bare date without the separator 
can't silently become `[now, now]`.



##########
superset-frontend/src/constants.ts:
##########
@@ -200,6 +200,7 @@ export enum FilterPlugins {
   Time = 'filter_time',
   TimeColumn = 'filter_timecolumn',
   TimeGrain = 'filter_timegrain',
+  DateRange = 'filter_date_range',

Review Comment:
   Fixed — `superset/reports/models.py`'s `_generate_native_filter` now has a 
`filter_date_range` branch alongside `filter_time`, with test coverage in 
`model_test.py`.



##########
superset-frontend/src/features/alerts/AlertReportModal.tsx:
##########
@@ -1699,6 +1706,28 @@ const AlertReportModal: 
FunctionComponent<AlertReportModalProps> = ({
         />
       );
     }
+    if (filterType === 'filter_date_range') {
+      return (
+        <RangePicker
+          value={parseTimeRange(filterValues?.[0])}

Review Comment:
   Fixed — the picker in `AlertReportModal.tsx` now uses the imported 
`DATE_FORMAT` constant instead of a literal `'YYYY-MM-DD'`.



##########
superset-frontend/src/features/alerts/AlertReportModal.tsx:
##########
@@ -1699,6 +1706,28 @@ const AlertReportModal: 
FunctionComponent<AlertReportModalProps> = ({
         />
       );
     }
+    if (filterType === 'filter_date_range') {
+      return (
+        <RangePicker
+          value={parseTimeRange(filterValues?.[0])}
+          format="YYYY-MM-DD"
+          allowClear
+          onChange={dates => {
+            const timeRange = formatTimeRange(dates);
+            setNativeFilterData(
+              nativeFilterData.map((f: any) =>
+                filter.nativeFilterId === f.nativeFilterId
+                  ? {
+                      ...f,
+                      filterValues: [timeRange],
+                    }

Review Comment:
   Fixed — `onChange` now stores `filterValues: timeRange ? [timeRange] : []`, 
so clearing the picker persists an empty array instead of `[undefined]`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to