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 change the sort, filter and selection of ArrayField #8802

Merged
merged 4 commits into from
Apr 5, 2023

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Apr 4, 2023

Problem

<ArrayField> creates a very limited ListContext that doesn't allow manipulating the list

Solution

Use useList to prepare the List context. It already does all we need.

Closes #8761

To Do

  • use useList in <ArrayField> to create a complete `ListContext``
  • add support for sort, filter, and perPage props
  • Add story
  • Add tests
  • Add documentation

Example

Leveraging perPage and <Pagination> in the <ArrayField>:

import { 
    ArrayField,
    Datagrid,
    Pagination,
    Show,
    SimpleShowLayout,
    TextField
} from 'react-admin';

const PostShow = () => (
    <Show>
        <SimpleShowLayout>
            <TextField source="title" />
            <ArrayField source="backlinks" perPage={5}>
                <Datagrid>
                    <TextField source="uuid" />
                    <TextField source="date" />
                    <TextField source="url" />
                </Datagrid>
                <Pagination />
            </ArrayField>
        </SimpleShowLayout>
    </Show>
);

@@ -162,8 +162,6 @@ const Root = styled('div', {
})(({ theme }) => ({
display: 'flex',
flexWrap: 'wrap',
marginTop: theme.spacing(-1),
Copy link
Member Author

Choose a reason for hiding this comment

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

This looked bad in a SimpleShowLayout. It was designed to make Datagrid rows thinner, but we can do it in user land via the sx prop (see modified PostList).

@fzaninotto fzaninotto added the RFR Ready For Review label Apr 4, 2023
</MemoryRouter>
);

export const PerPage = () => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one would benefit from setting up the I18nProvider

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, fixed!

@djhi djhi merged commit ab9fe9c into next Apr 5, 2023
@djhi djhi deleted the ArrayField-filterable branch April 5, 2023 11:58
@djhi djhi added this to the 4.10.0 milestone Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants