Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix List page display on dataProvider error #8319

Merged
merged 7 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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