Skip to content

Commit

Permalink
FIX: Respect default category sort when filter=default (#23411)
Browse files Browse the repository at this point in the history
Previously we would respect it if the filter was `nil`, but if `default` was explicitly passed then it would ignore the category order settings. This explicit passing of `filter=default` happens for some types of navigations in the JS app.

This extends the fix from 92bc61b
  • Loading branch information
davidtaylorhq committed Sep 5, 2023
1 parent 2ed223f commit 534f62c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/topic_query.rb
Expand Up @@ -749,7 +749,7 @@ def default_results(options = {})
# category default sort order
sort_order, sort_ascending =
Category.where(id: category_id).pick(:sort_order, :sort_ascending)
if sort_order && (filter.blank? || %w[latest unseen].include?(filter.to_s))
if sort_order && (filter.blank? || %w[default latest unseen].include?(filter.to_s))
options[:order] = sort_order
options[:ascending] = !!sort_ascending ? "true" : "false"
else
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/topic_query_spec.rb
Expand Up @@ -1005,6 +1005,17 @@ class ::TopicQuery
expect(topic_ids - [topic_category.id]).to eq([topic_in_cat1.id, topic_in_cat2.id])
end

it "uses the category's default sort order when filter=default is passed explicitly" do
category.update!(sort_order: "created", sort_ascending: true)
topic_ids =
TopicQuery
.new(user, category: category.id, filter: "default")
.list_latest
.topics
.map(&:id)
expect(topic_ids - [topic_category.id]).to eq([topic_in_cat1.id, topic_in_cat2.id])
end

it "should apply default sort order to latest and unseen filters only" do
category.update!(sort_order: "created", sort_ascending: true)

Expand Down

1 comment on commit 534f62c

@discoursebot
Copy link

Choose a reason for hiding this comment

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

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/category-links-should-honor-category-order-settings/274333/8

Please sign in to comment.