From 91d0712b0440b6bb0c2fedbf6c31191cdeb991fe Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Wed, 1 Dec 2021 08:54:13 +1100 Subject: [PATCH] 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) --- .../initializers/extend-for-assigns.js.es6 | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 index f117c5b..bec3747 100644 --- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 +++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 @@ -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";