Skip to content

Commit

Permalink
Merge pull request #8319 from marmelab/fix-list-error-display
Browse files Browse the repository at this point in the history
Fix `List` page display on dataProvider error
  • Loading branch information
fzaninotto authored Oct 28, 2022
2 parents 193994a + 7cccc4a commit 221dcbd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
22 changes: 22 additions & 0 deletions packages/ra-ui-materialui/src/list/List.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,26 @@ describe('<List />', () => {
).toHaveLength(1);
});
});

it('should render a list page with an error message when there is an error', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {});
const Datagrid = () => <div>datagrid</div>;
const dataProvider = {
getList: jest.fn(() =>
Promise.reject({ error: { key: 'error.unknown' } })
),
} as any;
render(
<CoreAdminContext dataProvider={dataProvider}>
<ThemeProvider theme={theme}>
<List resource="posts">
<Datagrid />
</List>
</ThemeProvider>
</CoreAdminContext>
);
await waitFor(() => {
expect(screen.getByText('ra.page.error'));
});
});
});
11 changes: 6 additions & 5 deletions packages/ra-ui-materialui/src/list/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ListToolbar } from './ListToolbar';
import { Pagination as DefaultPagination } from './pagination';
import { ListActions as DefaultActions } from './ListActions';
import { Empty } from './Empty';
import { Error } from '../layout';

const defaultActions = <DefaultActions />;
const defaultPagination = <DefaultPagination />;
Expand Down Expand Up @@ -50,10 +51,6 @@ export const ListView = <RecordType extends RaRecord = any>(
return null;
}

if (error) {
return null;
}

const renderList = () => (
<div className={ListClasses.main}>
{(filters || actions) && (
Expand All @@ -70,7 +67,11 @@ export const ListView = <RecordType extends RaRecord = any>(
})
: children}
</Content>
{pagination !== false && pagination}
{error ? (
<Error error={error} resetErrorBoundary={null} />
) : (
pagination !== false && pagination
)}
</div>
);

Expand Down

0 comments on commit 221dcbd

Please sign in to comment.