Skip to content

Commit

Permalink
Show the menu when topic isn't assigned but there are assigned posts
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPrigorshnev committed Mar 20, 2024
1 parent 7f2190f commit 2824e5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ function defaultTitle(topic) {
}
}

function includeIsAssignedOnTopic(api) {
function extendTopicModel(api) {
api.modifyClass("model:topic", {
pluginId: PLUGIN_ID,
isAssigned() {
return this.assigned_to_user || this.assigned_to_group;
},

hasAssignedPosts() {
// fixme andrei implement
return true;
}
});
}

Expand Down Expand Up @@ -793,7 +798,7 @@ export default {
}

withPluginApi("0.13.0", (api) => {
includeIsAssignedOnTopic(api);
extendTopicModel(api);
initialize(api);
registerTopicFooterButtons(api);

Expand Down
27 changes: 15 additions & 12 deletions assets/javascripts/discourse/lib/topic-level-assign-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,22 @@ export default {
}
},
content() {
const content = [
unassignFromTopicButton(this.topic),
...unassignFromPostButtons(this.topic),
];
const content = [];

if (showReassignSelfButton(this.topic, this.currentUser)) {
content.push(reassignToSelfButton());
if (this.topic.isAssigned()) {
content.push(unassignFromTopicButton(this.topic));
}

if (this.topic.hasAssignedPosts()) {
content.push(...unassignFromPostButtons(this.topic));
}

if (this.topic.isAssigned()) {
if (showReassignSelfButton(this.topic, this.currentUser)) {
content.push(reassignToSelfButton());
}
content.push(reassignButton());
}
content.push(reassignButton());

return content;
},
Expand All @@ -106,7 +113,7 @@ export default {
return (
this.currentUser?.can_assign &&
!this.site.mobileView &&
this.topic.isAssigned()
(this.topic.isAssigned() || this.topic.hasAssignedPosts())
);
},
};
Expand Down Expand Up @@ -165,10 +172,6 @@ function unassignFromTopicButton(topic) {
}

function unassignFromPostButtons(topic) {
if (!topic.indirectly_assigned_to) {
return [];
}

return Object.entries(topic.indirectly_assigned_to).map(
([postId, assignment]) => unassignFromPostButton(postId, assignment)
);
Expand Down

0 comments on commit 2824e5f

Please sign in to comment.