A platform for community discussion. Free, open, simple.
UX: Truncate category list in disabled tag reasons (#39315)
Régis HANOL64b8c0417926
diff --git a/app/services/tags/search.rb b/app/services/tags/search.rbindex f483d8b28d4..9f5a731b34b 100644--- a/app/services/tags/search.rb+++ b/app/services/tags/search.rb@@ -221,12 +221,23 @@ class Tags::Searchif category_names.present?category_names.uniq!- I18n.t(- "tags.forbidden.restricted_to",- count: category_names.count,- tag_name: tag.name,- category_names: category_names.join(", "),- )+ category_names.sort!++ if category_names.size > 3+ I18n.t(+ "tags.forbidden.restricted_to_truncated",+ tag_name: tag.name,+ category_names: category_names.first(3).join(", "),+ more_count: category_names.size - 3,+ )+ else+ I18n.t(+ "tags.forbidden.restricted_to",+ count: category_names.count,+ tag_name: tag.name,+ category_names: category_names.join(", "),+ )+ endelseI18n.t("tags.forbidden.in_this_category", tag_name: tag.name)enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 865dbc522cf..6a5dec9ae98 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -5561,6 +5561,7 @@ en:restricted_to:one: '"%{tag_name}" is restricted to the "%{category_names}" category'other: '"%{tag_name}" is restricted to the following categories: %{category_names}'+ restricted_to_truncated: '"%{tag_name}" is restricted to the following categories: %{category_names}, and %{more_count} more'synonym: 'This is a synonym for "%{tag_name}". Use "%{tag_name}" instead.'has_synonyms: '"%{tag_name}" cannot be used because it has synonyms.'one_tag_per_topic_group: 'Only one tag from the "%{tag_group_name}" group is allowed per topic'diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rbindex ecfb730ce7a..5ca7ffefa85 100644--- a/spec/requests/tags_controller_spec.rb+++ b/spec/requests/tags_controller_spec.rb@@ -1455,6 +1455,52 @@ RSpec.describe TagsController doexpect(result["disabled"]).to eq(true)end+ it "truncates category names when tag is restricted to many categories" do+ categories = [category] + (1..4).map { |i| Fabricate(:category, tags: [yup]) }++ get "/tags/filter/search.json",+ params: {+ q: yup.name,+ filterForInput: true,+ categoryId: Fabricate(:category).id,+ }++ expect(response.status).to eq(200)+ result = response.parsed_body["results"].find { |t| t["name"] == yup.name }+ expect(result).to be_present+ expect(result["disabled"]).to eq(true)++ sorted_names = categories.map(&:name).sort+ expect(result["title"]).to eq(+ I18n.t(+ "tags.forbidden.restricted_to_truncated",+ tag_name: yup.name,+ category_names: sorted_names.first(3).join(", "),+ more_count: 2,+ ),+ )+ end++ it "truncates category names in forbidden_message when restricted to many categories" do+ categories = [category] + (1..4).map { |i| Fabricate(:category, tags: [yup]) }++ get "/tags/filter/search.json",+ params: {+ q: yup.name,+ categoryId: Fabricate(:category).id,+ }++ sorted_names = categories.map(&:name).sort+ expect(response.parsed_body["forbidden_message"]).to eq(+ I18n.t(+ "tags.forbidden.restricted_to_truncated",+ tag_name: yup.name,+ category_names: sorted_names.first(3).join(", "),+ more_count: 2,+ ),+ )+ end+it "can filter on category without q param" doFabricate(:tag, name: "nope")get "/tags/filter/search.json", params: { categoryId: category.id }