A platform for community discussion. Free, open, simple.
UX: make each assign tag a separate list item (#43492)
Kris17b4e2cfa3ba
diff --git a/frontend/discourse/app/lib/render-tags.js b/frontend/discourse/app/lib/render-tags.jsindex 18ed857ccdd..456562b5a74 100644--- a/frontend/discourse/app/lib/render-tags.js+++ b/frontend/discourse/app/lib/render-tags.js@@ -62,7 +62,9 @@ export default function (topic, params) {if (callbacks && topic) {callbacks.forEach((c) => {const html = c(topic, params);- if (html) {+ if (Array.isArray(html)) {+ callbackResults.push(...html.filter(Boolean));+ } else if (html) {callbackResults.push(html);}});diff --git a/frontend/discourse/tests/unit/lib/render-tags-test.js b/frontend/discourse/tests/unit/lib/render-tags-test.jsindex dea58079e9d..575fe29bf57 100644--- a/frontend/discourse/tests/unit/lib/render-tags-test.js+++ b/frontend/discourse/tests/unit/lib/render-tags-test.js@@ -1,11 +1,16 @@import EmberObject from "@ember/object";import { setupTest } from "ember-qunit";import { module, test } from "qunit";-import renderTags from "discourse/lib/render-tags";+import renderTags, {+ addTagsHtmlCallback,+ clearTagsHtmlCallbacks,+} from "discourse/lib/render-tags";module("Unit | Utility | render-tags", function (hooks) {setupTest(hooks);+ hooks.afterEach(() => clearTagsHtmlCallbacks());+test("renderTags with tagClasses param", function (assert) {const topic = EmberObject.create({tags: ["cat", "dog"],@@ -38,4 +43,50 @@ module("Unit | Utility | render-tags", function (hooks) {"adds the woof class to the dog tag");});++ test("callback returning an array renders each item as its own li", function (assert) {+ addTagsHtmlCallback(() => ["<a>one</a>", "<a>two</a>", "<a>three</a>"]);++ const topic = EmberObject.create({+ tags: [],+ get(prop) {+ return this[prop];+ },+ });++ const result = renderTags(topic, {});+ const div = document.createElement("div");+ div.innerHTML = result;++ const items = div.querySelectorAll(".discourse-tags > li");+ assert.strictEqual(items.length, 3, "each array item gets its own li");+ assert.strictEqual(items[0].querySelector("a").textContent, "one");+ assert.strictEqual(items[1].querySelector("a").textContent, "two");+ assert.strictEqual(items[2].querySelector("a").textContent, "three");+ assert.dom(".discourse-tags__tag-separator", items[0]).exists();+ assert.dom(".discourse-tags__tag-separator", items[1]).exists();+ assert.dom(".discourse-tags__tag-separator", items[2]).doesNotExist();+ });++ test("callback returning an array alongside regular tags", function (assert) {+ addTagsHtmlCallback(() => ["<a>one</a>", "<a>two</a>"]);++ const topic = EmberObject.create({+ tags: ["alpha", "beta"],+ get(prop) {+ return this[prop];+ },+ });++ const result = renderTags(topic, {});+ const div = document.createElement("div");+ div.innerHTML = result;++ const items = div.querySelectorAll(".discourse-tags > li");+ assert.strictEqual(items.length, 4, "tags and array items each own li");+ assert.dom('[data-tag-name="alpha"]', items[0]).exists();+ assert.dom('[data-tag-name="beta"]', items[1]).exists();+ assert.strictEqual(items[2].querySelector("a").textContent, "one");+ assert.strictEqual(items[3].querySelector("a").textContent, "two");+ });});diff --git a/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js b/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.jsindex f8b0acb3554..2429683de68 100644--- a/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js+++ b/plugins/discourse-assign/assets/javascripts/discourse/initializers/extend-for-assigns.js@@ -4,7 +4,6 @@ import getURL from "discourse/lib/get-url";import { iconHTML } from "discourse/lib/icon-library";import { withPluginApi } from "discourse/lib/plugin-api";import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer-dropdown";-import { applyValueTransformer } from "discourse/lib/transformer";import { escapeExpression } from "discourse/lib/utilities";import { renderAvatar } from "discourse/ui-kit/helpers/d-user-avatar";import { i18n } from "discourse-i18n";@@ -415,27 +414,7 @@ function initialize(api) {)}">${escapeExpression(name)}</span></${tagName}>`;};- // is there's one assignment just return the tag- if (assignedTo.length === 1) {- return createTagHtml(assignedTo[0]);- }-- // join multiple assignments with a separator- let result = "";- assignedTo.forEach((assignment, index) => {- result += createTagHtml(assignment);-- // add separator if not the last tag- if (index < assignedTo.length - 1) {- const separator = applyValueTransformer("tag-separator", ",", {- topic,- index,- });- result += `<span class="discourse-tags__tag-separator">${separator}</span>`;- }- });-- return result;+ return assignedTo.map((assignment) => createTagHtml(assignment));});api.addModelSaveProperty("group", "assignable_level");diff --git a/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js b/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.jsindex 102a9b6dd0a..bd6da542c8a 100644--- a/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js+++ b/plugins/discourse-assign/test/javascripts/acceptance/assigned-topic-test.js@@ -125,6 +125,12 @@ acceptance("Assigned topic", function (needs) {'<script>alert("xss")</script>',"shows indirect assign notes");+ assert+ .dom(".discourse-tags > li:has(.assigned-to)")+ .exists(+ { count: 2 },+ "user and group assignment each render in their own li"+ );assert.dom("#topic-footer-dropdown-reassign").exists("shows reassign dropdown at the bottom of the topic");