Skip to content

Commit cb4ab53

Browse files
committed
remove import from react-admin
1 parent 9635203 commit cb4ab53

File tree

1 file changed

+154
-132
lines changed

1 file changed

+154
-132
lines changed

packages/ra-ui-materialui/src/input/SelectInput.stories.tsx

Lines changed: 154 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import {
1818
import polyglotI18nProvider from 'ra-i18n-polyglot';
1919
import englishMessages from 'ra-language-english';
2020
import * as React from 'react';
21-
import { Admin, AdminContext } from 'react-admin';
2221

22+
import { AdminContext } from '../AdminContext';
23+
24+
import { AdminUI } from '../AdminUI';
2325
import { SaveButton } from '../button/SaveButton';
2426
import { Edit, Create as RaCreate } from '../detail';
2527
import { SimpleForm } from '../form';
@@ -459,13 +461,49 @@ export const FetchChoices = () => {
459461
};
460462
return (
461463
<TestMemoryRouter initialEntries={['/books/1']}>
462-
<Admin dataProvider={dataProviderWithAuthors}>
463-
<Resource
464-
name="authors"
465-
recordRepresentation={record =>
466-
`${record.first_name} ${record.last_name}`
467-
}
468-
/>
464+
<AdminContext dataProvider={dataProviderWithAuthors}>
465+
<AdminUI>
466+
{' '}
467+
<Resource
468+
name="authors"
469+
recordRepresentation={record =>
470+
`${record.first_name} ${record.last_name}`
471+
}
472+
/>
473+
<Resource
474+
name="books"
475+
edit={() => (
476+
<Edit
477+
mutationMode="pessimistic"
478+
mutationOptions={{
479+
onSuccess: data => {
480+
console.log(data);
481+
},
482+
}}
483+
>
484+
<SimpleForm>
485+
<BookAuthorsInput />
486+
<FormInspector name="author" />
487+
</SimpleForm>
488+
</Edit>
489+
)}
490+
/>
491+
</AdminUI>
492+
</AdminContext>
493+
</TestMemoryRouter>
494+
);
495+
};
496+
497+
export const InsideReferenceInput = () => (
498+
<TestMemoryRouter initialEntries={['/books/1']}>
499+
<AdminContext dataProvider={dataProviderWithAuthors}>
500+
<Resource
501+
name="authors"
502+
recordRepresentation={record =>
503+
`${record.first_name} ${record.last_name}`
504+
}
505+
/>
506+
<AdminUI>
469507
<Resource
470508
name="books"
471509
edit={() => (
@@ -478,55 +516,27 @@ export const FetchChoices = () => {
478516
}}
479517
>
480518
<SimpleForm>
481-
<BookAuthorsInput />
519+
<ReferenceInput
520+
reference="authors"
521+
source="author"
522+
>
523+
<SelectInput />
524+
</ReferenceInput>
482525
<FormInspector name="author" />
483526
</SimpleForm>
484527
</Edit>
485528
)}
486529
/>
487-
</Admin>
488-
</TestMemoryRouter>
489-
);
490-
};
491-
492-
export const InsideReferenceInput = () => (
493-
<TestMemoryRouter initialEntries={['/books/1']}>
494-
<Admin dataProvider={dataProviderWithAuthors}>
495-
<Resource
496-
name="authors"
497-
recordRepresentation={record =>
498-
`${record.first_name} ${record.last_name}`
499-
}
500-
/>
501-
<Resource
502-
name="books"
503-
edit={() => (
504-
<Edit
505-
mutationMode="pessimistic"
506-
mutationOptions={{
507-
onSuccess: data => {
508-
console.log(data);
509-
},
510-
}}
511-
>
512-
<SimpleForm>
513-
<ReferenceInput reference="authors" source="author">
514-
<SelectInput />
515-
</ReferenceInput>
516-
<FormInspector name="author" />
517-
</SimpleForm>
518-
</Edit>
519-
)}
520-
/>
521-
</Admin>
530+
</AdminUI>
531+
</AdminContext>
522532
</TestMemoryRouter>
523533
);
524534

525535
export const InsideReferenceInputDefaultValue = ({
526536
onSuccess = console.log,
527537
}) => (
528538
<TestMemoryRouter initialEntries={['/books/1']}>
529-
<Admin
539+
<AdminContext
530540
dataProvider={{
531541
...dataProviderWithAuthors,
532542
getOne: () =>
@@ -543,36 +553,41 @@ export const InsideReferenceInputDefaultValue = ({
543553
}),
544554
}}
545555
>
546-
<Resource
547-
name="authors"
548-
recordRepresentation={record =>
549-
`${record.first_name} ${record.last_name}`
550-
}
551-
/>
552-
<Resource
553-
name="books"
554-
edit={() => (
555-
<Edit
556-
mutationMode="pessimistic"
557-
mutationOptions={{ onSuccess }}
558-
>
559-
<SimpleForm>
560-
<TextInput source="title" />
561-
<ReferenceInput reference="authors" source="author">
562-
<SelectInput />
563-
</ReferenceInput>
564-
<FormInspector name="author" />
565-
</SimpleForm>
566-
</Edit>
567-
)}
568-
/>
569-
</Admin>
556+
<AdminUI>
557+
<Resource
558+
name="authors"
559+
recordRepresentation={record =>
560+
`${record.first_name} ${record.last_name}`
561+
}
562+
/>
563+
<Resource
564+
name="books"
565+
edit={() => (
566+
<Edit
567+
mutationMode="pessimistic"
568+
mutationOptions={{ onSuccess }}
569+
>
570+
<SimpleForm>
571+
<TextInput source="title" />
572+
<ReferenceInput
573+
reference="authors"
574+
source="author"
575+
>
576+
<SelectInput />
577+
</ReferenceInput>
578+
<FormInspector name="author" />
579+
</SimpleForm>
580+
</Edit>
581+
)}
582+
/>
583+
</AdminUI>
584+
</AdminContext>
570585
</TestMemoryRouter>
571586
);
572587

