From d2a52c3c3510a54377ee768650670f6838149764 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Tue, 23 Apr 2024 15:27:12 -0500 Subject: [PATCH] FIX: Use serialized subcategories in subcategory-with-featured-topics (#26718) --- .../subcategories-with-featured-topics.hbs | 2 +- .../discourse/app/models/category.js | 10 ++++++++- .../tests/fixtures/discovery-fixtures.js | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/subcategories-with-featured-topics.hbs b/app/assets/javascripts/discourse/app/components/subcategories-with-featured-topics.hbs index c8159b74c7b..9629c4caea5 100644 --- a/app/assets/javascripts/discourse/app/components/subcategories-with-featured-topics.hbs +++ b/app/assets/javascripts/discourse/app/components/subcategories-with-featured-topics.hbs @@ -13,7 +13,7 @@ - {{#each category.subcategories as |subCategory|}} + {{#each category.serializedSubcategories as |subCategory|}} {{else}} {{! No subcategories... so just show the parent to avoid confusion }} diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.js index 77b65481613..1abe3ec1a50 100644 --- a/app/assets/javascripts/discourse/app/models/category.js +++ b/app/assets/javascripts/discourse/app/models/category.js @@ -6,6 +6,7 @@ import { NotificationLevels } from "discourse/lib/notification-levels"; import PermissionType from "discourse/models/permission-type"; import RestModel from "discourse/models/rest"; import Site from "discourse/models/site"; +import Topic from "discourse/models/topic"; import User from "discourse/models/user"; import { getOwnerWithFallback } from "discourse-common/lib/get-owner"; import getURL from "discourse-common/lib/get-url"; @@ -459,6 +460,11 @@ export default class Category extends RestModel { return this.site.categories.filterBy("parent_category_id", this.id); } + @computed("subcategory_list") + get serializedSubcategories() { + return this.subcategory_list?.map((c) => Category.create(c)); + } + @discourseComputed("required_tag_groups", "minimum_required_tags") minimumRequiredTags() { if (this.required_tag_groups?.length > 0) { @@ -759,7 +765,9 @@ export default class Category extends RestModel { @discourseComputed("topics") featuredTopics(topics) { if (topics && topics.length) { - return topics.slice(0, this.num_featured_topics || 2); + return topics + .slice(0, this.num_featured_topics || 2) + .map((t) => Topic.create(t)); } } diff --git a/app/assets/javascripts/discourse/tests/fixtures/discovery-fixtures.js b/app/assets/javascripts/discourse/tests/fixtures/discovery-fixtures.js index 796875aed70..63cee0d60c7 100644 --- a/app/assets/javascripts/discourse/tests/fixtures/discovery-fixtures.js +++ b/app/assets/javascripts/discourse/tests/fixtures/discovery-fixtures.js @@ -1554,6 +1554,27 @@ export default { description_excerpt: "Discussion about features or potential features of Discourse: how they work, why they work, etc.", featured_user_ids: [1917, 4385, 2072, 32, 4263], + subcategory_list: [ + { + id: 26, + name: "spec", + color: "33B0B0", + text_color: "FFFFFF", + slug: "spec", + topic_count: 20, + post_count: 278, + description: + "My idea here is to have mini specs for features we would like built but have no bandwidth to build", + description_text: + "My idea here is to have mini specs for features we would like built but have no bandwidth to build", + topic_url: "/t/about-the-spec-category/13965", + read_restricted: false, + permission: 1, + parent_category_id: 2, + notification_level: null, + background_url: null, + }, + ], topics: [ { id: 11997,