mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: Show only top categories in first category-drop (#24575)
This commit is contained in:
parent
b09422428d
commit
dbb8b66a37
|
@ -135,12 +135,15 @@ export default ComboBoxComponent.extend({
|
|||
|
||||
async search(filter) {
|
||||
const opts = {
|
||||
parentCategoryId: this.options.parentCategory?.id,
|
||||
parentCategoryId: this.options.parentCategory?.id || -1,
|
||||
includeUncategorized: this.siteSettings.allow_uncategorized_topics,
|
||||
};
|
||||
|
||||
if (this.siteSettings.lazy_load_categories) {
|
||||
const results = await Category.asyncSearch(filter, { ...opts, limit: 5 });
|
||||
const results = await Category.asyncSearch(filter, {
|
||||
...opts,
|
||||
limit: 15,
|
||||
});
|
||||
return this.shortcuts.concat(
|
||||
results.sort((a, b) => {
|
||||
if (a.parent_category_id && !b.parent_category_id) {
|
||||
|
|
|
@ -353,7 +353,13 @@ class CategoriesController < ApplicationController
|
|||
) if term.present?
|
||||
|
||||
categories =
|
||||
categories.where(parent_category_id: parent_category_id) if parent_category_id.present?
|
||||
(
|
||||
if parent_category_id != -1
|
||||
categories.where(parent_category_id: parent_category_id)
|
||||
else
|
||||
categories.where(parent_category_id: nil)
|
||||
end
|
||||
) if parent_category_id.present?
|
||||
|
||||
categories =
|
||||
categories.where.not(id: SiteSetting.uncategorized_category_id) if !include_uncategorized
|
||||
|
|
|
@ -1096,6 +1096,17 @@ RSpec.describe CategoriesController do
|
|||
"Foobar",
|
||||
)
|
||||
end
|
||||
|
||||
it "can return only top-level categories" do
|
||||
get "/categories/search.json", params: { parent_category_id: -1 }
|
||||
|
||||
expect(response.parsed_body["categories"].size).to eq(3)
|
||||
expect(response.parsed_body["categories"].map { |c| c["name"] }).to contain_exactly(
|
||||
"Uncategorized",
|
||||
"Foo",
|
||||
"Notfoo",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "with include_uncategorized" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user