FIX: improvements for assign to post (#258)

1. When post is assigned to current user, unassign icon is not hidden
2. Link under names lead to topic (when topic assignment) and to post (when post assignment)
This commit is contained in:
Krzysztof Kotlarek 2021-12-01 08:54:13 +11:00 committed by GitHub
parent a9a427150e
commit 91d0712b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 17 deletions

View File

@ -443,7 +443,10 @@ function initialize(api) {
icon: "user-times",
className: "unassign-post",
title: "discourse_assign.unassign_post.title",
position: "second-last-hidden",
position:
post.assigned_to_user?.id === api.getCurrentUser().id
? "first"
: "second-last-hidden",
};
} else {
return {
@ -568,24 +571,23 @@ function initialize(api) {
api.addDiscoveryQueryParam("assigned", { replace: true, refreshModel: true });
api.addTagsHtmlCallback((topic, params = {}) => {
const [
assignedToUser,
assignedToGroup,
assignedToIndirectly,
] = Object.values(
topic.getProperties(
"assigned_to_user",
"assigned_to_group",
"indirectly_assigned_to"
)
const [assignedToUser, assignedToGroup] = Object.values(
topic.getProperties("assigned_to_user", "assigned_to_group")
);
let assignedToIndirectly;
if (topic.get("indirectly_assigned_to")) {
assignedToIndirectly = Object.entries(
topic.get("indirectly_assigned_to")
).map(([key, value]) => {
value.assignedToPostId = key;
return value;
});
} else {
assignedToIndirectly = [];
}
const assignedTo = []
.concat(
assignedToUser,
assignedToGroup,
assignedToIndirectly ? Object.values(assignedToIndirectly) : []
)
.concat(assignedToUser, assignedToGroup, assignedToIndirectly)
.filter((element) => element)
.flat()
.uniqBy((assignee) => assignee.assign_path);
@ -593,7 +595,12 @@ function initialize(api) {
if (assignedTo) {
return assignedTo
.map((assignee) => {
const assignedPath = getURL(assignee.assign_path);
let assignedPath;
if (assignee.assignedToPostId) {
assignedPath = `/p/${assignee.assignedToPostId}`;
} else {
assignedPath = `/t/${topic.id}`;
}
const icon = iconHTML(assignee.assign_icon);
const name = assignee.username || assignee.name;
const tagName = params.tagName || "a";