From 3c8b1d8fcf31e6b45a22de2a9bacaf9e8af2ceb2 Mon Sep 17 00:00:00 2001 From: riahk Date: Sun, 28 Aug 2022 19:20:19 -0700 Subject: [PATCH 1/2] add onFilterUpdate handler to list view filters --- .../components/ListView/Filters/Select.tsx | 2 +- .../src/components/ListView/Filters/index.tsx | 37 ++++++++++++++++--- .../src/components/ListView/types.ts | 1 + 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/components/ListView/Filters/Select.tsx b/superset-frontend/src/components/ListView/Filters/Select.tsx index ecda25a81ff63..881a04da4c2b4 100644 --- a/superset-frontend/src/components/ListView/Filters/Select.tsx +++ b/superset-frontend/src/components/ListView/Filters/Select.tsx @@ -58,7 +58,7 @@ function SelectFilter( }; const onClear = () => { - onSelect(undefined); + onSelect(undefined, true); setSelectedOption(undefined); }; diff --git a/superset-frontend/src/components/ListView/Filters/index.tsx b/superset-frontend/src/components/ListView/Filters/index.tsx index 348ed3850dd26..f2f041d7f5332 100644 --- a/superset-frontend/src/components/ListView/Filters/index.tsx +++ b/superset-frontend/src/components/ListView/Filters/index.tsx @@ -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') { @@ -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); + } + } + + updateFilterValue(index, option); + }} paginate={paginate} selects={selects} /> @@ -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); + }} /> ); } diff --git a/superset-frontend/src/components/ListView/types.ts b/superset-frontend/src/components/ListView/types.ts index a0f495385e490..936900885b2ab 100644 --- a/superset-frontend/src/components/ListView/types.ts +++ b/superset-frontend/src/components/ListView/types.ts @@ -52,6 +52,7 @@ export interface Filter { unfilteredLabel?: string; selects?: SelectOption[]; onFilterOpen?: () => void; + onFilterUpdate?: (value?: any) => void; fetchSelects?: ( filterValue: string, page: number, From e8a8bf330b6da946a95dc213c920b1d631ee9eec Mon Sep 17 00:00:00 2001 From: riahk Date: Tue, 13 Sep 2022 13:16:44 -0700 Subject: [PATCH 2/2] fix tslint --- superset-frontend/src/components/ListView/Filters/Select.tsx | 2 +- superset-frontend/src/components/ListView/Filters/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/components/ListView/Filters/Select.tsx b/superset-frontend/src/components/ListView/Filters/Select.tsx index 881a04da4c2b4..b6c1e27642384 100644 --- a/superset-frontend/src/components/ListView/Filters/Select.tsx +++ b/superset-frontend/src/components/ListView/Filters/Select.tsx @@ -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']; } diff --git a/superset-frontend/src/components/ListView/Filters/index.tsx b/superset-frontend/src/components/ListView/Filters/index.tsx index f2f041d7f5332..6f839cd7208a2 100644 --- a/superset-frontend/src/components/ListView/Filters/index.tsx +++ b/superset-frontend/src/components/ListView/Filters/index.tsx @@ -87,7 +87,7 @@ function UIFilters( name={id} onSelect={( option: SelectOption | undefined, - isClear: boolean, + isClear?: boolean, ) => { if (onFilterUpdate) { // Filter change triggers both onChange AND onClear, only want to track onChange