Skip to content

Commit

Permalink
Merge pull request #5165 from marmelab/allows-list-empty-page-disabling
Browse files Browse the repository at this point in the history
Allows List Empty Page Disabling
  • Loading branch information
fzaninotto committed Aug 19, 2020
2 parents 4abaeeb + e4842ce commit 3eb2e3d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
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
? 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

0 comments on commit 3eb2e3d

Please sign in to comment.