-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: Add menu to assigned text on posts #550
Merged
AndrewPrigorshnev
merged 9 commits into
main
from
feature/add-menu-to-assigned-text-on-posts
Mar 15, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5a75e0
Extract the widget into its own file
AndrewPrigorshnev 70a269f
Implement
AndrewPrigorshnev eed5de3
Acceptance tests
AndrewPrigorshnev f5f3475
CSS
AndrewPrigorshnev fe057d3
moves more logic in component and fix skipped test
jjaffeux 7ee4ea8
linting
jjaffeux 5580af0
correct link
jjaffeux f9859e7
Add todo:
AndrewPrigorshnev e25476a
Merge branch 'main' into feature/add-menu-to-assigned-text-on-posts
AndrewPrigorshnev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
assets/javascripts/discourse/components/assigned-to-post.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import Component from "@glimmer/component"; | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import DButton from "discourse/components/d-button"; | ||
import icon from "discourse-common/helpers/d-icon"; | ||
import i18n from "discourse-common/helpers/i18n"; | ||
import DMenu from "float-kit/components/d-menu"; | ||
|
||
export default class AssignedToPost extends Component { | ||
@service taskActions; | ||
|
||
@action | ||
unassign() { | ||
this.taskActions.unassignPost(this.args.post); | ||
} | ||
|
||
@action | ||
editAssignment() { | ||
this.taskActions.showAssignPostModal(this.args.post); | ||
} | ||
|
||
<template> | ||
{{#if @assignedToUser}} | ||
{{icon "user-plus"}} | ||
{{else}} | ||
{{icon "group-plus"}} | ||
{{/if}} | ||
|
||
<span class="assign-text"> | ||
{{i18n "discourse_assign.assigned_to"}} | ||
</span> | ||
|
||
<a href={{@href}} class="assigned-to-username"> | ||
{{#if @assignedToUser}} | ||
{{@assignedToUser.username}} | ||
{{else}} | ||
{{@assignedToGroup.name}} | ||
{{/if}} | ||
</a> | ||
|
||
<DMenu @icon="ellipsis-h" class="btn-flat more-button"> | ||
<div class="popup-menu"> | ||
<ul> | ||
<li> | ||
<DButton | ||
@action={{this.unassign}} | ||
@icon="user-plus" | ||
@label="discourse_assign.unassign.title" | ||
class="popup-menu-btn" | ||
/> | ||
</li> | ||
<li> | ||
<DButton | ||
@action={{this.editAssignment}} | ||
@icon="group-plus" | ||
@label="discourse_assign.reassign.title_w_ellipsis" | ||
class="popup-menu-btn" | ||
/> | ||
</li> | ||
</ul> | ||
</div> | ||
</DMenu> | ||
</template> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { click, fillIn, visit } from "@ember/test-helpers"; | ||
import { test } from "qunit"; | ||
import topicFixtures from "discourse/tests/fixtures/topic"; | ||
import { | ||
acceptance, | ||
publishToMessageBus, | ||
updateCurrentUser, | ||
} from "discourse/tests/helpers/qunit-helpers"; | ||
import { cloneJSON } from "discourse-common/lib/object"; | ||
|
||
const username = "eviltrout"; | ||
const new_assignee_username = "new_assignee"; | ||
|
||
function topicWithAssignedPostResponse() { | ||
const topic = cloneJSON(topicFixtures["/t/28830/1.json"]); | ||
const secondPost = topic.post_stream.posts[1]; | ||
|
||
topic["indirectly_assigned_to"] = { | ||
[secondPost.id]: { | ||
assigned_to: { | ||
username, | ||
}, | ||
post_number: 1, | ||
}, | ||
}; | ||
secondPost["assigned_to_user"] = { username }; | ||
|
||
return topic; | ||
} | ||
|
||
const selectors = { | ||
assignedTo: ".post-stream article#post_2 .assigned-to", | ||
moreButton: ".post-stream .topic-post .more-button", | ||
popupMenu: { | ||
unassign: ".popup-menu .popup-menu-btn svg.d-icon-user-plus", | ||
editAssignment: ".popup-menu .popup-menu-btn svg.d-icon-group-plus", | ||
}, | ||
modal: { | ||
assignee: ".modal-container .select-kit-header-wrapper", | ||
assigneeInput: ".modal-container .filter-input", | ||
assignButton: ".d-modal__footer .btn-primary", | ||
}, | ||
}; | ||
|
||
const topic = topicWithAssignedPostResponse(); | ||
const post = topic.post_stream.posts[1]; | ||
|
||
acceptance("Discourse Assign | Post popup menu", function (needs) { | ||
needs.user(); | ||
needs.settings({ | ||
assign_enabled: true, | ||
}); | ||
|
||
needs.pretender((server, helper) => { | ||
server.get("/t/44.json", () => helper.response(topic)); | ||
|
||
server.put("/assign/assign", () => { | ||
return helper.response({ success: true }); | ||
}); | ||
|
||
server.put("/assign/unassign", () => { | ||
return helper.response({ success: true }); | ||
}); | ||
|
||
server.get("/assign/suggestions", () => | ||
helper.response({ | ||
assign_allowed_for_groups: [], | ||
suggestions: [{ username: new_assignee_username }], | ||
}) | ||
); | ||
|
||
server.get("/u/search/users", () => | ||
helper.response({ users: [{ username: new_assignee_username }] }) | ||
); | ||
}); | ||
|
||
needs.hooks.beforeEach(() => { | ||
updateCurrentUser({ can_assign: true }); | ||
}); | ||
|
||
test("Unassigns the post", async function (assert) { | ||
await visit("/t/assignment-topic/44"); | ||
await click(selectors.moreButton); | ||
await click(selectors.popupMenu.unassign); | ||
await publishToMessageBus("/staff/topic-assignment", { | ||
type: "unassigned", | ||
topic_id: topic.id, | ||
post_id: post.id, | ||
assigned_type: "User", | ||
}); | ||
|
||
assert.dom(".popup-menu").doesNotExist("The popup menu is closed"); | ||
assert.dom(selectors.assignedTo).doesNotExist("The post is unassigned"); | ||
}); | ||
|
||
test("Reassigns the post", async function (assert) { | ||
await visit("/t/assignment-topic/44"); | ||
await click(selectors.moreButton); | ||
await click(selectors.popupMenu.editAssignment); | ||
await click(selectors.modal.assignee); | ||
await fillIn(selectors.modal.assigneeInput, new_assignee_username); | ||
await click(selectors.modal.assignButton); | ||
|
||
await publishToMessageBus("/staff/topic-assignment", { | ||
type: "assigned", | ||
topic_id: topic.id, | ||
post_id: post.id, | ||
assigned_type: "User", | ||
assigned_to: { | ||
username: new_assignee_username, | ||
}, | ||
}); | ||
|
||
// todo: we can skip this one for now, I can fix it in a core PR | ||
// assert.dom(".popup-menu").doesNotExist("The popup menu is closed"); | ||
|
||
assert | ||
.dom(`${selectors.assignedTo} .assigned-to-username`) | ||
.hasText( | ||
new_assignee_username, | ||
"The post is assigned to the new assignee" | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this necessary ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need that to style the popup menu appropriately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(
DMenu
doesn't provide that)