@@ -6,33 +6,34 @@ import {
6
6
ResourceContext ,
7
7
testDataProvider ,
8
8
} from 'ra-core' ;
9
+ import englishMessages from 'ra-language-english' ;
10
+ import polyglotI18nProvider from 'ra-i18n-polyglot' ;
11
+ import { MemoryRouter } from 'react-router' ;
12
+ import { seed , address , internet , name } from 'faker/locale/en_GB' ;
13
+ import { QueryClient } from 'react-query' ;
14
+
9
15
import {
10
16
AdminUI ,
17
+ AdminContext ,
11
18
Edit ,
12
19
EditButton ,
13
20
ListGuesser ,
14
- PrevNextButtons ,
15
21
Show ,
16
22
ShowButton ,
17
23
SimpleForm ,
18
24
SimpleShowLayout ,
19
25
TextField ,
20
26
TextInput ,
21
27
TopToolbar ,
22
- } from 'react-admin' ;
23
- import englishMessages from 'ra-language-english' ;
24
- import polyglotI18nProvider from 'ra-i18n-polyglot' ;
25
- import { MemoryRouter } from 'react-router' ;
26
- import { seed , address , internet , name } from 'faker/locale/en_GB' ;
27
- import { QueryClient } from 'react-query' ;
28
-
29
- import { AdminContext } from '../AdminContext' ;
28
+ } from '../' ;
29
+ import { PrevNextButtons } from './PrevNextButtons' ;
30
30
31
31
export default { title : 'ra-ui-materialui/button/PrevNextButtons' } ;
32
32
33
33
const i18nProvider = polyglotI18nProvider ( ( ) => englishMessages , 'en' ) ;
34
34
35
35
seed ( 123 ) ; // we want consistent results
36
+
36
37
const data = {
37
38
customers : Array . from ( Array ( 900 ) . keys ( ) ) . map ( id => {
38
39
const first_name = name . firstName ( ) ;
@@ -52,35 +53,30 @@ const data = {
52
53
const dataProvider = fakeRestDataProvider ( data ) ;
53
54
54
55
const MyTopToolbar = ( { children } ) => (
55
- < TopToolbar
56
- sx = { {
57
- justifyContent : 'space-between' ,
58
- } }
59
- >
60
- { children }
61
- </ TopToolbar >
56
+ < TopToolbar sx = { { justifyContent : 'space-between' } } > { children } </ TopToolbar >
62
57
) ;
63
58
64
- const defaultFields = [
65
- < TextField source = "id" key = "id" /> ,
66
- < TextField source = "first_name" key = "first_name" /> ,
67
- < TextField source = "last_name" key = "last_name" /> ,
68
- < TextField source = "email" key = "email" /> ,
69
- < TextField source = "city" key = "city" /> ,
70
- ] ;
71
-
72
- const defaultInputs = [
73
- < TextInput source = "first_name" key = "first_name" /> ,
74
- < TextInput source = "last_name" key = "last_name" /> ,
75
- < TextInput source = "email" key = "email" /> ,
76
- < TextInput source = "city" key = "city" /> ,
77
- ] ;
78
-
79
- const DefaultSimpleForm = ( ) => (
80
- < SimpleForm warnWhenUnsavedChanges > { defaultInputs } </ SimpleForm >
59
+ const CustomerEdit = ( { actions } : any ) => (
60
+ < Edit redirect = { false } actions = { actions } >
61
+ < SimpleForm warnWhenUnsavedChanges >
62
+ < TextInput source = "first_name" key = "first_name" />
63
+ < TextInput source = "last_name" key = "last_name" />
64
+ < TextInput source = "email" key = "email" />
65
+ < TextInput source = "city" key = "city" />
66
+ </ SimpleForm >
67
+ </ Edit >
81
68
) ;
82
- const DefaultSimpleShowLayout = ( ) => (
83
- < SimpleShowLayout > { defaultFields } </ SimpleShowLayout >
69
+
70
+ const CustomerShow = ( { actions } : any ) => (
71
+ < Show actions = { actions } >
72
+ < SimpleShowLayout >
73
+ < TextField source = "id" key = "id" />
74
+ < TextField source = "first_name" key = "first_name" />
75
+ < TextField source = "last_name" key = "last_name" />
76
+ < TextField source = "email" key = "email" />
77
+ < TextField source = "city" key = "city" />
78
+ </ SimpleShowLayout >
79
+ </ Show >
84
80
) ;
85
81
86
82
export const Basic = ( ) => (
@@ -91,28 +87,24 @@ export const Basic = () => (
91
87
name = "customers"
92
88
list = { < ListGuesser /> }
93
89
edit = {
94
- < Edit
95
- redirect = { false }
90
+ < CustomerEdit
96
91
actions = {
97
92
< MyTopToolbar >
98
93
< PrevNextButtons />
99
94
< ShowButton />
100
95
</ MyTopToolbar >
101
96
}
102
- >
103
- < DefaultSimpleForm />
104
- </ Edit >
97
+ />
105
98
}
106
99
show = {
107
- < Show
100
+ < CustomerShow
108
101
actions = {
109
102
< MyTopToolbar >
110
103
< PrevNextButtons linkType = "show" />
104
+ < EditButton />
111
105
</ MyTopToolbar >
112
106
}
113
- >
114
- < DefaultSimpleShowLayout />
115
- </ Show >
107
+ />
116
108
}
117
109
/>
118
110
</ AdminUI >
@@ -128,20 +120,17 @@ export const WithStoreKey = () => (
128
120
name = "customers"
129
121
list = { < ListGuesser storeKey = "withStoreKey" /> }
130
122
edit = {
131
- < Edit
132
- redirect = { false }
123
+ < CustomerEdit
133
124
actions = {
134
125
< MyTopToolbar >
135
126
< PrevNextButtons storeKey = "withStoreKey" />
136
127
< ShowButton />
137
128
</ MyTopToolbar >
138
129
}
139
- >
140
- < DefaultSimpleForm />
141
- </ Edit >
130
+ />
142
131
}
143
132
show = {
144
- < Show
133
+ < CustomerShow
145
134
actions = {
146
135
< MyTopToolbar >
147
136
< PrevNextButtons
@@ -151,9 +140,7 @@ export const WithStoreKey = () => (
151
140
< EditButton />
152
141
</ MyTopToolbar >
153
142
}
154
- >
155
- < DefaultSimpleShowLayout />
156
- </ Show >
143
+ />
157
144
}
158
145
/>
159
146
</ AdminUI >
@@ -174,8 +161,7 @@ export const WithFilter = () => (
174
161
/>
175
162
}
176
163
edit = {
177
- < Edit
178
- redirect = { false }
164
+ < CustomerEdit
179
165
actions = {
180
166
< MyTopToolbar >
181
167
< PrevNextButtons
@@ -188,12 +174,10 @@ export const WithFilter = () => (
188
174
< ShowButton />
189
175
</ MyTopToolbar >
190
176
}
191
- >
192
- < DefaultSimpleForm />
193
- </ Edit >
177
+ />
194
178
}
195
179
show = {
196
- < Show
180
+ < CustomerShow
197
181
actions = {
198
182
< MyTopToolbar >
199
183
< PrevNextButtons
@@ -207,9 +191,7 @@ export const WithFilter = () => (
207
191
< EditButton />
208
192
</ MyTopToolbar >
209
193
}
210
- >
211
- < DefaultSimpleShowLayout />
212
- </ Show >
194
+ />
213
195
}
214
196
/>
215
197
</ AdminUI >
@@ -235,29 +217,24 @@ export const WithQueryFilter = () => (
235
217
/>
236
218
}
237
219
edit = {
238
- < Edit
239
- redirect = { false }
220
+ < CustomerEdit
240
221
actions = {
241
222
< MyTopToolbar >
242
223
< PrevNextButtons />
243
224
< ShowButton />
244
225
</ MyTopToolbar >
245
226
}
246
- >
247
- < DefaultSimpleForm />
248
- </ Edit >
227
+ />
249
228
}
250
229
show = {
251
- < Show
230
+ < CustomerShow
252
231
actions = {
253
232
< MyTopToolbar >
254
233
< PrevNextButtons linkType = "show" />
255
234
< EditButton />
256
235
</ MyTopToolbar >
257
236
}
258
- >
259
- < DefaultSimpleShowLayout />
260
- </ Show >
237
+ />
261
238
}
262
239
/>
263
240
</ AdminUI >
@@ -276,32 +253,27 @@ export const WithLimit = ({ customDataProvider = dataProvider }) => (
276
253
name = "customers"
277
254
list = { < ListGuesser /> }
278
255
edit = {
279
- < Edit
280
- redirect = { false }
256
+ < CustomerEdit
281
257
actions = {
282
258
< MyTopToolbar >
283
259
< PrevNextButtons limit = { 500 } />
284
260
< ShowButton />
285
261
</ MyTopToolbar >
286
262
}
287
- >
288
- < DefaultSimpleForm />
289
- </ Edit >
263
+ />
290
264
}
291
265
show = {
292
- < Show
266
+ < CustomerShow
293
267
actions = {
294
268
< MyTopToolbar >
295
269
< PrevNextButtons
296
270
linkType = "show"
297
271
limit = { 500 }
298
272
/>
299
- < ShowButton />
273
+ < EditButton />
300
274
</ MyTopToolbar >
301
275
}
302
- >
303
- < DefaultSimpleShowLayout />
304
- </ Show >
276
+ />
305
277
}
306
278
/>
307
279
</ AdminUI >
@@ -313,19 +285,10 @@ export const WithStyle = () => (
313
285
< AdminContext dataProvider = { dataProvider } >
314
286
< ResourceContext . Provider value = "customers" >
315
287
< RecordContextProvider value = { data . customers [ 0 ] } >
316
- < PrevNextButtons
317
- sx = { {
318
- color : 'blue' ,
319
- } }
320
- />
288
+ < PrevNextButtons sx = { { color : 'blue' } } />
321
289
< PrevNextButtons
322
290
linkType = "show"
323
- sx = { {
324
- '& .RaPrevNextButton-list' : {
325
- marginBottom : '20px' ,
326
- color : 'red' ,
327
- } ,
328
- } }
291
+ sx = { { marginBottom : '20px' , color : 'red' } }
329
292
/>
330
293
</ RecordContextProvider >
331
294
</ ResourceContext . Provider >
0 commit comments