mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
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:
@ -10,30 +10,31 @@ export default Component.extend({
|
|||||||
editingCategory: false,
|
editingCategory: false,
|
||||||
editingCategoryTab: null,
|
editingCategoryTab: null,
|
||||||
|
|
||||||
@discourseComputed("category.ancestors", "categories", "noSubcategories")
|
@discourseComputed("category", "categories", "noSubcategories")
|
||||||
categoryBreadcrumbs(categoryAncestors, filteredCategories, noSubcategories) {
|
categoryBreadcrumbs(category, filteredCategories, noSubcategories) {
|
||||||
categoryAncestors = categoryAncestors || [];
|
const ancestors = category?.ancestors || [];
|
||||||
const parentCategories = [undefined, ...categoryAncestors];
|
const parentCategories = [undefined, ...ancestors];
|
||||||
const categories = [...categoryAncestors, undefined];
|
const categories = [...ancestors, undefined];
|
||||||
const zipped = parentCategories.map((x, i) => [x, categories[i]]);
|
|
||||||
|
|
||||||
return zipped.map((record) => {
|
return parentCategories
|
||||||
const [parentCategory, category] = record;
|
.map((x, i) => [x, categories[i]])
|
||||||
|
.map((record) => {
|
||||||
|
const [parentCategory, subCategory] = record;
|
||||||
|
|
||||||
const options = filteredCategories.filter(
|
const options = filteredCategories.filter(
|
||||||
(c) =>
|
(c) =>
|
||||||
c.get("parentCategory.id") === (parentCategory && parentCategory.id)
|
c.get("parentCategory.id") === (parentCategory && parentCategory.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
category,
|
category: subCategory,
|
||||||
parentCategory,
|
parentCategory,
|
||||||
options,
|
options,
|
||||||
isSubcategory: !!parentCategory,
|
isSubcategory: !!parentCategory,
|
||||||
noSubcategories: !category && noSubcategories,
|
noSubcategories: !subCategory && noSubcategories,
|
||||||
hasOptions: !parentCategory || parentCategory.has_children,
|
hasOptions: !parentCategory || parentCategory.has_children,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed("siteSettings.tagging_enabled", "editingCategory")
|
@discourseComputed("siteSettings.tagging_enabled", "editingCategory")
|
||||||
|
@ -436,6 +436,7 @@ class CategoriesController < ApplicationController
|
|||||||
|
|
||||||
if include_ancestors
|
if include_ancestors
|
||||||
ancestors = Category.secured(guardian).ancestors_of(categories.map(&:id))
|
ancestors = Category.secured(guardian).ancestors_of(categories.map(&:id))
|
||||||
|
Category.preload_user_fields!(guardian, ancestors)
|
||||||
response[:ancestors] = serialize_data(ancestors, SiteCategorySerializer, scope: guardian)
|
response[:ancestors] = serialize_data(ancestors, SiteCategorySerializer, scope: guardian)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user