A platform for community discussion. Free, open, simple.
UX: ensure read-only only appears once, on the relevant category (#37492)
Krisdd2663a88d7f
diff --git a/app/assets/stylesheets/common/select-kit/category-row.scss b/app/assets/stylesheets/common/select-kit/category-row.scssindex de91ba84790..d9ab777eb7a 100644--- a/app/assets/stylesheets/common/select-kit/category-row.scss+++ b/app/assets/stylesheets/common/select-kit/category-row.scss@@ -5,7 +5,7 @@.category-status {display: flex;- align-items: center;+ align-items: baseline;max-width: 100%;flex: 1 1 auto;gap: 0 0.5em;@@ -26,7 +26,7 @@}.read-only {- padding: 0.2em 0.5em;+ padding: 0.1em 0.5em;margin: 0 0 0.25em 0.5em;border-radius: 8px;color: var(--secondary);diff --git a/frontend/discourse/app/helpers/category-link.js b/frontend/discourse/app/helpers/category-link.jsindex 58a5a634835..d6a7c997691 100644--- a/frontend/discourse/app/helpers/category-link.js+++ b/frontend/discourse/app/helpers/category-link.js@@ -61,7 +61,7 @@ export function categoryBadgeHTML(category, opts) {}if (opts.ancestors) {- const { ancestors, ...newOpts } = opts;+ const { ancestors, readOnly, ...newOpts } = opts;// allow each ancestor to use its own style["styleType", "icon", "emoji"].forEach((k) => delete newOpts[k]);@@ -69,7 +69,10 @@ export function categoryBadgeHTML(category, opts) {return [category, ...ancestors].reverse().map((c) => {- return categoryBadgeHTML(c, { ...newOpts });+ return categoryBadgeHTML(c, {+ ...newOpts,+ ...(readOnly && c === category ? { readOnly } : {}),+ });}).join("");}diff --git a/frontend/discourse/tests/unit/lib/category-badge-test.js b/frontend/discourse/tests/unit/lib/category-badge-test.jsindex e00a5483f39..d17530c3033 100644--- a/frontend/discourse/tests/unit/lib/category-badge-test.js+++ b/frontend/discourse/tests/unit/lib/category-badge-test.js@@ -185,4 +185,34 @@ module("Unit | Utility | category-badge", function (hooks) {assert.true(badge.includes('data-category-id="1"'), "includes parent");assert.true(badge.includes('data-category-id="2"'), "includes child");});++ test("read-only badge appears only once with ancestors", function (assert) {+ const store = getOwner(this).lookup("service:store");++ const parent = store.createRecord("category", {+ name: "parent",+ id: 1,+ });+ const child = store.createRecord("category", {+ name: "child",+ id: 2,+ parent_category_id: parent.id,+ });++ const badge = categoryBadgeHTML(child, {+ ancestors: [parent],+ readOnly: true,+ });++ const readOnlyMatches = badge.match(/class="read-only"/g) || [];+ assert.strictEqual(+ readOnlyMatches.length,+ 1,+ "read-only badge appears exactly once"+ );+ assert.true(+ badge.includes("read-only"),+ "read-only badge is present in the output"+ );+ });});