A platform for community discussion. Free, open, simple.
FIX: category badge hide parent with ancestors (#35734)
David Battersby01e7f2760739
diff --git a/frontend/discourse/tests/unit/lib/category-badge-test.js b/frontend/discourse/tests/unit/lib/category-badge-test.jsindex 0ba0e122dc2..2e1afa10511 100644--- a/frontend/discourse/tests/unit/lib/category-badge-test.js+++ b/frontend/discourse/tests/unit/lib/category-badge-test.js@@ -159,4 +159,29 @@ module("Unit | Utility | category-badge", function (hooks) {assert.true(badge.includes("d-icon-book"), "has parent with book icon");assert.true(badge.includes("d-icon-file"), "has child with file icon");});++ test("ancestors", function (assert) {+ const store = getOwner(this).lookup("service:store");+ let badge;++ const parent = store.createRecord("category", {+ name: "parent",+ id: 1,+ });+ const child = store.createRecord("category", {+ name: "child",+ id: 2,+ parent_category_id: parent.id,+ });++ badge = categoryBadgeHTML(child);+ assert.strictEqual((badge.match(/data-category-id/g) || []).length, 1);+ assert.false(badge.includes('data-category-id="1"'), "excludes parent");+ assert.true(badge.includes('data-category-id="2"'), "includes child");++ badge = categoryBadgeHTML(child, { ancestors: [parent] });+ assert.strictEqual((badge.match(/data-category-id/g) || []).length, 2);+ assert.true(badge.includes('data-category-id="1"'), "includes parent");+ assert.true(badge.includes('data-category-id="2"'), "includes child");+ });});diff --git a/frontend/select-kit/addon/components/category-row.gjs b/frontend/select-kit/addon/components/category-row.gjsindex 5cf750badbc..63047757231 100644--- a/frontend/select-kit/addon/components/category-row.gjs+++ b/frontend/select-kit/addon/components/category-row.gjs@@ -124,8 +124,8 @@ export default class CategoryRow extends Component {link: false,allowUncategorized:this.allowUncategorizedTopics || this.allowUncategorized,- hideParent: true,- ancestors: this.category?.predecessors,+ hideParent: !this.hasParentCategory,+ ancestors: this.hideParentCategory ? [] : this.category?.predecessors,topicCount: this.topicCount,subcategoryCount: this.args.item?.category? this.category.subcategory_count