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

Add ability to disable the Empty Page in List #5165

Merged
merged 3 commits into from
Aug 19, 2020
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
12 changes: 12 additions & 0 deletions docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,18 @@ The `empty` component can call the `useListContext()` hook to receive the same p
- `total`,
- `version`,

You can also set the `empty` props value to `false` to bypass the empty page display and render an empty list instead.

```
import { List } from 'react-admin';

const ProductList = props => (
<List empty={false} {...props}>
...
</List>
);
```

### Component

By default, the List view renders the main content area inside a material-ui `<Card>` element. The actual layout of the list depends on the child component you're using (`<Datagrid>`, `<SimpleList>`, or a custom layout component).
Expand Down
20 changes: 20 additions & 0 deletions packages/ra-ui-materialui/src/list/List.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ describe('<List />', () => {
});
});

it('should not render an invite when the list is empty with an empty prop set to false', async () => {
const Dummy = () => <div />;
const dataProvider = {
getList: jest.fn(() => Promise.resolve({ data: [], total: 0 })),
};
const { queryAllByText } = renderWithRedux(
<ThemeProvider theme={theme}>
<DataProviderContext.Provider value={dataProvider}>
<List {...defaultProps} empty={false}>
<Dummy />
</List>
</DataProviderContext.Provider>
</ThemeProvider>,
defaultStateForList
);
await wait(() => {
expect(queryAllByText('resources.posts.empty')).toHaveLength(0);
});
});

it('should not render an invite when a filter is active', async () => {
const Dummy = () => <div />;
const dataProvider = {
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/list/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const ListView: FC<ListViewProps> = props => {
{...sanitizeRestProps(rest)}
>
<Title title={title} defaultTitle={defaultTitle} />
{shouldRenderEmptyPage
{shouldRenderEmptyPage && empty !== false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not update the shouldRenderEmptyPage method to use the empty prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of Typescript ;)

? cloneElement(empty, listContext)
: renderList()}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ListProps extends ResourceComponentProps {
classes?: any;
className?: string;
component?: FC<{ className?: string }>;
empty?: ReactElement;
empty?: ReactElement | false;
exporter?: Exporter | false;
filter?: any;
filterDefaultValues?: any;
Expand Down