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 <ListView> should show custom empty component with partial pagination #8945

Merged
merged 5 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 27 additions & 0 deletions packages/ra-ui-materialui/src/list/List.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,33 @@ describe('<List />', () => {
});
});

it('should render custom empty component when data is empty', async () => {
const Dummy = () => null;
const CustomEmpty = () => <div>Custom Empty</div>;

const dataProvider = {
getList: jest.fn(() =>
Promise.resolve({
data: [],
pageInfo: { hasNextPage: false, hasPreviousPage: false },
})
),
} as any;
render(
<CoreAdminContext dataProvider={dataProvider}>
<ThemeProvider theme={theme}>
<List resource="posts" empty={<CustomEmpty />}>
<Dummy />
</List>
</ThemeProvider>
</CoreAdminContext>
);
await waitFor(() => {
expect(screen.queryByText('resources.posts.empty')).toBeNull();
screen.getByText('Custom Empty');
});
});

it('should not render an invite when a filter is active', async () => {
const Dummy = () => {
const { isLoading } = useListContext();
Expand Down
4 changes: 1 addition & 3 deletions packages/ra-ui-materialui/src/list/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const ListView = <RecordType extends RaRecord = any>(
defaultTitle,
data,
error,
total,
isLoading,
filterValues,
resource,
Expand Down Expand Up @@ -83,7 +82,7 @@ export const ListView = <RecordType extends RaRecord = any>(

const shouldRenderEmptyPage =
!isLoading &&
total === 0 &&
data?.length === 0 &&
yanchesky marked this conversation as resolved.
Show resolved Hide resolved
!Object.keys(filterValues).length &&
empty !== false;

Expand Down Expand Up @@ -144,7 +143,6 @@ ListView.propTypes = {
setSort: PropTypes.func,
showFilter: PropTypes.func,
title: TitlePropType,
total: PropTypes.number,
slax57 marked this conversation as resolved.
Show resolved Hide resolved
};

export interface ListViewProps {
Expand Down