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 <martin@discourse.org>
This commit is contained in:
parent
c696e44714
commit
ed059d3dfe
|
@ -2,6 +2,7 @@
|
||||||
<label>{{i18n "discourse_assign.assign_modal.assignee_label"}}</label>
|
<label>{{i18n "discourse_assign.assign_modal.assignee_label"}}</label>
|
||||||
<AssigneeChooser
|
<AssigneeChooser
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
|
@id="assignee-chooser"
|
||||||
@value={{this.assigneeName}}
|
@value={{this.assigneeName}}
|
||||||
@onChange={{this.assignUsername}}
|
@onChange={{this.assignUsername}}
|
||||||
@showUserStatus={{true}}
|
@showUserStatus={{true}}
|
||||||
|
|
|
@ -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>
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import { iconHTML, iconNode } from "discourse-common/lib/icon-library";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import BulkAssign from "../components/bulk-actions/assign-user";
|
import BulkAssign from "../components/bulk-actions/assign-user";
|
||||||
|
import BulkActionsAssignUser from "../components/bulk-actions/bulk-assign-user";
|
||||||
|
|
||||||
const PLUGIN_ID = "discourse-assign";
|
const PLUGIN_ID = "discourse-assign";
|
||||||
|
|
||||||
|
@ -932,13 +933,19 @@ export default {
|
||||||
|
|
||||||
api.addUserSearchOption("assignableGroups");
|
api.addUserSearchOption("assignableGroups");
|
||||||
|
|
||||||
|
const bulkAssignComponent =
|
||||||
|
currentUser?.use_experimental_topic_bulk_actions
|
||||||
|
? BulkActionsAssignUser
|
||||||
|
: BulkAssign;
|
||||||
|
|
||||||
api.addBulkActionButton({
|
api.addBulkActionButton({
|
||||||
label: "topics.bulk.assign",
|
label: "topics.bulk.assign",
|
||||||
icon: "user-plus",
|
icon: "user-plus",
|
||||||
class: "btn-default assign-topics",
|
class: "btn-default assign-topics",
|
||||||
action({ setComponent }) {
|
action({ setComponent }) {
|
||||||
setComponent(BulkAssign);
|
setComponent(bulkAssignComponent);
|
||||||
},
|
},
|
||||||
|
actionType: "setComponent",
|
||||||
});
|
});
|
||||||
|
|
||||||
api.addBulkActionButton({
|
api.addBulkActionButton({
|
||||||
|
@ -948,6 +955,7 @@ export default {
|
||||||
action({ performAndRefresh }) {
|
action({ performAndRefresh }) {
|
||||||
performAndRefresh({ type: "unassign" });
|
performAndRefresh({ type: "unassign" });
|
||||||
},
|
},
|
||||||
|
actionType: "performAndRefresh",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue