Skip to content
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(filters): add onFilterUpdate handler to list view filters #21443

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions superset-frontend/src/components/ListView/Filters/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { FilterContainer, BaseFilter, FilterHandler } from './Base';
interface SelectFilterProps extends BaseFilter {
fetchSelects?: Filter['fetchSelects'];
name?: string;
onSelect: (selected: SelectOption | undefined) => void;
onSelect: (selected: SelectOption | undefined, isClear?: boolean) => void;
paginate?: boolean;
selects: Filter['selects'];
}
Expand All @@ -58,7 +58,7 @@ function SelectFilter(
};

const onClear = () => {
onSelect(undefined);
onSelect(undefined, true);
setSelectedOption(undefined);
};

Expand Down
37 changes: 32 additions & 5 deletions superset-frontend/src/components/ListView/Filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ function UIFilters(
return (
<>
{filters.map(
({ Header, fetchSelects, id, input, paginate, selects }, index) => {
(
{
Header,
fetchSelects,
id,
input,
paginate,
selects,
onFilterUpdate,
},
index,
) => {
const initialValue =
internalFilters[index] && internalFilters[index].value;
if (input === 'select') {
Expand All @@ -74,9 +85,19 @@ function UIFilters(
initialValue={initialValue}
key={id}
name={id}
onSelect={(option: SelectOption | undefined) =>
updateFilterValue(index, option)
}
onSelect={(
option: SelectOption | undefined,
isClear?: boolean,
) => {
if (onFilterUpdate) {
// Filter change triggers both onChange AND onClear, only want to track onChange
if (!isClear) {
onFilterUpdate(option);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onFilterUpdate?.(option); would work too

}
}

updateFilterValue(index, option);
}}
paginate={paginate}
selects={selects}
/>
Expand All @@ -90,7 +111,13 @@ function UIFilters(
initialValue={initialValue}
key={id}
name={id}
onSubmit={(value: string) => updateFilterValue(index, value)}
onSubmit={(value: string) => {
if (onFilterUpdate) {
onFilterUpdate(value);
}

updateFilterValue(index, value);
}}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/ListView/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface Filter {
unfilteredLabel?: string;
selects?: SelectOption[];
onFilterOpen?: () => void;
onFilterUpdate?: (value?: any) => void;
fetchSelects?: (
filterValue: string,
page: number,
Expand Down