FEATURE: Add more bulk dismiss buttons with confirmation (#29331)

When performing bulk dismissal in Unread and New views, the dismiss button stays at the top of the UI. Because of this we want to provide the dismiss action also in the "sticky" menu that's always in view, even when scrolling a long list of topics.
This commit is contained in:
Ted Johansson 2024-11-08 15:59:12 +08:00 committed by GitHub
parent 467ecbabf5
commit f573fd8f5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 92 additions and 0 deletions

View File

@ -7,6 +7,8 @@ import DropdownMenu from "discourse/components/dropdown-menu";
import BulkTopicActions, { import BulkTopicActions, {
addBulkDropdownAction, addBulkDropdownAction,
} from "discourse/components/modal/bulk-topic-actions"; } from "discourse/components/modal/bulk-topic-actions";
import DismissNew from "discourse/components/modal/dismiss-new";
import DismissReadModal from "discourse/components/modal/dismiss-read";
import concatClass from "discourse/helpers/concat-class"; import concatClass from "discourse/helpers/concat-class";
import icon from "discourse-common/helpers/d-icon"; import icon from "discourse-common/helpers/d-icon";
import i18n from "discourse-common/helpers/i18n"; import i18n from "discourse-common/helpers/i18n";
@ -35,12 +37,25 @@ export function addBulkDropdownButton(opts) {
} }
export default class BulkSelectTopicsDropdown extends Component { export default class BulkSelectTopicsDropdown extends Component {
@service router;
@service modal; @service modal;
@service currentUser; @service currentUser;
@service siteSettings; @service siteSettings;
get buttons() { get buttons() {
let options = [ let options = [
{
id: "dismiss-unread",
icon: "check",
name: i18n("topic_bulk_actions.dismiss.name"),
visible: ({ router }) => router.currentRouteName === "discovery.unread",
},
{
id: "dismiss-new",
icon: "check",
name: i18n("topic_bulk_actions.dismiss.name"),
visible: ({ router }) => router.currentRouteName === "discovery.new",
},
{ {
id: "update-category", id: "update-category",
icon: "pencil", icon: "pencil",
@ -139,6 +154,7 @@ export default class BulkSelectTopicsDropdown extends Component {
topics: this.args.bulkSelectHelper.selected, topics: this.args.bulkSelectHelper.selected,
currentUser: this.currentUser, currentUser: this.currentUser,
siteSettings: this.siteSettings, siteSettings: this.siteSettings,
router: this.router,
}); });
} else { } else {
return true; return true;
@ -186,6 +202,23 @@ export default class BulkSelectTopicsDropdown extends Component {
await this.dMenu.close(); await this.dMenu.close();
switch (actionId) { switch (actionId) {
case "dismiss-unread":
this.modal.show(DismissReadModal, {
model: {
title: "topics.bulk.dismiss_read_with_selected",
count: this.args.bulkSelectHelper.selected.length,
dismissRead: (dismissTopics) => this.dismissRead(dismissTopics),
},
});
break;
case "dismiss-new":
this.modal.show(DismissNew, {
model: {
selectedTopics: this.args.bulkSelectHelper.selected,
dismissCallback: (dismissTopics) => this.dismissRead(dismissTopics),
},
});
break;
case "update-category": case "update-category":
this.showBulkTopicActionsModal(actionId, "change_category", { this.showBulkTopicActionsModal(actionId, "change_category", {
description: i18n(`topic_bulk_actions.update_category.description`), description: i18n(`topic_bulk_actions.update_category.description`),
@ -257,6 +290,10 @@ export default class BulkSelectTopicsDropdown extends Component {
} }
} }
dismissRead(stopTracking) {
this.args.bulkSelectHelper.dismissRead(stopTracking ? "topics" : "posts");
}
@action @action
onRegisterApi(api) { onRegisterApi(api) {
this.dMenu = api; this.dMenu = api;

View File

@ -70,6 +70,10 @@
padding: 1rem 1.5rem; padding: 1rem 1.5rem;
box-sizing: border-box; box-sizing: border-box;
&.empty {
display: none;
}
input { input {
width: auto; width: auto;

View File

@ -3218,6 +3218,8 @@ en:
filter: "There are no more topics." filter: "There are no more topics."
topic_bulk_actions: topic_bulk_actions:
dismiss:
name: "Dismiss"
close_topics: close_topics:
name: "Close" name: "Close"
note: "Note" note: "Note"

View File

@ -12,6 +12,10 @@ module PageObjects
find("#bulk-topics-confirm").click find("#bulk-topics-confirm").click
end end
def click_dismiss_confirm
find("#dismiss-read-confirm").click
end
def click_silent def click_silent
find("#topic-bulk-action-options__silent").click find("#topic-bulk-action-options__silent").click
end end

View File

@ -24,6 +24,51 @@ describe "Topic bulk select", type: :system do
expect(topic_bulk_actions_modal).to be_open expect(topic_bulk_actions_modal).to be_open
end end
context "when dismissing unread topics" do
fab!(:topic) { Fabricate(:topic, user: admin) }
fab!(:post1) { create_post(user: admin, topic: topic) }
fab!(:post2) { create_post(topic: topic) }
it "removes the topics from the list" do
sign_in(admin)
visit("/unread")
topic_list_header.click_bulk_select_button
expect(topic_list).to have_topic_checkbox(topic)
topic_list.click_topic_checkbox(topic)
topic_list_header.click_bulk_select_topics_dropdown
topic_list_header.click_bulk_button("dismiss-unread")
topic_bulk_actions_modal.click_dismiss_confirm
expect(page).to have_text(I18n.t("js.topics.none.unread"))
end
end
context "when dismissing new topics" do
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:post1) { create_post(user: user, topic: topic) }
it "removes the topics from the list" do
sign_in(admin)
visit("/new")
topic_list_header.click_bulk_select_button
expect(topic_list).to have_topic_checkbox(topic)
topic_list.click_topic_checkbox(topic)
topic_list_header.click_bulk_select_topics_dropdown
topic_list_header.click_bulk_button("dismiss-new")
topic_bulk_actions_modal.click_dismiss_confirm
expect(page).to have_text(I18n.t("js.topics.none.new"))
end
end
context "when appending tags" do context "when appending tags" do
fab!(:tag1) { Fabricate(:tag) } fab!(:tag1) { Fabricate(:tag) }
fab!(:tag2) { Fabricate(:tag) } fab!(:tag2) { Fabricate(:tag) }