-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: sort by multiple columns #8799
feat: sort by multiple columns #8799
Conversation
7e02474
to
abfb3f4
Compare
Thank you @andershermansen, when I found about Payload I was surprised that it's not a thing and opened a PR @DanRibbens will review this, but I want to throw my point about type-safety. We plan to make And Array (
Yep, because you need to sort by a nested property there. As the actual data in versions is stored inside of the |
I think that looks nice, and it should not be a big problem to adjust this implementation. |
@r1tsuu Here is PR which uses array instead of comma separated list for local API. I left REST API alone as using an array will complicate the interface a lot. The PR is in my fork against this branch/PR, and if merged will update this branch/PR with the array style. Let me know what you think. |
Oh, I didn't mean to make these changes just now, I wanted to see Dan's view on this first. With REST API, if you use |
Now we have some code to discuss 😄
I know, but I did not see the benefit of doing it like this is the REST API. I did it at first, but reverted it to make the input simpler. I understand the benefit of using qs for complex where queries, but here for sort it's very simple input and is much simpler with just a comma separated string IMO. |
I like the type safety points that @r1tsuu is making. I approve the idea for it to have a type of string or array of strings that we can derive from the collection slugs, that sounds really good to me. I would make it so that the database adapter methods and the payload local API have the same type for the |
feat: sort by multiple columns using array
@DanRibbens Cool. Merged my changes for that into the branch of this PR.
Yes, this is what I have done. I have defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one question for you. Overall this looks great!
@andershermansen I ran your commented test with my merged changes from here #8839, it passes! |
@r1tsuu Nice! 💪 Not in front of a computer right now, but there was an integration test inside localization which was only running on mongodb, and disabled for others. You should check if that is OK and can be enabled for all again as well. |
I tried, this test doesn't really check localized sorting, it sorts by non-localized |
🚀 This is included in version v3.0.0-beta.119 |
This change adds support for sort with multiple columns in local API and REST API. I looked at the comment from DanRibbens in old PR #3236 for v1 and implemented this as a comma separated string only.
Related discussion #2089
I added a new integration test suite for sorting as I did not find any other good place to test this. It includes current functionality for sort with both regular collections, drafts and versions to make sure I did not break anything. And of course testing the new functionality implemented.
I also included documentation updates.
When testing localization the new test suite actually uncovers an existing error in drizzle localized sorting. The integration test for localization works with mongodb, but fails with postgres and sqlite (drizzle). This is already reported by another user in issue #5152
I left the test is in this PR, but commented out. I have not yet used enough time to look into how the drizzle package deals with localization to be able to fix this. Anyways, it's out of scope for this PR and should be a separate fix.
For findVersions I'm a bit surprised that you need to prepend the sort string with "version." for it to work. Is this expected?