Skip to content

Commit 221dcbd

Browse files
authored
Merge pull request #8319 from marmelab/fix-list-error-display
Fix `List` page display on dataProvider error
2 parents 193994a + 7cccc4a commit 221dcbd

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

packages/ra-ui-materialui/src/list/List.spec.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,26 @@ describe('<List />', () => {
207207
).toHaveLength(1);
208208
});
209209
});
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+
});
210232
});

packages/ra-ui-materialui/src/list/ListView.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ListToolbar } from './ListToolbar';
1212
import { Pagination as DefaultPagination } from './pagination';
1313
import { ListActions as DefaultActions } from './ListActions';
1414
import { Empty } from './Empty';
15+
import { Error } from '../layout';
1516

1617
const defaultActions = <DefaultActions />;
1718
const defaultPagination = <DefaultPagination />;
@@ -50,10 +51,6 @@ export const ListView = <RecordType extends RaRecord = any>(
5051
return null;
5152
}
5253

53-
if (error) {
54-
return null;
55-
}
56-
5754
const renderList = () => (
5855
<div className={ListClasses.main}>
5956
{(filters || actions) && (
@@ -70,7 +67,11 @@ export const ListView = <RecordType extends RaRecord = any>(
7067
})
7168
: children}
7269
</Content>
73-
{pagination !== false && pagination}
70+
{error ? (
71+
<Error error={error} resetErrorBoundary={null} />
72+
) : (
73+
pagination !== false && pagination
74+
)}
7475
</div>
7576
);
7677

0 commit comments

Comments
 (0)