mathesar icon indicating copy to clipboard operation
mathesar copied to clipboard

Sort list of schemas

Open seancolsen opened this issue 2 years ago • 22 comments

On the Database Page, the schemas appear in random order.

image

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.

seancolsen avatar Nov 04 '22 01:11 seancolsen

Is this necessary for the live demo?

kgodey avatar Nov 04 '22 13:11 kgodey

@kgodey

Is this necessary for the live demo?

I don't feel strongly about it. Feel free to re-prioritize

seancolsen avatar Nov 04 '22 13:11 seancolsen

@seancolsen Can I tackle this issue!

ayao451 avatar Nov 29 '22 00:11 ayao451

Sure, go ahead @ayao451!

kgodey avatar Nov 29 '22 01:11 kgodey

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

rajatvijay avatar Nov 29 '22 13:11 rajatvijay

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.

mathemancer avatar Nov 30 '22 19:11 mathemancer

I removed the frontend label from the issue.

kgodey avatar Nov 30 '22 19:11 kgodey

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!

ayao451 avatar Dec 05 '22 03:12 ayao451

Yes, we should sort the schemas in the backend. @mathemancer can point to the best place in the code to do this.

kgodey avatar Dec 05 '22 04:12 kgodey

Thank you so much! I am excited to contribute!!

ayao451 avatar Dec 05 '22 04:12 ayao451

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.

mathemancer avatar Dec 06 '22 04:12 mathemancer

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.

kgodey avatar Dec 06 '22 04:12 kgodey

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 avatar Dec 06 '22 05:12 ayao451

@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.

kgodey avatar Dec 06 '22 05:12 kgodey

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)

ayao451 avatar Dec 06 '22 05:12 ayao451

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.

Edit: see Django docs for order_by for more details

kgodey avatar Dec 06 '22 06:12 kgodey

Hi @kgodey I made my commit to my branch! It is called ayaobranch, should I run git push?

ayao451 avatar Dec 08 '22 21:12 ayao451

@ayao451 Yes, push your changes and make a pull request as described here.

kgodey avatar Dec 08 '22 21:12 kgodey

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 avatar Mar 15 '23 18:03 pavish

@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 avatar Mar 15 '23 18:03 kgodey

@kgodey Sorry, my bad. I marked it as restricted to maintainers again. Thanks!

pavish avatar Mar 15 '23 18:03 pavish

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"

danielrosehill avatar May 08 '24 22:05 danielrosehill