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

FEATURE: add new custom status filters #286

Merged
merged 2 commits into from Apr 26, 2024
Merged

Conversation

ZogStriP
Copy link
Member

Those can be used in /filter route.

Depends on discourse/discourse#26770

Internal ref. /t/127278

plugin.rb Outdated
@@ -310,15 +310,16 @@ def self.skip_db?
end

if respond_to?(:register_modifier)
register_modifier(:search_rank_sort_priorities) do |priorities, search|
register_modifier(:search_rank_sort_priorities) do |priorities, _search|
Copy link
Member Author

Choose a reason for hiding this comment

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

Added the "_" prefix to signal that this argument isn't being used.

WHERE topics.id = f.topic_id
AND f.name = '#{::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD}'
)
EXISTS (
Copy link
Member Author

Choose a reason for hiding this comment

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

Formatted the query and added the "AND value IS NOT NULL" condition that is being used everywhere else

WHERE tc.name = '#{::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD}' AND
tc.value IS NOT NULL
)",
solved_callback = ->(scope) do
Copy link
Member Author

Choose a reason for hiding this comment

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

We have several ways to filter by solved/unsolved status (in search, in filter, in topic lists, etc...).

I've extracted both solved and unsolved "queries" so they can be used everywhere.

plugin.rb Outdated
end

if Discourse.has_needed_version?(Discourse::VERSION::STRING, "1.8.0.beta6")
if respond_to? :register_custom_filter_by_status
Copy link
Member Author

Choose a reason for hiding this comment

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

Using the new API introduced in discourse/discourse#26770

plugin.rb Outdated
register_custom_filter_by_status("unsolved", &unsolved_callback)
end

if respond_to? :register_search_advanced_filter
Copy link
Member Author

Choose a reason for hiding this comment

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

Used the "plugin" API instead of reaching directly for the Search class.

plugin.rb Outdated
@@ -432,19 +423,27 @@ def self.skip_db?
if Search.respond_to? :preloaded_topic_custom_fields
Search.preloaded_topic_custom_fields << ::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD
end

if CategoryList.respond_to?(:preloaded_topic_custom_fields)
if CategoryList.respond_to? :preloaded_topic_custom_fields
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed parenthesis to match surrounding styling.

AND value IS NOT NULL
)
SQL
on(:filter_auto_bump_topics) do |_category, filters|
Copy link
Member Author

Choose a reason for hiding this comment

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

Tweaked the formatting a little bit so it's less confusing 🤷

Those can be used in /filter route.

Depends on discourse/discourse#26770

Internal ref. /t/127278
@jjaffeux
Copy link
Contributor

How about using discourse_compatibility so we dont have to do all the ifs everywhere?

@ZogStriP
Copy link
Member Author

ZogStriP commented Apr 26, 2024

@jjaffeux Is 2dbb02f what you had in mind? 🤔

@jjaffeux
Copy link
Contributor

@jjaffeux Is 2dbb02f what you had in mind? 🤔

Yes we know these APIs are in discourse at this version, so it should be safe

@ZogStriP ZogStriP merged commit 2c96c5b into main Apr 26, 2024
4 checks passed
@ZogStriP ZogStriP deleted the add-custom-status-filters branch April 26, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants