Skip to content

Commit

Permalink
Merge pull request #5675 from marmelab/fix-export-button-filter
Browse files Browse the repository at this point in the history
Fix ExportButton doesn't take permanent filter into account
  • Loading branch information
djhi authored Dec 16, 2020
2 parents 105b8ae + b5cc365 commit 6f359dc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/ra-core/src/controller/useListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface ListControllerProps<RecordType extends Record = Record> {
displayedFilters: any;
error?: any;
exporter?: Exporter | false;
filter?: FilterPayload;
filterValues: any;
hasCreate: boolean;
hideFilter: (filterName: string) => void;
Expand Down Expand Up @@ -250,6 +251,7 @@ const useListController = <RecordType extends Record = Record>(
displayedFilters: query.displayedFilters,
error,
exporter,
filter,
filterValues: query.filterValues,
hasCreate,
hideFilter: queryModifiers.hideFilter,
Expand Down
8 changes: 1 addition & 7 deletions packages/ra-core/src/controller/useListParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -111,7 +109,6 @@ const useListParams = ({
resource,
location,
filterDefaultValues,
filter, // permanent filter
sort = defaultSort,
perPage = 10,
debounce = 500,
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/ra-ui-materialui/src/button/ExportButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ExportButton: FunctionComponent<ExportButtonProps> = props => {
...rest
} = props;
const {
filter,
filterValues,
currentSort,
exporter: exporterFromContext,
Expand All @@ -39,7 +40,9 @@ const ExportButton: FunctionComponent<ExportButtonProps> = props => {
dataProvider
.getList(resource, {
sort: currentSort || sort,
filter: filterValues,
filter: filter
? { ...filterValues, ...filter }
: filterValues,
pagination: { page: 1, perPage: maxResults },
})
.then(
Expand All @@ -64,6 +67,7 @@ const ExportButton: FunctionComponent<ExportButtonProps> = props => {
currentSort,
dataProvider,
exporter,
filter,
filterValues,
maxResults,
notify,
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Identifier,
Exporter,
SortPayload,
FilterPayload,
Record as RaRecord,
ResourceComponentProps,
ResourceComponentPropsWithId,
Expand All @@ -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;
Expand Down

0 comments on commit 6f359dc

Please sign in to comment.