573588
export const InsideReferenceInputWithError = () => (
574589
<TestMemoryRouter initialEntries={['/books/1']}>
575-
<Admin
590+
<AdminContext
576591
dataProvider={{
577592
...dataProviderWithAuthors,
578593
getList: () =>
@@ -581,33 +596,38 @@ export const InsideReferenceInputWithError = () => (
581596
),
582597
}}
583598
>
584-
<Resource
585-
name="authors"
586-
recordRepresentation={record =>
587-
`${record.first_name} ${record.last_name}`
588-
}
589-
/>
590-
<Resource
591-
name="books"
592-
edit={() => (
593-
<Edit
594-
mutationMode="pessimistic"
595-
mutationOptions={{
596-
onSuccess: data => {
597-
console.log(data);
598-
},
599-
}}
600-
>
601-
<SimpleForm>
602-
<ReferenceInput reference="authors" source="author">
603-
<SelectInput />
604-
</ReferenceInput>
605-
<FormInspector name="author" />
606-
</SimpleForm>
607-
</Edit>
608-
)}
609-
/>
610-
</Admin>
599+
<AdminUI>
600+
<Resource
601+
name="authors"
602+
recordRepresentation={record =>
603+
`${record.first_name} ${record.last_name}`
604+
}
605+
/>
606+
<Resource
607+
name="books"
608+
edit={() => (
609+
<Edit
610+
mutationMode="pessimistic"
611+
mutationOptions={{
612+
onSuccess: data => {
613+
console.log(data);
614+
},
615+
}}
616+
>
617+
<SimpleForm>
618+
<ReferenceInput
619+
reference="authors"
620+
source="author"
621+
>
622+
<SelectInput />
623+
</ReferenceInput>
624+
<FormInspector name="author" />
625+
</SimpleForm>
626+
</Edit>
627+
)}
628+
/>
629+
</AdminUI>
630+
</AdminContext>
611631
</TestMemoryRouter>
612632
);
613633

@@ -665,41 +685,43 @@ export const InsideReferenceInputWithCreationSupport = () => {
665685
};
666686
return (
667687
<TestMemoryRouter initialEntries={['/books/1']}>
668-
<Admin dataProvider={dataProviderWithAuthors}>
669-
<Resource
670-
name="authors"
671-
recordRepresentation={record =>
672-
`${record.first_name} ${record.last_name}`
673-
}
674-
/>
675-
<Resource
676-
name="books"
677-
edit={() => (
678-
<Edit
679-
mutationMode="pessimistic"
680-
mutationOptions={{
681-
onSuccess: data => {
682-
console.log(data);
683-
},
684-
}}
685-
>
686-
<SimpleForm>
687-
<ReferenceInput
688-
reference="authors"
689-
source="author"
690-
>
691-
<SelectInput
692-
create={<CreateAuthor />}
693-
createLabel="Create a new Author"
694-
optionText={optionRenderer}
695-
/>
696-
</ReferenceInput>
697-
<FormInspector name="author" />
698-
</SimpleForm>
699-
</Edit>
700-
)}
701-
/>
702-
</Admin>
688+
<AdminContext dataProvider={dataProviderWithAuthors}>
689+
<AdminUI>
690+
<Resource
691+
name="authors"
692+
recordRepresentation={record =>
693+
`${record.first_name} ${record.last_name}`
694+
}
695+
/>
696+
<Resource
697+
name="books"
698+
edit={() => (
699+
<Edit
700+
mutationMode="pessimistic"
701+
mutationOptions={{
702+
onSuccess: data => {
703+
console.log(data);
704+
},
705+
}}
706+
>
707+
<SimpleForm>
708+
<ReferenceInput
709+
reference="authors"
710+
source="author"
711+
>
712+
<SelectInput
713+
create={<CreateAuthor />}
714+
createLabel="Create a new Author"
715+
optionText={optionRenderer}
716+
/>
717+
</ReferenceInput>
718+
<FormInspector name="author" />
719+
</SimpleForm>
720+
</Edit>
721+
)}
722+
/>
723+
</AdminUI>
724+
</AdminContext>
703725
</TestMemoryRouter>
704726
);
705727
};

0 commit comments

Comments
 (0)