File tree 2 files changed +28
-5
lines changed
packages/ra-ui-materialui/src/list
2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -207,4 +207,26 @@ describe('<List />', () => {
207
207
) . toHaveLength ( 1 ) ;
208
208
} ) ;
209
209
} ) ;
210
+
211
+ it ( 'should render a list page with an error message when there is an error' , async ( ) => {
212
+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
213
+ const Datagrid = ( ) => < div > datagrid</ div > ;
214
+ const dataProvider = {
215
+ getList : jest . fn ( ( ) =>
216
+ Promise . reject ( { error : { key : 'error.unknown' } } )
217
+ ) ,
218
+ } as any ;
219
+ render (
220
+ < CoreAdminContext dataProvider = { dataProvider } >
221
+ < ThemeProvider theme = { theme } >
222
+ < List resource = "posts" >
223
+ < Datagrid />
224
+ </ List >
225
+ </ ThemeProvider >
226
+ </ CoreAdminContext >
227
+ ) ;
228
+ await waitFor ( ( ) => {
229
+ expect ( screen . getByText ( 'ra.page.error' ) ) ;
230
+ } ) ;
231
+ } ) ;
210
232
} ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { ListToolbar } from './ListToolbar';
12
12
import { Pagination as DefaultPagination } from './pagination' ;
13
13
import { ListActions as DefaultActions } from './ListActions' ;
14
14
import { Empty } from './Empty' ;
15
+ import { Error } from '../layout' ;
15
16
16
17
const defaultActions = < DefaultActions /> ;
17
18
const defaultPagination = < DefaultPagination /> ;
@@ -50,10 +51,6 @@ export const ListView = <RecordType extends RaRecord = any>(
50
51
return null ;
51
52
}
52
53
53
- if ( error ) {
54
- return null ;
55
- }
56
-
57
54
const renderList = ( ) => (
58
55
< div className = { ListClasses . main } >
59
56
{ ( filters || actions ) && (
@@ -70,7 +67,11 @@ export const ListView = <RecordType extends RaRecord = any>(
70
67
} )
71
68
: children }
72
69
</ Content >
73
- { pagination !== false && pagination }
70
+ { error ? (
71
+ < Error error = { error } resetErrorBoundary = { null } />
72
+ ) : (
73
+ pagination !== false && pagination
74
+ ) }
74
75
</ div >
75
76
) ;
76
77
You can’t perform that action at this time.
0 commit comments