mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 12:08:12 -05:00
DEV: remove category badge recursive (#35175)
Cleanup task to remove the recursive option from the category link helper. This was mostly replaced with the additional of the `ancestors` option in #26638, this PR removes the last instance of where it was used and removes it from the helper.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user