Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit cdfa3a6

Browse files
authored
UX: update for new core tag separator (#639)
1 parent 6a83db6 commit cdfa3a6

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

assets/javascripts/discourse/initializers/extend-for-assigns.js

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import getURL from "discourse/lib/get-url";
1111
import { iconHTML, iconNode } from "discourse/lib/icon-library";
1212
import { withPluginApi } from "discourse/lib/plugin-api";
1313
import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer-dropdown";
14+
import { applyValueTransformer } from "discourse/lib/transformer";
1415
import { escapeExpression } from "discourse/lib/utilities";
1516
import RawHtml from "discourse/widgets/raw-html";
1617
import RenderGlimmer from "discourse/widgets/render-glimmer";
@@ -467,28 +468,52 @@ function initialize(api) {
467468
.filter(({ assignee }) => assignee)
468469
.flat();
469470

470-
if (assignedTo) {
471-
return assignedTo
472-
.map(({ assignee, note }) => {
473-
let assignedPath;
474-
if (assignee.assignedToPostId) {
475-
assignedPath = `/p/${assignee.assignedToPostId}`;
476-
} else {
477-
assignedPath = `/t/${topic.id}`;
478-
}
479-
const icon = iconHTML(assignee.username ? "user-plus" : "group-plus");
480-
const name = assignee.username || assignee.name;
481-
const tagName = params.tagName || "a";
482-
const href =
483-
tagName === "a"
484-
? `href="${getURL(assignedPath)}" data-auto-route="true"`
485-
: "";
486-
return `<${tagName} class="assigned-to discourse-tag simple" ${href}>${icon}<span title="${escapeExpression(
487-
note
488-
)}">${name}</span></${tagName}>`;
489-
})
490-
.join("");
471+
if (!assignedTo) {
472+
return "";
473+
}
474+
475+
const createTagHtml = ({ assignee, note }) => {
476+
let assignedPath;
477+
if (assignee.assignedToPostId) {
478+
assignedPath = `/p/${assignee.assignedToPostId}`;
479+
} else {
480+
assignedPath = `/t/${topic.id}`;
481+
}
482+
483+
const icon = iconHTML(assignee.username ? "user-plus" : "group-plus");
484+
const name = assignee.username || assignee.name;
485+
const tagName = params.tagName || "a";
486+
const href =
487+
tagName === "a"
488+
? `href="${getURL(assignedPath)}" data-auto-route="true"`
489+
: "";
490+
491+
return `<${tagName} class="assigned-to discourse-tag simple" ${href}>${icon}<span title="${escapeExpression(
492+
note
493+
)}">${name}</span></${tagName}>`;
494+
};
495+
496+
// is there's one assignment just return the tag
497+
if (assignedTo.length === 1) {
498+
return createTagHtml(assignedTo[0]);
491499
}
500+
501+
// join multiple assignments with a separator
502+
let result = "";
503+
assignedTo.forEach((assignment, index) => {
504+
result += createTagHtml(assignment);
505+
506+
// add separator if not the last tag
507+
if (index < assignedTo.length - 1) {
508+
const separator = applyValueTransformer("tag-separator", ",", {
509+
topic,
510+
index,
511+
});
512+
result += `<span class="discourse-tags__tag-separator">${separator}</span>`;
513+
}
514+
});
515+
516+
return result;
492517
});
493518

494519
api.createWidget("assigned-to-post", {

0 commit comments

Comments
 (0)