From b5cc365df792ef357f1cb2748c234b0bfb22a833 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Tue, 15 Dec 2020 17:55:54 +0100 Subject: [PATCH] Fix ExportButton doesn't take permanent filter into account Closes #5286 --- packages/ra-core/src/controller/useListController.ts | 2 ++ packages/ra-core/src/controller/useListParams.ts | 8 +------- packages/ra-ui-materialui/src/button/ExportButton.tsx | 6 +++++- packages/ra-ui-materialui/src/types.ts | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/ra-core/src/controller/useListController.ts b/packages/ra-core/src/controller/useListController.ts index ea4e46597b2..38c751d1d36 100644 --- a/packages/ra-core/src/controller/useListController.ts +++ b/packages/ra-core/src/controller/useListController.ts @@ -61,6 +61,7 @@ export interface ListControllerProps { displayedFilters: any; error?: any; exporter?: Exporter | false; + filter?: FilterPayload; filterValues: any; hasCreate: boolean; hideFilter: (filterName: string) => void; @@ -250,6 +251,7 @@ const useListController = ( displayedFilters: query.displayedFilters, error, exporter, + filter, filterValues: query.filterValues, hasCreate, hideFilter: queryModifiers.hideFilter, diff --git a/packages/ra-core/src/controller/useListParams.ts b/packages/ra-core/src/controller/useListParams.ts index 0b961163dfe..e5d634c75cb 100644 --- a/packages/ra-core/src/controller/useListParams.ts +++ b/packages/ra-core/src/controller/useListParams.ts @@ -26,8 +26,6 @@ interface ListParamsOptions { sort?: SortPayload; // default value for a filter when displayed but not yet set filterDefaultValues?: FilterPayload; - // permanent filter which always overrides the user entry - filter?: FilterPayload; debounce?: number; } @@ -111,7 +109,6 @@ const useListParams = ({ resource, location, filterDefaultValues, - filter, // permanent filter sort = defaultSort, perPage = 10, debounce = 500, @@ -191,10 +188,7 @@ const useListParams = ({ requestSignature // eslint-disable-line react-hooks/exhaustive-deps ); - const filterValues = useMemo( - () => ({ ...(query.filter || emptyObject), ...filter }), - [filter, query.filter] - ); + const filterValues = query.filter || emptyObject; const displayedFilterValues = query.displayedFilters || emptyObject; const debouncedSetFilters = lodashDebounce((filter, displayedFilters) => { diff --git a/packages/ra-ui-materialui/src/button/ExportButton.tsx b/packages/ra-ui-materialui/src/button/ExportButton.tsx index 6183de01a61..ca3e947c093 100644 --- a/packages/ra-ui-materialui/src/button/ExportButton.tsx +++ b/packages/ra-ui-materialui/src/button/ExportButton.tsx @@ -25,6 +25,7 @@ const ExportButton: FunctionComponent = props => { ...rest } = props; const { + filter, filterValues, currentSort, exporter: exporterFromContext, @@ -39,7 +40,9 @@ const ExportButton: FunctionComponent = props => { dataProvider .getList(resource, { sort: currentSort || sort, - filter: filterValues, + filter: filter + ? { ...filterValues, ...filter } + : filterValues, pagination: { page: 1, perPage: maxResults }, }) .then( @@ -64,6 +67,7 @@ const ExportButton: FunctionComponent = props => { currentSort, dataProvider, exporter, + filter, filterValues, maxResults, notify, diff --git a/packages/ra-ui-materialui/src/types.ts b/packages/ra-ui-materialui/src/types.ts index da829e9a7cf..083d8103324 100644 --- a/packages/ra-ui-materialui/src/types.ts +++ b/packages/ra-ui-materialui/src/types.ts @@ -3,6 +3,7 @@ import { Identifier, Exporter, SortPayload, + FilterPayload, Record as RaRecord, ResourceComponentProps, ResourceComponentPropsWithId, @@ -17,7 +18,7 @@ export interface ListProps extends ResourceComponentProps { component?: ElementType; empty?: ReactElement | false; exporter?: Exporter | false; - filter?: any; + filter?: FilterPayload; filterDefaultValues?: any; filters?: ReactElement; pagination?: ReactElement | false;