Skip to content

Commit

Permalink
Fix list appears loaded when at least one record was fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Jun 7, 2019
1 parent 16a1fea commit 23b8068
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/ra-core/src/fetch/useGetList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ const useGetList = (
filter: object,
options?: any
) => {
const { data, total, error, loading, loaded } = useQueryWithStore(
const { data: ids, total, error, loading, loaded } = useQueryWithStore(
{ type: GET_LIST, resource, payload: { pagination, sort, filter } },
{ ...options, action: CRUD_GET_LIST },
(state: ReduxState) =>
state.admin.resources[resource]
? state.admin.resources[resource].data
? state.admin.resources[resource].list.ids
: null,
(state: ReduxState) =>
state.admin.resources[resource]
? state.admin.resources[resource].list.total
: null
);
const ids = useSelector(
const data = useSelector(
(state: ReduxState) =>
state.admin.resources[resource]
? state.admin.resources[resource].list.ids
? state.admin.resources[resource].data
: null,
[resource]
);
Expand Down
6 changes: 5 additions & 1 deletion packages/ra-core/src/fetch/useQueryWithStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export interface QueryOptions {
* @see src/reducer/admin/data.ts
*/
const isEmptyList = data =>
data && Object.keys(data).length === 0 && data.hasOwnProperty('fetchedAt');
Array.isArray(data)
? data.length === 0
: data &&
Object.keys(data).length === 0 &&
data.hasOwnProperty('fetchedAt');

/**
* Default cache selector. Allows to cache responses by default.
Expand Down

0 comments on commit 23b8068

Please sign in to comment.