FIX: Update category breadcrumbs more reliably (#26608)
The breadcrumbs were updated everytime there were changes to the categories which was not efficient and caused unnecessary rerendering of the CategoryDrop elements when "lazy load categories" is enabled. This commit also ensures that all category fields are serialized for ancestors too for the categories#search endpoint.
This commit is contained in:
parent
4d2dcdad9b
commit
38e1706b61
|
@ -10,30 +10,31 @@ export default Component.extend({
|
|||
editingCategory: false,
|
||||
editingCategoryTab: null,
|
||||
|
||||
@discourseComputed("category.ancestors", "categories", "noSubcategories")
|
||||
categoryBreadcrumbs(categoryAncestors, filteredCategories, noSubcategories) {
|
||||
categoryAncestors = categoryAncestors || [];
|
||||
const parentCategories = [undefined, ...categoryAncestors];
|
||||
const categories = [...categoryAncestors, undefined];
|
||||
const zipped = parentCategories.map((x, i) => [x, categories[i]]);
|
||||
@discourseComputed("category", "categories", "noSubcategories")
|
||||
categoryBreadcrumbs(category, filteredCategories, noSubcategories) {
|
||||
const ancestors = category?.ancestors || [];
|
||||
const parentCategories = [undefined, ...ancestors];
|
||||
const categories = [...ancestors, undefined];
|
||||
|
||||
return zipped.map((record) => {
|
||||
const [parentCategory, category] = record;
|
||||
return parentCategories
|
||||
.map((x, i) => [x, categories[i]])
|
||||
.map((record) => {
|
||||
const [parentCategory, subCategory] = record;
|
||||
|
||||
const options = filteredCategories.filter(
|
||||
(c) =>
|
||||
c.get("parentCategory.id") === (parentCategory && parentCategory.id)
|
||||
);
|
||||
const options = filteredCategories.filter(
|
||||
(c) =>
|
||||
c.get("parentCategory.id") === (parentCategory && parentCategory.id)
|
||||
);
|
||||
|
||||
return {
|
||||
category,
|
||||
parentCategory,
|
||||
options,
|
||||
isSubcategory: !!parentCategory,
|
||||
noSubcategories: !category && noSubcategories,
|
||||
hasOptions: !parentCategory || parentCategory.has_children,
|
||||
};
|
||||
});
|
||||
return {
|
||||
category: subCategory,
|
||||
parentCategory,
|
||||
options,
|
||||
isSubcategory: !!parentCategory,
|
||||
noSubcategories: !subCategory && noSubcategories,
|
||||
hasOptions: !parentCategory || parentCategory.has_children,
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
@discourseComputed("siteSettings.tagging_enabled", "editingCategory")
|
||||
|
|
|
@ -436,6 +436,7 @@ class CategoriesController < ApplicationController
|
|||
|
||||
if include_ancestors
|
||||
ancestors = Category.secured(guardian).ancestors_of(categories.map(&:id))
|
||||
Category.preload_user_fields!(guardian, ancestors)
|
||||
response[:ancestors] = serialize_data(ancestors, SiteCategorySerializer, scope: guardian)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue