villebro commented on a change in pull request #12946:
URL: https://github.com/apache/superset/pull/12946#discussion_r570948771
##########
File path:
superset-frontend/src/explore/components/controls/DateFilterControl/DateFilterControl.tsx
##########
@@ -76,12 +77,13 @@ const fetchTimeRange = async (
const endpoint = `/api/v1/time_range/?q=${query}`;
try {
const response = await SupersetClient.get({ endpoint });
- const timeRangeString = buildTimeRangeString(
- response?.json?.result?.since || '',
- response?.json?.result?.until || '',
- );
+ const { since = '', until = '' } = response?.json?.result || {};
+ const timeRangeString = buildTimeRangeString(since, until);
+
return {
value: formatTimeRange(timeRangeString, endpoints),
+ since,
+ until,
Review comment:
instead of returning `since` and `until`, let's rather return
`timeRangeString` as that's what we'll be passing to `ExtraFormData`.
##########
File path: superset-frontend/src/filters/components/Time/TimeFilter.tsx
##########
@@ -0,0 +1,72 @@
+/**
+ * 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 { styled, TimeRange } from '@superset-ui/core';
+import React, { useState, useEffect } from 'react';
+import DateFilterControl from
'src/explore/components/controls/DateFilterControl/DateFilterControl';
+import { getRangeExtraFormData } from 'src/filters/utils';
+import { AntdPluginFilterStylesProps } from '../types';
+import { DEFAULT_FORM_DATA, PluginFilterTimeProps } from './types';
+
+const Styles = styled.div<AntdPluginFilterStylesProps>`
+ height: ${({ height }) => height}px;
+ width: ${({ width }) => width}px;
+ overflow-x: scroll;
+`;
+
+export default function PluginFilterTime(props: PluginFilterTimeProps) {
+ const { formData, setExtraFormData, width, height } = props;
+ const { defaultValue } = {
+ ...DEFAULT_FORM_DATA,
+ ...formData,
+ };
+
+ const firstDefault = (defaultValue?.[0] || '').toString();
+ const [value, setValue] = useState<string>(firstDefault || 'Last week');
+
+ let { groupby = [] } = formData;
+ groupby = Array.isArray(groupby) ? groupby : [groupby];
+
+ const handleTimeRangeChange = (timeRange: TimeRange) => {
+ const [col] = groupby;
+ const extraFormData = getRangeExtraFormData(
+ col,
+ timeRange.since,
+ timeRange.until,
+ );
+ // @ts-ignore
+ setExtraFormData({ extraFormData, currentState: { value: [value] } });
+ };
Review comment:
I checked, this would be roughly the correct hook call (assuming
`time_range` is what's generated by `buildTimeRangeString`):
```
setExtraFormData({
extraFormData: {
override_form_data: {
time_range,
}
},
currentState: { value: [timeRange] },
});
```
Btw, you'll need to `@ts-ignore` until we update the `ExtraFormData` type in
`superset-ui/core`
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]