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

Use resource definition to set default <Datagrid rowClick> value #9466

Merged
merged 4 commits into from
Nov 23, 2023

Conversation

slax57
Copy link
Contributor

@slax57 slax57 commented Nov 22, 2023

<Datagrid> should be smarter than having rowClick default to false.
It can use the resource definition to look for an existing Show or Edit view, and default to those instead.
This PR changes the default value to be a bit smarter.

Minor Breaking Change

<Datagrid> will now make the rows clickable as soon as a Show or Edit view is declared on the resource.

If you previously relied on the fact that the rows were not clickable by default, you now need to explicitly disable the rowClick feature:

-<Datagrid>
+<Datagrid rowClick={false}>
   ...
</Datagrid>

@slax57 slax57 added the RFR Ready For Review label Nov 22, 2023
@@ -604,7 +592,7 @@ But now that the `users` resource has a `show` view, you can also link to it fro
// in src/posts.tsx
export const PostList = () => (
<List>
<Datagrid rowClick="edit">
<Datagrid>
- <ReferenceField source="userId" reference="users" />
+ <ReferenceField source="userId" reference="users" link="show" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR but this should probably be automatic as well (detection of the available views with the same priorities)

@@ -93,7 +91,7 @@ const ListViewGuesser = (
);
const inferredChild = new InferredElement(
listFieldTypes.table,
{ hasEdit, hasShow },
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ?

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 it's no longer necessary 🤷
(ListGuesser used these props to calculate the rowClick prop, which we no longer needed, so might as well cleanup the props we send to InferredElement... Using null is something I saw in other components (EditGuesser if my recollection is correct) so I did the same thing)

@djhi djhi modified the milestones: 5.0.0, 4.17.0 Nov 22, 2023
@djhi djhi merged commit dfd83ca into next Nov 23, 2023
11 checks passed
@djhi djhi deleted the Datagrid-rowClick-default branch November 23, 2023 05:53
@djhi djhi modified the milestones: 4.17.0, 5.0.0 Nov 23, 2023
@fzaninotto fzaninotto mentioned this pull request Nov 23, 2023
24 tasks
@slax57 slax57 added the v5 label Nov 27, 2023
slax57 added a commit that referenced this pull request Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review v5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants