mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
FIX: Make category-drop search subcategories (#25817)
Subcategories were not returned when lazy loaded categories are enabled. This commit implements the old behavior which displayed only top level categories when there was no search term, but when there was one, it searched subcategories too. This commit also removes the client-side ordering of categories, because the results are already ordered on the server-side.
This commit is contained in:
parent
57ab42d4ca
commit
35adf6046e
@ -139,22 +139,26 @@ export default ComboBoxComponent.extend({
|
|||||||
|
|
||||||
async search(filter) {
|
async search(filter) {
|
||||||
if (this.site.lazy_load_categories) {
|
if (this.site.lazy_load_categories) {
|
||||||
const results = await Category.asyncSearch(filter, {
|
let parentCategoryId;
|
||||||
parentCategoryId: this.options.parentCategory?.id || -1,
|
if (this.options.parentCategory?.id) {
|
||||||
includeUncategorized: this.siteSettings.allow_uncategorized_topics,
|
parentCategoryId = this.options.parentCategory.id;
|
||||||
limit: 15,
|
} else if (!filter) {
|
||||||
});
|
// Only top-level categories should be displayed by default.
|
||||||
return this.shortcuts.concat(
|
// If there is a search term, the term can match any category,
|
||||||
results.sort((a, b) => {
|
// including subcategories.
|
||||||
if (a.parent_category_id && !b.parent_category_id) {
|
parentCategoryId = -1;
|
||||||
return 1;
|
|
||||||
} else if (!a.parent_category_id && b.parent_category_id) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const results = (
|
||||||
|
await Category.asyncSearch(filter, {
|
||||||
|
parentCategoryId,
|
||||||
|
includeUncategorized: this.siteSettings.allow_uncategorized_topics,
|
||||||
|
includeAncestors: true,
|
||||||
|
limit: 15,
|
||||||
})
|
})
|
||||||
);
|
).categories;
|
||||||
|
|
||||||
|
return this.shortcuts.concat(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
|
Loading…
Reference in New Issue
Block a user