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

Commit e51ed45

Browse files
committed
UX: update for new core tag separator
1 parent 6a83db6 commit e51ed45

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
@@ -23,6 +23,7 @@ import BulkActionsAssignUser from "../components/bulk-actions/bulk-assign-user";
2323
import EditTopicAssignments from "../components/modal/edit-topic-assignments";
2424
import TopicLevelAssignMenu from "../components/topic-level-assign-menu";
2525
import { extendTopicModel } from "../models/topic";
26+
import { applyValueTransformer } from "discourse/lib/transformer";
2627

2728
const DEPENDENT_KEYS = [
2829
"topic.assigned_to_user",
@@ -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)