@@ -5,7 +5,9 @@ import { QueryClient } from 'react-query';
5
5
import { Resource , Form , testDataProvider , useRedirect } from 'ra-core' ;
6
6
import polyglotI18nProvider from 'ra-i18n-polyglot' ;
7
7
import englishMessages from 'ra-language-english' ;
8
- import { Stack , Divider , Typography } from '@mui/material' ;
8
+ import fakeRestDataProvider from 'ra-data-fakerest' ;
9
+ import { Stack , Divider , Typography , Button } from '@mui/material' ;
10
+ import { MemoryRouter } from 'react-router-dom' ;
9
11
10
12
import { Edit } from '../detail' ;
11
13
import { SimpleForm } from '../form' ;
@@ -507,3 +509,85 @@ export const SelfReference = ({ dataProvider = dataProviderWithAuthors }) => (
507
509
< Resource name = "books" edit = { BookEditWithSelfReference } />
508
510
</ Admin >
509
511
) ;
512
+
513
+ const BookEditQueryOptions = ( ) => {
514
+ const [ enabled , setEnabled ] = React . useState ( false ) ;
515
+ return (
516
+ < Edit mutationMode = "pessimistic" >
517
+ < Button onClick = { ( ) => setEnabled ( ! enabled ) } >
518
+ Toggle queryOptions
519
+ </ Button >
520
+ < SimpleForm >
521
+ < TextInput source = "title" />
522
+ < ReferenceInput
523
+ reference = "authors"
524
+ source = "author"
525
+ queryOptions = { { enabled } }
526
+ />
527
+ </ SimpleForm >
528
+ </ Edit >
529
+ ) ;
530
+ } ;
531
+
532
+ export const QueryOptions = ( ) => (
533
+ < MemoryRouter initialEntries = { [ '/books/1' ] } >
534
+ < Admin
535
+ dataProvider = { fakeRestDataProvider (
536
+ {
537
+ books : [
538
+ {
539
+ id : 1 ,
540
+ title : 'War and Peace' ,
541
+ author : 1 ,
542
+ summary :
543
+ "War and Peace broadly focuses on Napoleon's invasion of Russia, and the impact it had on Tsarist society. The book explores themes such as revolution, revolution and empire, the growth and decline of various states and the impact it had on their economies, culture, and society." ,
544
+ year : 1869 ,
545
+ } ,
546
+ ] ,
547
+ authors : [
548
+ {
549
+ id : 1 ,
550
+ first_name : 'Leo' ,
551
+ last_name : 'Tolstoy' ,
552
+ language : 'Russian' ,
553
+ } ,
554
+ {
555
+ id : 2 ,
556
+ first_name : 'Victor' ,
557
+ last_name : 'Hugo' ,
558
+ language : 'French' ,
559
+ } ,
560
+ {
561
+ id : 3 ,
562
+ first_name : 'William' ,
563
+ last_name : 'Shakespeare' ,
564
+ language : 'English' ,
565
+ } ,
566
+ {
567
+ id : 4 ,
568
+ first_name : 'Charles' ,
569
+ last_name : 'Baudelaire' ,
570
+ language : 'French' ,
571
+ } ,
572
+ {
573
+ id : 5 ,
574
+ first_name : 'Marcel' ,
575
+ last_name : 'Proust' ,
576
+ language : 'French' ,
577
+ } ,
578
+ ] ,
579
+ } ,
580
+ process . env . NODE_ENV === 'development'
581
+ ) }
582
+ >
583
+ < Resource
584
+ name = "authors"
585
+ recordRepresentation = { record =>
586
+ `${ record . first_name } ${ record . last_name } `
587
+ }
588
+ list = { AuthorList }
589
+ />
590
+ < Resource name = "books" edit = { BookEditQueryOptions } />
591
+ </ Admin >
592
+ </ MemoryRouter >
593
+ ) ;
0 commit comments