File tree Expand file tree Collapse file tree 1 file changed +44
-1
lines changed
packages/ra-ui-materialui/src/list Expand file tree Collapse file tree 1 file changed +44
-1
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react' ;
2- import { Admin , AutocompleteInput } from 'react-admin' ;
2+ import { Admin , AutocompleteInput , CardContentInner } from 'react-admin' ;
33import {
44 CustomRoutes ,
55 Resource ,
66 useListContext ,
77 TestMemoryRouter ,
88 DataProvider ,
9+ GetListParams ,
910} from 'ra-core' ;
1011import fakeRestDataProvider from 'ra-data-fakerest' ;
1112import {
@@ -229,6 +230,48 @@ export const Filters = () => (
229230 </ TestMemoryRouter >
230231) ;
231232
233+ export const ConditionalDataFetching = ( ) => (
234+ < TestMemoryRouter initialEntries = { [ '/books' ] } >
235+ < Admin dataProvider = { defaultDataProvider } >
236+ < Resource
237+ name = "books"
238+ list = { ( ) => (
239+ < List
240+ filters = { [ < SearchInput source = "q" alwaysOn /> ] }
241+ empty = { false }
242+ queryOptions = { {
243+ enabled : query => {
244+ const params = query
245+ . queryKey [ 2 ] as GetListParams ;
246+ return (
247+ params . filter . q != null &&
248+ params . filter . q !== ''
249+ ) ;
250+ } ,
251+ } }
252+ >
253+ < ConditionalDataFetchingView />
254+ </ List >
255+ ) }
256+ />
257+ </ Admin >
258+ </ TestMemoryRouter >
259+ ) ;
260+
261+ const ConditionalDataFetchingView = ( ) => {
262+ const context = useListContext ( ) ;
263+
264+ if ( context . filterValues . q == null || context . filterValues . q === '' ) {
265+ return (
266+ < CardContentInner >
267+ Type a search term to fetch data
268+ </ CardContentInner >
269+ ) ;
270+ }
271+
272+ return < BookList /> ;
273+ } ;
274+
232275export const Filter = ( ) => (
233276 < TestMemoryRouter initialEntries = { [ '/books' ] } >
234277 < Admin dataProvider = { defaultDataProvider } >
You can’t perform that action at this time.
0 commit comments