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

[DataGrid] Do not publish rowEditStop event if row has fields with errors #11383

Merged
merged 8 commits into from Mar 26, 2024

Conversation

@cherniavskii cherniavskii added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Editing Related to the data grid Editing feature labels Dec 12, 2023
@mui-bot
Copy link

mui-bot commented Dec 12, 2023

Deploy preview: https://deploy-preview-11383--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 863db74

@cherniavskii cherniavskii marked this pull request as ready for review December 13, 2023 14:40
@cherniavskii cherniavskii added the needs cherry-pick The PR should be cherry-picked to master after merge label Dec 13, 2023
@lauri865
Copy link
Contributor

Does this prevent processRowUpdate from being called as well? If so, it'll break a lot of things in our custom validator implementation that shows validation errors also in viewing mode, and I'm not sure if there's a good alternative to that.

Copy link
Member

@michelengelen michelengelen left a comment

Choose a reason for hiding this comment

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

super solid! LGTM! :shipit:

@michelengelen
Copy link
Member

@lauri865 this will only prevent the rowEditStop event to be fired, when there are fields with errors present. Correct @cherniavskii ?

@cherniavskii
Copy link
Member Author

@lauri865 processRowUpdate is not being called if the row has fields in error state - see https://codesandbox.io/p/sandbox/nostalgic-paper-wyyv28?file=%2Fsrc%2FDemo.tsx%3A19%2C21

If you're not using preProcessEditCellProps and only rely on processRowUpdate for validation - it should be OK.
The server-side validation demo works as before: https://deploy-preview-11383--material-ui-x.netlify.app/x/react-data-grid/editing/#server-side-validation

@cherniavskii
Copy link
Member Author

Let's wait a bit for @lauri865's feedback on this to make sure we're not breaking anything 🙂
@lauri865 Could you confirm my points in #11383 (comment)?

@lauri865
Copy link
Contributor

You are correct.

We are using preProcessEditCellProps, but have sidestepped using the error prop and replaced it with custom props like errorMessage to make sure processRowUpdate gets called regardless of whether there is an error or not. So, thanks to that it will not break things for us luckily.

The problem is that both onCellEditStop and onRowEditStop don't include the latest value, and the only way we've found to be able to show validation errors in view mode (see example below) is through the above workaround by side-stepping the error prop and getting datagrid to call processRowUpdate regardless. Just rejecting invalid inputs, which is the default behaviour, is often too restricting of an UX. Imagine a use case where the user uploads a CSV with 25 rows, and there's missing data you want to highlight (validation needs to be shown outside editing mode), and maybe erroneous rows that the user will want to skip altogether (not get stuck in edit mode every time you enter an invalid field). That requires validation to be less blocking, more informative. Just wish there was an easier way to achieve this behaviour by default, but we have managed to find a way that works for us for now at least, albeit I realise it may not be the most future-proof way.

Example of showcasing a tooltip with validation errors in view mode:
Screenshot 2023-12-15 at 13 39 54

@cherniavskii
Copy link
Member Author

@lauri865

So, thanks to that it will not break things for us luckily.

Great, I'll push this PR forward then!

The problem is that both onCellEditStop and onRowEditStop don't include the latest value

Could you open a new issue for this discussion? A minimal reproduction example would be great!

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 7, 2024
Copy link

github-actions bot commented Feb 7, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

1 similar comment
Copy link

github-actions bot commented Feb 7, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@MBilalShafi MBilalShafi changed the base branch from next to master March 21, 2024 02:29
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 26, 2024
@cherniavskii cherniavskii removed the needs cherry-pick The PR should be cherry-picked to master after merge label Mar 26, 2024
@cherniavskii cherniavskii merged commit 5e99aa1 into mui:master Mar 26, 2024
18 checks passed
@cherniavskii cherniavskii deleted the fix-rowEditStop branch March 26, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Editing Related to the data grid Editing feature
Projects
None yet
6 participants