mathesar
mathesar copied to clipboard
Sort list of schemas
On the Database Page, the schemas appear in random order.
I think they should be listed alphabetically, perhaps with public
first.
I'm not sure whether it would be better to handle this on the back end or the front end.
Any thoughts @mathemancer @rajatvijay?
Update:
- This issue is supposed to be handled on the backend.
- Part of this issue is solved in https://github.com/centerofci/mathesar/pull/2062
- Refer https://github.com/centerofci/mathesar/issues/1897#issuecomment-1470542703 for the current state of the issue.
Is this necessary for the live demo?
@kgodey
Is this necessary for the live demo?
I don't feel strongly about it. Feel free to re-prioritize
@seancolsen Can I tackle this issue!
Sure, go ahead @ayao451!
Given how easy is to create a schema from FE, I expect this list to grow in the future. It will be better if we handle it on the BE, I think the effort is going to be somewhat similar
Given how easy is to create a schema from FE, I expect this list to grow in the future. It will be better if we handle it on the BE, I think the effort is going to be somewhat similar
Also, we're paginating (or can paginate) the results on the back end (if there are enough of them). This would require sorting them consistently in the back end.
I removed the frontend label from the issue.
Hi @kgodey! This is actually my first ever issue, and I was wondering about the specifics of the fix you wanted me to implement! Since this is a backend task, I wanted to sort the schemas in the actual database, so when we display it, it should automatically display sorted! Would this be the way you wanted me to tackle it!
Yes, we should sort the schemas in the backend. @mathemancer can point to the best place in the code to do this.
Thank you so much! I am excited to contribute!!
A couple of things:
- The correct place to start looking at ordering for the schemas is the schema viewset
- Currently, they're ordered in descending order based on creation timestamp (newest first). It occurs to me that this (or most recently accessed) might be at least as valid as alphabetical.
At the risk of overly increasing the scope of this ticket, it seems like alphabetical should be one of a few options for ordering. (others being creation date, and recently accessed), and the default should actually be the current ordering (creation date descending).
@seancolsen What do you think? As a user has more and more schemas they're working with, I don't think they'll want to always have to go to the 4th page of schema listings to find their Movie collection schema.
Apologies for not thinking deeply enough about this in my earlier reply. I didn't realize we already had a pretty sensible (to me) default ordering.
I think alphabetical still makes the most sense here, it's easiest to scan and a user is probably not indexing on when they created a schema.
As a user has more and more schemas they're working with, I don't think they'll want to always have to go to the 4th page of schema listings to find their Movie collection schema.
We're going to introduce some sort of bookmarking / favoriting in the future to solve this problem.
At the risk of overly increasing the scope of this ticket, it seems like alphabetical should be one of a few options for ordering. (others being creation date, and recently accessed), and the default should actually be the current ordering (creation date descending).
I do think offering more sorting options makes sense in the future (out of scope for this issue), but the default should still be alphabetical.
Edit: or actually the default should be determined through usability testing.
I can try to code up all four for user-testing purposes then! I am also a bit new to git, so should I create my own branch and maybe put alphabetical sorting there, as well as create separate branches for the other sorting methods? Once I finish the sorting, I can try to get a button on the front end that can toggle the sort, although as the database grows, it would take much longer!
@ayao451 For this issue, just alphabetical sorting is fine, no need to create all four or make any front end changes. We're just discussing ideas for things we could do in the future.
Please do make your own branch, change the code to do alphabetical sorting, and then create a pull request. We'll review it once it's up.
Sounds good! Would the change just be one small thing then, Changing this to -name instead of created_at?
def get_queryset(self): qs = Schema.objects.all().order_by('-created_at') return self.access_policy.scope_viewset_queryset(self.request, qs)
You'd want to do name
, not -name
, since -
changes it to descending order. When you're sorting by date, descending makes sense since you want newest first. When you're sorting by name, you want ascending.
Hi @kgodey I made my commit to my branch! It is called ayaobranch, should I run git push?
@ayao451 Yes, push your changes and make a pull request as described here.
This issue is reopened because it still persists. The PR solves the ordering when requested via API.
The most possible cause that this still persists is because ordering is not handled in the preloaded data where the list is obtained directly from the schema serializer.
I'm removing the restricted: maintainers
label and marking this issue as a good first issue
.
@pavish This is not a good issue for contributors since it needs backend architectural changes. Please see discussion in https://github.com/centerofci/mathesar/pull/2062
@kgodey Sorry, my bad. I marked it as restricted to maintainers again. Thanks!
I know this is an old issue but ... yes. The first thing I thought was "it would be great to be able to order the schemas alphabetically"