DataViews: filterSortAndPaginate should ignore sorting on non-sortable fields#73950
Conversation
98aad2c to
44c345c
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| const sortByField = view.sort?.field | ||
| ? _fields.find( ( field ) => { | ||
| return field.id === view.sort?.field; | ||
| return ( |
There was a problem hiding this comment.
This makes sense to me. @oandregal should we add the same check for groupByField?
There was a problem hiding this comment.
I suppose this is fine.
@fushar can you share more in which situations do you run into this? If the field is not sortable, it won't be listed in the view config sort component, and so the user will never trigger a "sorting request" with that field.
There was a problem hiding this comment.
Just checked the PR description and it's for covering for stored views.
|
Can we merge this? cc: @youknowriad since it's a bit related to view persistence (I can't add reviewer since I don't have the rights) 😄 |
@fushar it seems @oandregal agreed (thumbs up emoji) that we should also add this check for groupByField. |
Oops, I misunderstood the comment. I am just aware of the |
|
Thank you!! |
What?
filterSortAndPaginate()should check whether the requested sort-by field is sortable or not before attempting to sort the data.Why?
useView() will retrieve the previously-persisted view.
The following faulty sequence of events could happen:
localeCompare()on it). Or we just decide that the field should not be sortable.enableSorting: falsefilterSortAndPaginate()runs, and could potentially crash. Example error:How?
Check for
field.enableSortingfirst before sorting.Testing Instructions
Verify the added unit test passes.