A platform for community discussion. Free, open, simple.
DEV: remove category badge recursive (#35175)
David Battersby0c0296db6985
diff --git a/app/assets/javascripts/discourse/app/helpers/category-link.js b/app/assets/javascripts/discourse/app/helpers/category-link.jsindex cb87ec0f8ec..9105d780e14 100644--- a/app/assets/javascripts/discourse/app/helpers/category-link.js+++ b/app/assets/javascripts/discourse/app/helpers/category-link.js@@ -31,8 +31,6 @@ export function addExtraIconRenderer(renderer) {@param {Boolean} [opts.allowUncategorized] If false, returns an empty string for the uncategorized category.@param {Boolean} [opts.link] If false, the category badge will not be a link.@param {Boolean} [opts.hideParent] If true, parent category will be hidden in the badge.- @param {Boolean} [opts.recursive] If true, the function will be called recursively for all parent categories- @param {Number} [opts.depth] Current category depth, used for limiting recursive calls@param {Boolean} [opts.previewColor] If true, category color will be set as an inline style.@param {Array} [opts.ancestors] The ancestors of the category to generate the badge for.@param {String} [opts.styleType] Badge style, either "icon", "emoji" or "square" (default).@@ -62,14 +60,11 @@ export function categoryBadgeHTML(category, opts) {}}- // allow each ancestor to use its own styles- const newOpts = { ...opts };- ["styleType", "icon", "emoji"].forEach((k) => delete newOpts[k]);-- const depth = (opts.depth || 1) + 1;if (opts.ancestors) {- const { ancestors } = opts;- delete newOpts.ancestors;+ const { ancestors, ...newOpts } = opts;++ // allow each ancestor to use its own style+ ["styleType", "icon", "emoji"].forEach((k) => delete newOpts[k]);return [category, ...ancestors].reverse()@@ -77,16 +72,6 @@ export function categoryBadgeHTML(category, opts) {return categoryBadgeHTML(c, { ...newOpts });}).join("");- } else if (opts.recursive && depth <= siteSettings.max_category_nesting) {- const parentCategory = Category.findById(category.parent_category_id);- const lastSubcategory = !opts.depth;- opts.depth = depth;- const parentBadge = categoryBadgeHTML(parentCategory, {- depth,- ...newOpts,- });- opts.lastSubcategory = lastSubcategory;- return parentBadge + _renderer(category, opts);}return _renderer(category, opts);@@ -117,9 +102,6 @@ export function categoryLinkHTML(category, options) {if (options.hideParent) {categoryOptions.hideParent = true;}- if (options.recursive) {- categoryOptions.recursive = true;- }if (options.ancestors) {categoryOptions.ancestors = options.ancestors;}diff --git a/app/assets/javascripts/discourse/tests/unit/lib/category-badge-test.js b/app/assets/javascripts/discourse/tests/unit/lib/category-badge-test.jsindex 796fcd43ec1..0ba0e122dc2 100644--- a/app/assets/javascripts/discourse/tests/unit/lib/category-badge-test.js+++ b/app/assets/javascripts/discourse/tests/unit/lib/category-badge-test.js@@ -111,46 +111,6 @@ module("Unit | Utility | category-badge", function (hooks) {assert.strictEqual(dirSpan.dir, "auto");});- test("recursive", function (assert) {- const store = getOwner(this).lookup("service:store");- const siteSettings = getOwner(this).lookup("service:site-settings");-- const foo = store.createRecord("category", {- name: "foo",- id: 1,- });-- const bar = store.createRecord("category", {- name: "bar",- id: 2,- parent_category_id: foo.id,- });-- const baz = store.createRecord("category", {- name: "baz",- id: 3,- parent_category_id: bar.id,- });-- siteSettings.max_category_nesting = 0;- assert.true(categoryBadgeHTML(baz, { recursive: true }).includes("baz"));- assert.false(categoryBadgeHTML(baz, { recursive: true }).includes("bar"));-- siteSettings.max_category_nesting = 1;- assert.true(categoryBadgeHTML(baz, { recursive: true }).includes("baz"));- assert.false(categoryBadgeHTML(baz, { recursive: true }).includes("bar"));-- siteSettings.max_category_nesting = 2;- assert.true(categoryBadgeHTML(baz, { recursive: true }).includes("baz"));- assert.true(categoryBadgeHTML(baz, { recursive: true }).includes("bar"));- assert.false(categoryBadgeHTML(baz, { recursive: true }).includes("foo"));-- siteSettings.max_category_nesting = 3;- assert.true(categoryBadgeHTML(baz, { recursive: true }).includes("baz"));- assert.true(categoryBadgeHTML(baz, { recursive: true }).includes("bar"));- assert.true(categoryBadgeHTML(baz, { recursive: true }).includes("foo"));- });-test("category style types", function (assert) {const store = getOwner(this).lookup("service:store");const category = store.createRecord("category", { name: "hello", id: 123 });diff --git a/app/assets/javascripts/select-kit/addon/components/category-row.gjs b/app/assets/javascripts/select-kit/addon/components/category-row.gjsindex d6b2eeddd94..5cf750badbc 100644--- a/app/assets/javascripts/select-kit/addon/components/category-row.gjs+++ b/app/assets/javascripts/select-kit/addon/components/category-row.gjs@@ -124,7 +124,8 @@ export default class CategoryRow extends Component {link: false,allowUncategorized:this.allowUncategorizedTopics || this.allowUncategorized,- hideParent: !!this.parentCategory,+ hideParent: true,+ ancestors: this.category?.predecessors,topicCount: this.topicCount,subcategoryCount: this.args.item?.category? this.category.subcategory_count@@ -134,22 +135,6 @@ export default class CategoryRow extends Component {);}- @cached- get badgeForParentCategory() {- return htmlSafe(- categoryBadgeHTML(this.parentCategory, {- link: false,- allowUncategorized:- this.allowUncategorizedTopics || this.allowUncategorized,- recursive: true,- })- );- }-- get parentCategory() {- return Category.findById(this.parentCategoryId);- }-get hasParentCategory() {return this.parentCategoryId;}@@ -317,11 +302,6 @@ export default class CategoryRow extends Component {{{#if this.category}}<div class="category-status">- {{#if this.hasParentCategory}}- {{#unless this.hideParentCategory}}- {{this.badgeForParentCategory}}- {{/unless}}- {{/if}}{{this.badgeForCategory}}</div>diff --git a/app/assets/javascripts/select-kit/addon/components/none-category-row.gjs b/app/assets/javascripts/select-kit/addon/components/none-category-row.gjsindex 9c65beae496..8346c152667 100644--- a/app/assets/javascripts/select-kit/addon/components/none-category-row.gjs+++ b/app/assets/javascripts/select-kit/addon/components/none-category-row.gjs@@ -14,6 +14,7 @@ export default class NoneCategoryRow extends CategoryRowComponent {link: false,allowUncategorized: true,hideParent: true,+ ancestors: category?.predecessors,}));}@@ -21,11 +22,6 @@ export default class NoneCategoryRow extends CategoryRowComponent {<template>{{#if this.category}}<div class="category-status" aria-hidden="true">- {{#if this.hasParentCategory}}- {{#unless this.hideParentCategory}}- {{this.badgeForParentCategory}}- {{/unless}}- {{/if}}{{this.badgeForCategory}}</div>