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 record context in SimpleList #6552

Merged
merged 2 commits into from
Sep 3, 2021
Merged

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Sep 2, 2021

SimpleList now wrap each item inside a record context and support React elements directly for the primaryText, secondaryText and tertiaryText props.

This allows to use any of the react-admin fields and make it way easier to display referenced records data:

// in src/posts.js
import * as React from "react";
import { List, SimpleList } from 'react-admin';

const postRowStyle = (record, index) => ({
    backgroundColor: record.nb_views >= 500 ? '#efe' : 'white',
});

export const PostList = (props) => (
    <List {...props}>
        <SimpleList
            primaryText={<TextField source="title" />}
            secondaryText={record => `${record.views} views`}
            tertiaryText={
                <ReferenceField reference="categories" source="category_id">
                    <TextField source="name" />
                </ReferenceField>
            }
            linkType={record => record.canEdit ? "edit" : "show"}
            rowStyle={postRowStyle}
        />
    </List>
);

It also fixes a semantic issue as the SimpleList display an ul but the children were anchors instead of li

@djhi djhi added the RFR Ready For Review label Sep 2, 2021
@djhi djhi added this to the 3.18 milestone Sep 2, 2021
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

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

Awesome!

docs/List.md Outdated Show resolved Hide resolved
Co-authored-by: Francois Zaninotto <francois@marmelab.com>
@djhi djhi requested a review from fzaninotto September 3, 2021 08:01
@fzaninotto fzaninotto merged commit c0cf7d6 into master Sep 3, 2021
@fzaninotto fzaninotto deleted the simplelist-recordcontext branch September 3, 2021 08:07
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