-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(native-filters): Time native filter #12992
Merged
Merged
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a29c6d0
Add Time Filter component
agatapst 1c3f891
Improve Time Filter component
agatapst a7af2e9
Fix import errors
agatapst 4ed0cb5
Display Time Filter
agatapst 82a0320
Remove console logs
agatapst a727bfe
Change Control Panel
agatapst c2ba1c7
Remove unnecessary files
agatapst ff28359
Use time range override
agatapst 158d86b
test: fix tests
simcha90 5260fca
feat: re run pipeline
simcha90 56c5fc4
fix: fix some case for Time filter
simcha90 20308cb
Merge branch 'master' of github.com:apache/superset into time-cont
simcha90 a0619c0
fix: merge with master
simcha90 e3de8a6
Merge branch 'master' into time-cont
villebro 111b2d0
use original time range
villebro c52617c
fix height
villebro 639dac2
Merge branch 'master' into time-cont
villebro a67b0fe
add cross filter behavior
villebro 0659f3f
apply filters on initialization
villebro 7063b2e
Merge branch 'master' into time-cont
villebro 23592ea
add applied filter to overrides
villebro a71d35b
add unit tests for merge_extra_form_data
villebro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,12 +76,12 @@ 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), | ||
timeRangeString, | ||
}; | ||
} catch (response) { | ||
const clientError = await getClientErrorObject(response); | ||
|
@@ -168,13 +168,20 @@ const IconWrapper = styled.span` | |
interface DateFilterLabelProps { | ||
name: string; | ||
onChange: (timeRange: string) => void; | ||
onTimeRangeChange?: (textValue?: string, timeRange?: string) => void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
value?: string; | ||
endpoints?: TimeRangeEndpoints; | ||
datasource?: string; | ||
} | ||
|
||
export default function DateFilterControl(props: DateFilterLabelProps) { | ||
const { value = 'Last week', endpoints, onChange, datasource } = props; | ||
const { | ||
value = 'Last week', | ||
endpoints, | ||
datasource, | ||
onChange, | ||
onTimeRangeChange = () => {}, | ||
} = props; | ||
const [actualTimeRange, setActualTimeRange] = useState<string>(value); | ||
|
||
const [show, setShow] = useState<boolean>(false); | ||
|
@@ -187,13 +194,14 @@ export default function DateFilterControl(props: DateFilterLabelProps) { | |
|
||
useEffect(() => { | ||
if (!isMounted) setIsMounted(true); | ||
fetchTimeRange(value, endpoints).then(({ value: actualRange, error }) => { | ||
if (error) { | ||
setEvalResponse(error || ''); | ||
setValidTimeRange(false); | ||
setTooltipTitle(value || ''); | ||
} else { | ||
/* | ||
fetchTimeRange(value, endpoints).then( | ||
({ value: actualRange, timeRangeString, error }) => { | ||
if (error) { | ||
setEvalResponse(error || ''); | ||
setValidTimeRange(false); | ||
setTooltipTitle(value || ''); | ||
} else { | ||
/* | ||
HRT == human readable text | ||
ADR == actual datetime range | ||
+--------------+------+----------+--------+----------+-----------+ | ||
|
@@ -204,20 +212,24 @@ export default function DateFilterControl(props: DateFilterLabelProps) { | |
| tooltip | ADR | ADR | HRT | HRT | ADR | | ||
+--------------+------+----------+--------+----------+-----------+ | ||
*/ | ||
if ( | ||
frame === 'Common' || | ||
frame === 'Calendar' || | ||
frame === 'No filter' | ||
) { | ||
setActualTimeRange(value); | ||
setTooltipTitle(actualRange || ''); | ||
} else { | ||
setActualTimeRange(actualRange || ''); | ||
setTooltipTitle(value || ''); | ||
const currentFrame = guessFrame(value); | ||
if ( | ||
currentFrame === 'Common' || | ||
currentFrame === 'Calendar' || | ||
currentFrame === 'No filter' | ||
) { | ||
setActualTimeRange(value); | ||
setTooltipTitle(actualRange || ''); | ||
onTimeRangeChange(value, timeRangeString); | ||
} else { | ||
setActualTimeRange(actualRange || ''); | ||
setTooltipTitle(value || ''); | ||
onTimeRangeChange(value, timeRangeString); | ||
} | ||
setValidTimeRange(true); | ||
} | ||
setValidTimeRange(true); | ||
} | ||
}); | ||
}, | ||
); | ||
}, [value]); | ||
|
||
useEffect(() => { | ||
|
@@ -245,6 +257,12 @@ export default function DateFilterControl(props: DateFilterLabelProps) { | |
setShow(false); | ||
} | ||
|
||
function onOpen() { | ||
setTimeRangeValue(value); | ||
setFrame(guessFrame(value)); | ||
setShow(true); | ||
} | ||
|
||
function onHide() { | ||
setTimeRangeValue(value); | ||
setFrame(guessFrame(value)); | ||
|
@@ -355,7 +373,7 @@ export default function DateFilterControl(props: DateFilterLabelProps) { | |
<Label | ||
className="pointer" | ||
data-test="time-range-trigger" | ||
onClick={() => setShow(true)} | ||
onClick={onOpen} | ||
> | ||
{actualTimeRange} | ||
</Label> | ||
|
69 changes: 69 additions & 0 deletions
69
superset-frontend/src/filters/components/Time/AntdTimeFilter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* 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 } from '@superset-ui/core'; | ||
import React, { useState, useEffect } from 'react'; | ||
import DateFilterControl from 'src/explore/components/controls/DateFilterControl/DateFilterControl'; | ||
import { AntdPluginFilterStylesProps } from '../types'; | ||
import { AntdPluginFilterTimeProps } from './types'; | ||
|
||
const DEFAULT_VALUE = 'Last week'; | ||
|
||
const Styles = styled.div<AntdPluginFilterStylesProps>` | ||
height: ${({ height }) => height}px; | ||
width: ${({ width }) => width}px; | ||
overflow-x: scroll; | ||
`; | ||
|
||
export default function AntdTimeFilter(props: AntdPluginFilterTimeProps) { | ||
const { formData, setExtraFormData, width, height } = props; | ||
const { defaultValue, currentValue } = formData; | ||
|
||
const [value, setValue] = useState<string>(defaultValue ?? DEFAULT_VALUE); | ||
|
||
const handleTimeRangeChange = (textValue: string, timeRange: string) => { | ||
setExtraFormData({ | ||
// @ts-ignore | ||
extraFormData: { | ||
override_form_data: { | ||
time_range: timeRange, | ||
zhaoyongjie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
currentState: { value: textValue }, | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
setValue(currentValue ?? DEFAULT_VALUE); | ||
}, [currentValue]); | ||
|
||
useEffect(() => { | ||
setValue(defaultValue ?? DEFAULT_VALUE); | ||
}, [defaultValue]); | ||
|
||
return ( | ||
<Styles width={width} height={height}> | ||
<DateFilterControl | ||
value={value} | ||
name="" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one nit: |
||
onChange={setValue} | ||
onTimeRangeChange={handleTimeRangeChange} | ||
/> | ||
</Styles> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
superset-frontend/src/filters/components/Time/controlPanel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* 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 { ControlPanelConfig } from '@superset-ui/chart-controls'; | ||
|
||
const config: ControlPanelConfig = { | ||
// For control input types, see: superset-frontend/src/explore/components/controls/index.js | ||
controlPanelSections: [], | ||
}; | ||
|
||
export default config; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* 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 { t, ChartMetadata, ChartPlugin } from '@superset-ui/core'; | ||
import controlPanel from './controlPanel'; | ||
import transformProps from './transformProps'; | ||
import thumbnail from './images/thumbnail.png'; | ||
|
||
export default class TimeFilterPlugin extends ChartPlugin { | ||
constructor() { | ||
const metadata = new ChartMetadata({ | ||
name: t('Time range filter plugin'), | ||
description: 'Custom time filter plugin', | ||
isNativeFilter: true, | ||
villebro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
thumbnail, | ||
}); | ||
|
||
super({ | ||
controlPanel, | ||
loadChart: () => import('./AntdTimeFilter'), | ||
metadata, | ||
transformProps, | ||
}); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
superset-frontend/src/filters/components/Time/transformProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* 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 { ChartProps } from '@superset-ui/core'; | ||
import { DEFAULT_FORM_DATA } from './types'; | ||
|
||
export default function transformProps(chartProps: ChartProps) { | ||
const { formData, height, hooks, queriesData, width } = chartProps; | ||
const { setExtraFormData } = hooks; | ||
const { data } = queriesData[0]; | ||
|
||
return { | ||
data, | ||
formData: { | ||
...DEFAULT_FORM_DATA, | ||
...formData, | ||
}, | ||
height, | ||
setExtraFormData, | ||
width, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* 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 { | ||
QueryFormData, | ||
DataRecord, | ||
SetExtraFormDataHook, | ||
} from '@superset-ui/core'; | ||
import { AntdPluginFilterStylesProps } from '../types'; | ||
|
||
interface PluginFilterTimeCustomizeProps { | ||
defaultValue?: string | null; | ||
currentValue?: string | null; | ||
} | ||
|
||
export type AntdPluginFilterSelectQueryFormData = QueryFormData & | ||
AntdPluginFilterStylesProps & | ||
PluginFilterTimeCustomizeProps; | ||
|
||
export type AntdPluginFilterTimeProps = AntdPluginFilterStylesProps & { | ||
data: DataRecord[]; | ||
setExtraFormData: SetExtraFormDataHook; | ||
formData: AntdPluginFilterSelectQueryFormData; | ||
}; | ||
|
||
export const DEFAULT_FORM_DATA: PluginFilterTimeCustomizeProps = { | ||
defaultValue: null, | ||
currentValue: null, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NEED to double check here.
timeRangeString
isAbsolute time range
.eg:
if today is 2021-2-8, then
last day
, generate "2021-02-07 : 2021-02-08".when the 2021-3-8, then
last day
generate "2021-03-07 : 2021-03-08"