-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: list view filters for Query History (#11702)
- Loading branch information
Showing
16 changed files
with
809 additions
and
416 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -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 { ReactNode } from 'react'; | ||
import { styled } from '@superset-ui/core'; | ||
|
||
export interface BaseFilter { | ||
Header: ReactNode; | ||
initialValue: any; | ||
} | ||
|
||
export const FilterContainer = styled.div` | ||
display: inline-flex; | ||
margin-right: 2em; | ||
font-size: ${({ theme }) => theme.typography.sizes.s}px; | ||
`; | ||
|
||
export const FilterTitle = styled.label` | ||
font-weight: bold; | ||
line-height: 27px; | ||
margin: 0 0.4em 0 0; | ||
`; |
75 changes: 75 additions & 0 deletions
75
superset-frontend/src/components/ListView/Filters/DateRange.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,75 @@ | ||
/** | ||
* 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 React, { useState, useMemo } from 'react'; | ||
import moment, { Moment } from 'moment'; | ||
import { styled } from '@superset-ui/core'; | ||
import { RangePicker as AntRangePicker } from 'src/common/components/DatePicker'; | ||
import { FilterContainer, BaseFilter, FilterTitle } from './Base'; | ||
|
||
interface DateRangeFilterProps extends BaseFilter { | ||
onSubmit: (val: number[]) => void; | ||
name: string; | ||
} | ||
|
||
type ValueState = [number, number]; | ||
|
||
const RangePicker = styled(AntRangePicker)` | ||
padding: 0 11px; | ||
transform: translateX(-7px); | ||
`; | ||
|
||
const RangeFilterContainer = styled(FilterContainer)` | ||
margin-right: 1em; | ||
`; | ||
|
||
export default function DateRangeFilter({ | ||
Header, | ||
initialValue, | ||
onSubmit, | ||
}: DateRangeFilterProps) { | ||
const [value, setValue] = useState<ValueState | null>(initialValue ?? null); | ||
const momentValue = useMemo((): [Moment, Moment] | null => { | ||
if (!value || (Array.isArray(value) && !value.length)) return null; | ||
return [moment(value[0]), moment(value[1])]; | ||
}, [value]); | ||
|
||
return ( | ||
<RangeFilterContainer> | ||
<FilterTitle>{Header}:</FilterTitle> | ||
<RangePicker | ||
showTime | ||
bordered={false} | ||
value={momentValue} | ||
onChange={momentRange => { | ||
if (!momentRange) { | ||
setValue(null); | ||
onSubmit([]); | ||
return; | ||
} | ||
const changeValue = [ | ||
momentRange[0]?.valueOf() ?? 0, | ||
momentRange[1]?.valueOf() ?? 0, | ||
] as ValueState; | ||
setValue(changeValue); | ||
onSubmit(changeValue); | ||
}} | ||
/> | ||
</RangeFilterContainer> | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
superset-frontend/src/components/ListView/Filters/Search.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,61 @@ | ||
/** | ||
* 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 React, { useState } from 'react'; | ||
import SearchInput from 'src/components/SearchInput'; | ||
import { FilterContainer, BaseFilter } from './Base'; | ||
|
||
interface SearchHeaderProps extends BaseFilter { | ||
Header: string; | ||
onSubmit: (val: string) => void; | ||
name: string; | ||
} | ||
|
||
export default function SearchFilter({ | ||
Header, | ||
name, | ||
initialValue, | ||
onSubmit, | ||
}: SearchHeaderProps) { | ||
const [value, setValue] = useState(initialValue || ''); | ||
const handleSubmit = () => { | ||
if (value) { | ||
onSubmit(value); | ||
} | ||
}; | ||
const onClear = () => { | ||
setValue(''); | ||
onSubmit(''); | ||
}; | ||
|
||
return ( | ||
<FilterContainer> | ||
<SearchInput | ||
data-test="filters-search" | ||
placeholder={Header} | ||
name={name} | ||
value={value} | ||
onChange={e => { | ||
setValue(e.currentTarget.value); | ||
}} | ||
onSubmit={handleSubmit} | ||
onClear={onClear} | ||
/> | ||
</FilterContainer> | ||
); | ||
} |
Oops, something went wrong.