Skip to content

Commit 292f0ce

Browse files
committed
Merge branch 'next' into headless-doc
2 parents 16208b1 + 23ccbfe commit 292f0ce

File tree

16 files changed

+127
-41
lines changed

16 files changed

+127
-41
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 5.10.0
4+
5+
- Upgraded `@tanstack/react-query` to `5.83.0`. You might have duplicate versions if you already had it in your dependencies. Should you have an error mentioning the `QueryContext`, make sure you only have one version in your package manager lock file.
6+
37
## 5.9.1
48

59
* Fix `<Datagrid>` empty throws error when used in standalone mode ([#10812](https://github.com/marmelab/react-admin/pull/10812)) ([fzaninotto](https://github.com/fzaninotto))

docs/List.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,42 @@ const ProductList = () => (
11741174
)
11751175
```
11761176

1177+
## Enabling Data Fetching Conditionally
1178+
1179+
You might want to allow data to be fetched only when at least some filters have been set. You can leverage TanStack react-query `enabled` option for that. It accepts a function that receives the query as its only parameter. As react-admin always format the `queryKey` as `[ResourceName, DataProviderMethod, DataProviderParams]`, you can check that there is at least a filter in this function:
1180+
1181+
{% raw %}
1182+
```tsx
1183+
export const PostList = () => (
1184+
<List
1185+
filters={postFilter}
1186+
queryOptions={{
1187+
enabled: query => {
1188+
const listParams = query.queryKey[2] as GetListParams;
1189+
return listParams.filter.q?.length > 2;
1190+
}
1191+
}}
1192+
>
1193+
<WithListContext
1194+
render={context =>
1195+
context.filterValues.q?.length > 2 ? (
1196+
<CardContentInner>
1197+
Type a search term to fetch data
1198+
</CardContentInner>
1199+
) : (
1200+
<Datagrid>
1201+
{/* your fields */}
1202+
</Datagrid>
1203+
)
1204+
}
1205+
/>
1206+
</List>
1207+
)
1208+
```
1209+
{% endraw %}
1210+
1211+
**Note**: Notice we display some custom UI when there is no filter. This is because otherwise, users would see the loading UI as Tanstack Query will set the `isPending` property of the underlying query to `true` if the query isn't enabled.
1212+
11771213
## Accessing Extra Response Data
11781214

11791215
If `dataProvider.getList()` returns additional metadata in the response under the `meta` key, you can access it in the list view using the `meta` property of the `ListContext`.

examples/simple/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"dependencies": {
1313
"@mui/icons-material": "^5.16.12",
1414
"@mui/material": "^5.16.12",
15-
"@tanstack/react-query": "^5.21.7",
16-
"@tanstack/react-query-devtools": "^5.21.7",
15+
"@tanstack/react-query": "^5.83.0",
16+
"@tanstack/react-query-devtools": "^5.83.0",
1717
"jsonexport": "^3.2.0",
1818
"lodash": "~4.17.5",
1919
"ra-data-fakerest": "^5.9.1",

packages/ra-core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
"react-router-dom": "^6.28.1 || ^7.1.1"
5858
},
5959
"dependencies": {
60-
"@tanstack/react-query": "^5.21.7",
61-
"clsx": "^2.1.1",
60+
"@tanstack/react-query": "^5.83.0",
6261
"date-fns": "^3.6.0",
6362
"eventemitter3": "^5.0.1",
6463
"inflection": "^3.0.0",

packages/ra-core/src/auth/useAuthState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const useAuthState = <ErrorType = Error>(
150150

151151
return authProvider != null
152152
? result
153-
: (noAuthProviderQueryResult as UseAuthStateResult<ErrorType>);
153+
: (noAuthProviderQueryResult as unknown as UseAuthStateResult<ErrorType>);
154154
};
155155

156156
type UseAuthStateOptions<ErrorType = Error> = Omit<

packages/ra-core/src/auth/useCanAccess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const useCanAccess = <
9393

9494
return authProviderHasCanAccess
9595
? result
96-
: (emptyQueryObserverResult as UseCanAccessResult<ErrorType>);
96+
: (emptyQueryObserverResult as unknown as UseCanAccessResult<ErrorType>);
9797
};
9898

9999
const emptyQueryObserverResult = {

packages/ra-core/src/auth/usePermissions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ const usePermissions = <PermissionsType = any, ErrorType = Error>(
108108
);
109109

110110
return !authProvider || !authProvider.getPermissions
111-
? (fakeQueryResult as UsePermissionsResult<PermissionsType, ErrorType>)
111+
? (fakeQueryResult as unknown as UsePermissionsResult<
112+
PermissionsType,
113+
ErrorType
114+
>)
112115
: result;
113116
};
114117

packages/ra-core/src/controller/input/useReferenceInputController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ export const useReferenceInputController = <RecordType extends RaRecord = any>(
116116
} = useReference<RecordType>({
117117
id: currentValue,
118118
reference,
119-
// @ts-ignore the types of the queryOptions for the getMAny and getList are not compatible
120119
options: {
120+
// @ts-ignore the types of the queryOptions for the getMAny and getList are not compatible
121121
enabled: currentValue != null && currentValue !== '',
122122
meta,
123123
...otherQueryOptions,

packages/ra-core/src/dataProvider/useGetList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export const useGetList = <
176176
}
177177
: result,
178178
[result]
179-
) as UseQueryResult<RecordType[], Error> & {
179+
) as unknown as UseQueryResult<RecordType[], Error> & {
180180
total?: number;
181181
pageInfo?: {
182182
hasNextPage?: boolean;

packages/ra-core/src/dataProvider/useGetManyReference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const useGetManyReference = <
155155
}
156156
: result,
157157
[result]
158-
) as UseQueryResult<RecordType[], ErrorType> & {
158+
) as unknown as UseQueryResult<RecordType[], ErrorType> & {
159159
total?: number;
160160
pageInfo?: {
161161
hasNextPage?: boolean;

0 commit comments

Comments
 (0)