Skip to content

A platform for community discussion. Free, open, simple.

FIX: workflows - fix autocomplete for list post node (#40597)

Sambf4614f578ac
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index a017915d0ee..353939e23f7 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -3005,8 +3005,20 @@ en:
keywords: "Show posts containing any of the specified keywords"
topic_keywords: "Show posts in topics containing any of the specified keywords"
post_type: "Show first posts or replies"
+ post_type_first: "First posts only"
+ post_type_reply: "Replies only"
status: "Filter posts by topic status"
+ status_open: "Open topics"
+ status_closed: "Closed topics"
+ status_archived: "Archived topics"
+ status_noreplies: "Topics with no replies"
+ status_single_user: "Topics with a single user"
order: "Sort posts"
+ order_latest: "Latest posts"
+ order_oldest: "Oldest posts"
+ order_latest_topic: "Latest topics"
+ order_oldest_topic: "Oldest topics"
+ order_likes: "Most liked"
max_results: "Maximum number of posts to return"
filter:
diff --git a/lib/posts_filter.rb b/lib/posts_filter.rb
index f61081bee5b..d249ebbd57b 100644
--- a/lib/posts_filter.rb
+++ b/lib/posts_filter.rb
@@ -129,6 +129,19 @@ class PostsFilter
end
end
+ def self.option_value_info(filter_name, values)
+ values.map do |value|
+ {
+ name: "#{filter_name}:#{value}",
+ description:
+ I18n.t(
+ "posts_filter.description.#{filter_name}_#{value}",
+ default: value.to_s.tr("_", " ").capitalize,
+ ),
+ }
+ end
+ end
+
def self.option_info(guardian)
results = [
{
@@ -204,21 +217,13 @@ class PostsFilter
{
name: "post_type:",
description: I18n.t("posts_filter.description.post_type"),
- type: "string",
- extra_entries: POST_TYPE_VALUES.map { |value| { name: value } },
- },
- {
- name: "status:",
- description: I18n.t("posts_filter.description.status"),
- type: "string",
- extra_entries: STATUS_VALUES.map { |value| { name: value } },
- },
- {
- name: "order:",
- description: I18n.t("posts_filter.description.order"),
- type: "string",
- extra_entries: ORDER_VALUES.map { |value| { name: value } },
+ priority: 1,
},
+ *option_value_info("post_type", POST_TYPE_VALUES),
+ { name: "status:", description: I18n.t("posts_filter.description.status"), priority: 1 },
+ *option_value_info("status", STATUS_VALUES),
+ { name: "order:", description: I18n.t("posts_filter.description.order"), priority: 1 },
+ *option_value_info("order", ORDER_VALUES),
{
name: "max_results:",
description: I18n.t("posts_filter.description.max_results"),
diff --git a/plugins/discourse-workflows/spec/requests/discourse_workflows/filter_options_controller_spec.rb b/plugins/discourse-workflows/spec/requests/discourse_workflows/filter_options_controller_spec.rb
index 759ec39bdd2..e49028e0dfe 100644
--- a/plugins/discourse-workflows/spec/requests/discourse_workflows/filter_options_controller_spec.rb
+++ b/plugins/discourse-workflows/spec/requests/discourse_workflows/filter_options_controller_spec.rb
@@ -24,7 +24,14 @@ RSpec.describe DiscourseWorkflows::FilterOptionsController do
expect(response).to have_http_status(:ok)
option_names = response.parsed_body["filter_option_info"].map { |option| option["name"] }
- expect(option_names).to include("category:", "keywords:", "post_type:")
+ expect(option_names).to include(
+ "category:",
+ "keywords:",
+ "post_type:",
+ "post_type:first",
+ "status:open",
+ "order:latest",
+ )
end
end
end
diff --git a/spec/lib/posts_filter_spec.rb b/spec/lib/posts_filter_spec.rb
index 4b4105fa84d..e56ef9a887b 100644
--- a/spec/lib/posts_filter_spec.rb
+++ b/spec/lib/posts_filter_spec.rb
@@ -59,6 +59,21 @@ RSpec.describe PostsFilter do
.pluck(:id)
end
+ it "returns enum filter values as server-supplied suggestions" do
+ options = described_class.option_info(user.guardian)
+
+ expect(options).to include(
+ { name: "order:", description: I18n.t("posts_filter.description.order"), priority: 1 },
+ { name: "order:latest", description: I18n.t("posts_filter.description.order_latest") },
+ { name: "status:open", description: I18n.t("posts_filter.description.status_open") },
+ { name: "post_type:first", description: I18n.t("posts_filter.description.post_type_first") },
+ )
+ expect(options.find { |option| option[:name] == "order:" }).not_to include(
+ :type,
+ :extra_entries,
+ )
+ end
+
it "filters posts by tags and categories" do
expect(filtered_post_ids("tag:feature")).to contain_exactly(
feature_post.id,