mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 21:24:45 +08:00
FIX: Show only top categories in first category-drop (#24575)
This commit is contained in:
@ -135,12 +135,15 @@ export default ComboBoxComponent.extend({
|
|||||||
|
|
||||||
async search(filter) {
|
async search(filter) {
|
||||||
const opts = {
|
const opts = {
|
||||||
parentCategoryId: this.options.parentCategory?.id,
|
parentCategoryId: this.options.parentCategory?.id || -1,
|
||||||
includeUncategorized: this.siteSettings.allow_uncategorized_topics,
|
includeUncategorized: this.siteSettings.allow_uncategorized_topics,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.siteSettings.lazy_load_categories) {
|
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(
|
return this.shortcuts.concat(
|
||||||
results.sort((a, b) => {
|
results.sort((a, b) => {
|
||||||
if (a.parent_category_id && !b.parent_category_id) {
|
if (a.parent_category_id && !b.parent_category_id) {
|
||||||
|
@ -353,7 +353,13 @@ class CategoriesController < ApplicationController
|
|||||||
) if term.present?
|
) if term.present?
|
||||||
|
|
||||||
categories =
|
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 =
|
||||||
categories.where.not(id: SiteSetting.uncategorized_category_id) if !include_uncategorized
|
categories.where.not(id: SiteSetting.uncategorized_category_id) if !include_uncategorized
|
||||||
|
@ -1096,6 +1096,17 @@ RSpec.describe CategoriesController do
|
|||||||
"Foobar",
|
"Foobar",
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "with include_uncategorized" do
|
context "with include_uncategorized" do
|
||||||
|
Reference in New Issue
Block a user