DEV: Async category search for sidebar modal (#25686)

This commit is contained in:
Daniel Waterworth
2024-02-20 11:24:30 -06:00
committed by GitHub
parent 716e3a4dd5
commit 13083d03ae
10 changed files with 266 additions and 92 deletions

View File

@ -341,6 +341,12 @@ class CategoriesController < ApplicationController
else
true
end
include_ancestors =
if params[:include_ancestors].present?
ActiveModel::Type::Boolean.new.cast(params[:include_ancestors])
else
false
end
prioritized_category_id = params[:prioritized_category_id].to_i if params[
:prioritized_category_id
].present?
@ -388,7 +394,18 @@ class CategoriesController < ApplicationController
Category.preload_user_fields!(guardian, categories)
render_serialized(categories, SiteCategorySerializer, root: :categories, scope: guardian)
if include_ancestors
ancestors = Category.secured(guardian).ancestors_of(categories.map(&:id))
render_json_dump(
{
categories: serialize_data(categories, SiteCategorySerializer, scope: guardian),
ancestors: serialize_data(ancestors, SiteCategorySerializer, scope: guardian),
},
)
else
render_serialized(categories, SiteCategorySerializer, root: :categories, scope: guardian)
end
end
private