-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Changes for new bulk action dropdown modal (#553)
When the new bulk actions dropdown is enabled use a new component for bulk assigning. Co-authored-by: Martin Brennan <[email protected]>
- Loading branch information
1 parent
c696e44
commit ed059d3
Showing
6 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
assets/javascripts/discourse/components/bulk-actions/bulk-assign-user.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,37 @@ | ||
import Component from "@glimmer/component"; | ||
import { action } from "@ember/object"; | ||
import didInsert from "@ember/render-modifiers/modifiers/did-insert"; | ||
import { TrackedObject } from "@ember-compat/tracked-built-ins"; | ||
import AssignUserForm from "discourse/plugins/discourse-assign/discourse/components/assign-user-form"; | ||
|
||
export default class BulkActionsAssignUser extends Component { | ||
model = new TrackedObject({}); | ||
|
||
formApi = { | ||
submit() {}, | ||
}; | ||
|
||
@action | ||
async assign(performAndRefreshCallback) { | ||
return performAndRefreshCallback({ | ||
type: "assign", | ||
username: this.model.username, | ||
status: this.model.status, | ||
note: this.model.note, | ||
}); | ||
} | ||
|
||
@action | ||
performRegistration() { | ||
this.args.onRegisterAction?.(this.assign.bind(this)); | ||
} | ||
|
||
<template> | ||
<span {{didInsert this.performRegistration}}></span> | ||
<AssignUserForm | ||
@model={{this.model}} | ||
@onSubmit={{this.assign}} | ||
@formApi={{this.formApi}} | ||
/> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
describe "Assign | Bulk Assign", type: :system do | ||
let(:topic_page) { PageObjects::Pages::Topic.new } | ||
let(:assign_modal) { PageObjects::Modals::Assign.new } | ||
let(:topic_list_header) { PageObjects::Components::TopicListHeader.new } | ||
let(:topic_list) { PageObjects::Components::TopicList.new } | ||
fab!(:staff_user) { Fabricate(:user, groups: [Group[:staff]]) } | ||
fab!(:admin) | ||
fab!(:topics) { Fabricate.times(10, :post).map(&:topic) } | ||
|
||
before do | ||
SiteSetting.assign_enabled = true | ||
SiteSetting.experimental_topic_bulk_actions_enabled_groups = "1" | ||
|
||
sign_in(admin) | ||
end | ||
|
||
describe "from topic list" do | ||
it "can assign and unassign topics" do | ||
## Assign | ||
visit "/latest" | ||
topic = topics.first | ||
|
||
# Select Topic | ||
topic_list_header.click_bulk_select_button | ||
topic_list.click_topic_checkbox(topic) | ||
|
||
# Click Assign Button | ||
topic_list_header.click_bulk_select_topics_dropdown | ||
expect(topic_list_header).to have_assign_topics_button | ||
topic_list_header.click_assign_topics_button | ||
expect(topic_list_header).to have_bulk_select_modal | ||
|
||
# Assign User | ||
assignee = staff_user.username | ||
select_kit = PageObjects::Components::SelectKit.new("#assignee-chooser") | ||
|
||
# This initial collapse is needed because for some reason the modal is | ||
# opening with `is-expanded` property, but it isn't actually expanded. | ||
select_kit.collapse | ||
|
||
select_kit.expand_if_needed | ||
select_kit.search(assignee) | ||
select_kit.select_row_by_value(assignee) | ||
select_kit.collapse | ||
|
||
# Click Confirm | ||
topic_list_header.click_bulk_topics_confirm | ||
|
||
# Reload and check that topic is now assigned | ||
visit "/latest" | ||
expect(topic_list).to have_assigned_status(topic) | ||
|
||
## Unassign | ||
|
||
# Select Topic | ||
topic_list_header.click_bulk_select_button | ||
topic_list.click_topic_checkbox(topic) | ||
|
||
# Click Unassign Button | ||
topic_list_header.click_bulk_select_topics_dropdown | ||
expect(topic_list_header).to have_unassign_topics_button | ||
topic_list_header.click_unassign_topics_button | ||
expect(topic_list_header).to have_bulk_select_modal | ||
|
||
# Click Confirm | ||
topic_list_header.click_bulk_topics_confirm | ||
|
||
# Reload and check that topic is now assigned | ||
visit "/latest" | ||
expect(topic_list).to have_unassigned_status(topic) | ||
end | ||
end | ||
end |
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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module PageObjects | ||
module Components | ||
class TopicList < PageObjects::Components::Base | ||
def has_assigned_status?(topic) | ||
page.has_css?("#{topic_list_item_assigned(topic)}") | ||
end | ||
|
||
def has_unassigned_status?(topic) | ||
page.has_no_css?("#{topic_list_item_assigned(topic)}") | ||
end | ||
|
||
private | ||
|
||
def topic_list_item_assigned(topic) | ||
"#{topic_list_item_class(topic)} .discourse-tags a.assigned-to" | ||
end | ||
end | ||
end | ||
end |
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module PageObjects | ||
module Components | ||
class TopicListHeader < PageObjects::Components::Base | ||
def has_assign_topics_button? | ||
page.has_css?(bulk_select_dropdown_item("topics.bulk.assign")) | ||
end | ||
|
||
def click_assign_topics_button | ||
find(bulk_select_dropdown_item("topics.bulk.assign")).click | ||
end | ||
|
||
def has_unassign_topics_button? | ||
page.has_css?(bulk_select_dropdown_item("topics.bulk.unassign")) | ||
end | ||
|
||
def click_unassign_topics_button | ||
find(bulk_select_dropdown_item("topics.bulk.unassign")).click | ||
end | ||
end | ||
end | ||
end |