Skip to content

Commit

Permalink
Fix update or delete resets the pagination
Browse files Browse the repository at this point in the history
Closes #4902
  • Loading branch information
fzaninotto committed Jun 12, 2020
1 parent e314e07 commit 9b6bca6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/ra-core/src/controller/useListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ const useListController = <RecordType = Record>(
get(state.admin.resources, [resource, 'list', 'total'], 0)
);

const finalIds = typeof total === 'undefined' ? defaultIds : ids;

useEffect(() => {
if (
query.page <= 0 ||
(!loading && query.page > 1 && (ids || []).length === 0)
(!loading && query.page > 1 && (finalIds || []).length === 0)
) {
// query for a page that doesn't exist, set page to 1
queryModifiers.setPage(1);
}
}, [loading, query.page, ids, queryModifiers]);
}, [loading, query.page, finalIds, queryModifiers, total, defaultIds]);

const currentSort = useMemo(
() => ({
Expand All @@ -209,7 +211,7 @@ const useListController = <RecordType = Record>(
filterValues: query.filterValues,
hasCreate,
hideFilter: queryModifiers.hideFilter,
ids: typeof total === 'undefined' ? defaultIds : ids,
ids: finalIds,
loaded: loaded || defaultIds.length > 0,
loading,
onSelect: selectionModifiers.select,
Expand Down

0 comments on commit 9b6bca6

Please sign in to comment.