|
1 | | -import * as React from 'react'; |
2 | | -import { Admin } from 'react-admin'; |
| 1 | +import { InputAdornment } from '@mui/material'; |
3 | 2 | import { |
4 | | - FormDataConsumer, |
5 | 3 | required, |
6 | 4 | Resource, |
7 | 5 | testI18nProvider, |
8 | 6 | TestMemoryRouter, |
9 | 7 | } from 'ra-core'; |
10 | | -import { InputAdornment } from '@mui/material'; |
11 | | -import fakeRestProvider from 'ra-data-fakerest'; |
| 8 | +import * as React from 'react'; |
| 9 | +import { Admin } from 'react-admin'; |
12 | 10 |
|
13 | | -import { Edit, Create } from '../../detail'; |
| 11 | +import { Create, Edit } from '../../detail'; |
| 12 | +import { ReferenceField, TextField, TranslatableFields } from '../../field'; |
14 | 13 | import { SimpleForm, TabbedForm } from '../../form'; |
15 | | -import { ArrayInput } from './ArrayInput'; |
16 | | -import { SimpleFormIterator } from './SimpleFormIterator'; |
17 | | -import { TextInput } from '../TextInput'; |
18 | | -import { SelectInput } from '../SelectInput'; |
| 14 | +import { Labeled } from '../../Labeled'; |
| 15 | +import { AutocompleteInput } from '../AutocompleteInput'; |
19 | 16 | import { DateInput } from '../DateInput'; |
20 | 17 | import { NumberInput } from '../NumberInput'; |
21 | | -import { AutocompleteInput } from '../AutocompleteInput'; |
| 18 | +import { TextInput } from '../TextInput'; |
22 | 19 | import { TranslatableInputs } from '../TranslatableInputs'; |
23 | | -import { ReferenceField, TextField, TranslatableFields } from '../../field'; |
24 | | -import { Labeled } from '../../Labeled'; |
25 | | -import { List, Datagrid } from '../../list'; |
| 20 | +import { ArrayInput } from './ArrayInput'; |
| 21 | +import { SimpleFormIterator } from './SimpleFormIterator'; |
26 | 22 |
|
27 | 23 | export default { title: 'ra-ui-materialui/input/ArrayInput' }; |
28 | 24 |
|
@@ -828,109 +824,3 @@ export const WithReferenceField = () => ( |
828 | 824 | </Admin> |
829 | 825 | </TestMemoryRouter> |
830 | 826 | ); |
831 | | - |
832 | | -const shouldUnregisterData = { |
833 | | - books: [ |
834 | | - { |
835 | | - id: 1, |
836 | | - title: 'War and Peace', |
837 | | - authors: [ |
838 | | - { |
839 | | - name: 'Alexander Pushkin', |
840 | | - role: 'co_writer', |
841 | | - }, |
842 | | - { |
843 | | - // name: 'Leo Tolstoy', |
844 | | - role: 'head_writer', |
845 | | - }, |
846 | | - ], |
847 | | - }, |
848 | | - { |
849 | | - id: 2, |
850 | | - title: 'Anna Karenina', |
851 | | - authors: [ |
852 | | - { |
853 | | - // name: 'Leo Tolstoy', |
854 | | - role: 'head_writer', |
855 | | - }, |
856 | | - { |
857 | | - name: 'Alexander Pushkin', |
858 | | - role: 'co_writer', |
859 | | - }, |
860 | | - ], |
861 | | - }, |
862 | | - ], |
863 | | -}; |
864 | | - |
865 | | -const WithShouldUnregisterBookList = () => { |
866 | | - return ( |
867 | | - <List> |
868 | | - <Datagrid> |
869 | | - <TextField source="id" /> |
870 | | - <TextField source="title" /> |
871 | | - </Datagrid> |
872 | | - </List> |
873 | | - ); |
874 | | -}; |
875 | | -const WithShouldUnregisterBookEdit = () => { |
876 | | - return ( |
877 | | - <Edit |
878 | | - mutationMode="pessimistic" |
879 | | - mutationOptions={{ |
880 | | - onSuccess: data => { |
881 | | - console.log(data); |
882 | | - }, |
883 | | - }} |
884 | | - > |
885 | | - <SimpleForm> |
886 | | - <TextInput source="title" /> |
887 | | - <ArrayInput source="authors"> |
888 | | - <SimpleFormIterator> |
889 | | - <FormDataConsumer> |
890 | | - {({ scopedFormData }) => { |
891 | | - return ( |
892 | | - <> |
893 | | - <SelectInput |
894 | | - source="role" |
895 | | - choices={[ |
896 | | - 'co_writer', |
897 | | - 'head_writer', |
898 | | - ]} |
899 | | - /> |
900 | | - {scopedFormData?.role === |
901 | | - 'co_writer' ? ( |
902 | | - <TextInput |
903 | | - source="name" |
904 | | - shouldUnregister |
905 | | - /> |
906 | | - ) : null} |
907 | | - </> |
908 | | - ); |
909 | | - }} |
910 | | - </FormDataConsumer> |
911 | | - </SimpleFormIterator> |
912 | | - </ArrayInput> |
913 | | - </SimpleForm> |
914 | | - </Edit> |
915 | | - ); |
916 | | -}; |
917 | | - |
918 | | -export const WithShouldUnregister = () => ( |
919 | | - <React.StrictMode> |
920 | | - <TestMemoryRouter initialEntries={['/books/1']}> |
921 | | - <Admin |
922 | | - dataProvider={fakeRestProvider( |
923 | | - JSON.parse(JSON.stringify(shouldUnregisterData)), |
924 | | - true, |
925 | | - 300 |
926 | | - )} |
927 | | - > |
928 | | - <Resource |
929 | | - name="books" |
930 | | - list={WithShouldUnregisterBookList} |
931 | | - edit={WithShouldUnregisterBookEdit} |
932 | | - /> |
933 | | - </Admin> |
934 | | - </TestMemoryRouter> |
935 | | - </React.StrictMode> |
936 | | -); |
0 commit comments