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

Fix ExportButton doesn't take permanent filter into account #5675

Merged
merged 1 commit into from
Dec 16, 2020
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
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