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

Add ability to specify default_sort_direction on a resource #3116

Merged

Conversation

stevegeek
Copy link
Contributor

Description

The ability to specify a default_sort_column was added recently, this PR adds the ability to also specify the direction of the sort.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots & recording

Manual review steps

Simply add a .default_sort_direction = :asc to a Resource

@stevegeek
Copy link
Contributor Author

I will need to update the docs when I get a chance

Copy link

codeclimate bot commented Aug 9, 2024

Code Climate has analyzed commit 484bfc3 and detected 0 issues on this pull request.

View more on Code Climate.

@adrianthedev
Copy link
Collaborator

FYI, these are the docs for sort column
https://github.com/avo-hq/docs.avohq.io/pull/269/files

@stevegeek
Copy link
Contributor Author

Docs added avo-hq/docs.avohq.io#274

@stevegeek stevegeek requested a review from Paul-Bob August 11, 2024 04:40
Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

Feature tests are breaking

@stevegeek
Copy link
Contributor Author

@Paul-Bob ok seems to be related to the change to remove the || :desc , will look at it now

@stevegeek
Copy link
Contributor Author

@Paul-Bob so activesupport Class.class_attribute sets the default only on definition of the attribute, ie it does not act as a default when the attribute is specifically set to nil. Im not sure what the desired behaviour here is. My initial implementation meant that if default_sort_direction was specifically set to nil then the sort direction would default to :desc , now in the current implementation, setting default_sort_direction to nil explicitly removes a sort order parameter.

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Aug 12, 2024

Why would someone set self.default_sort_direction = nil?

@stevegeek
Copy link
Contributor Author

I imagine one would only do so to explicitly force to use the default, or in the case of it being set by some other configuration value say which may end up being nil. Hence I would suggest we revert back to the original implementation with || :desc which is more defensive, setting the sort direction to :desc in the event self.default_sort_direction is set to nil (on purpose or inadvertently)

@Paul-Bob
Copy link
Contributor

In my opinion, setting self.default_sort_direction = nil to enforce an explicit default is not the right approach and we should not maintain it. The intention behind this line is to explicitly set default_sort_direction to nil. In some specific edge cases, this behavior might be necessary, and we should preserve the ability to set it to nil when required.

I made this change, which resolved the test issues.

Thank you for your contribution, @stevegeek! We appreciate it.

@Paul-Bob Paul-Bob merged commit b43a939 into avo-hq:main Aug 12, 2024
22 checks passed
@stevegeek
Copy link
Contributor Author

@Paul-Bob ok! You are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants