Skip to content

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

FIX: show categories dropdown filter for user groups in lazy_load_categories_groups (#36218)

Yuriy Kurant4ecdbaf22a5b
diff --git a/frontend/discourse/select-kit/components/category-drop.js b/frontend/discourse/select-kit/components/category-drop.js
index 9c01a7d141a..662a1efb7bc 100644
--- a/frontend/discourse/select-kit/components/category-drop.js
+++ b/frontend/discourse/select-kit/components/category-drop.js
@@ -42,6 +42,7 @@ const MORE_COLLECTION = "MORE_COLLECTION";
headerComponent: CategoryDropHeader,
parentCategory: false,
allowUncategorized: "allowUncategorized",
+ autoFilterable: "autoFilterable",
})
@pluginApiIdentifiers(["category-drop"])
export default class CategoryDrop extends ComboBoxComponent {
@@ -87,6 +88,11 @@ export default class CategoryDrop extends ComboBoxComponent {
return this.options.subCategory || false;
}
+ @computed("content.length", "site.lazy_load_categories")
+ get autoFilterable() {
+ return this.site.lazy_load_categories || this.content.length >= 10;
+ }
+
@computed("value", "selectKit.options.{subCategory,noSubcategories}")
get shortcuts() {
const shortcuts = [];
diff --git a/spec/system/categories_page_spec.rb b/spec/system/categories_page_spec.rb
index ef43d63b5e3..e345f924e6b 100644
--- a/spec/system/categories_page_spec.rb
+++ b/spec/system/categories_page_spec.rb
@@ -38,4 +38,38 @@ RSpec.describe "Categories Page" do
expect(subcategory_selector).to have_selected_name(subcategory.name)
end
end
+
+ describe "dropdown filter" do
+ it "is shown for users in lazy_load_categories_groups" do
+ SiteSetting.lazy_load_categories_groups = "admins"
+ sign_in(admin)
+ category_page.visit_general(category)
+ category_selector =
+ PageObjects::Components::SelectKit.new(".category-breadcrumb__category-selector")
+
+ expect(category_selector).to have_filter
+ end
+
+ it "is not shown if categories are up to 10" do
+ sign_in(admin)
+ category_page.visit_general(category)
+ category_selector =
+ PageObjects::Components::SelectKit.new(".category-breadcrumb__category-selector")
+
+ expect(category_selector).to have_no_filter
+ end
+
+ context "when categories are 10 or more" do
+ fab!(:categories) { Fabricate.times(8, :category) }
+
+ it "is shown" do
+ sign_in(admin)
+ category_page.visit_general(category)
+ category_selector =
+ PageObjects::Components::SelectKit.new(".category-breadcrumb__category-selector")
+
+ expect(category_selector).to have_filter
+ end
+ end
+ end
end
diff --git a/spec/system/page_objects/components/select_kit.rb b/spec/system/page_objects/components/select_kit.rb
index f987ed64df6..bd607764c46 100644
--- a/spec/system/page_objects/components/select_kit.rb
+++ b/spec/system/page_objects/components/select_kit.rb
@@ -92,6 +92,14 @@ module PageObjects
collapsed_component
end
+ def has_filter?
+ expanded_component.has_css?(".select-kit-filter .filter-input", visible: true)
+ end
+
+ def has_no_filter?
+ expanded_component.has_no_css?(".select-kit-filter .filter-input")
+ end
+
def search(value = nil)
expanded_component.find(".select-kit-filter .filter-input").fill_in(with: value)
end