A platform for community discussion. Free, open, simple.
FEATURE: Add message to bulk close topics (#26535)
Blake Erickson8da49b566418
diff --git a/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs b/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjsindex b5894646fe5..0e4d2987408 100644--- a/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs+++ b/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs@@ -1,6 +1,7 @@import Component from "@glimmer/component";import { tracked } from "@glimmer/tracking";import { Input } from "@ember/component";+import { on } from "@ember/modifier";import { action, computed } from "@ember/object";import { service } from "@ember/service";import { Promise } from "rsvp";@@ -10,6 +11,7 @@ import DModal from "discourse/components/d-modal";import RadioButton from "discourse/components/radio-button";import { topicLevels } from "discourse/lib/notification-levels";import Topic from "discourse/models/topic";+import autoFocus from "discourse/modifiers/auto-focus";import htmlSafe from "discourse-common/helpers/html-safe";import i18n from "discourse-common/helpers/i18n";import CategoryChooser from "select-kit/components/category-chooser";@@ -30,6 +32,7 @@ export default class BulkTopicActions extends Component {@tracked loading;@tracked errors;@tracked isSilent = false;+ @tracked closeNote = null;notificationLevelId = null;@@ -84,6 +87,10 @@ export default class BulkTopicActions extends Component {operation = { type: "silent_close" };}+ if (this.isCloseAction && this.closeNote) {+ operation["message"] = this.closeNote;+ }+const tasks = topicChunks.map((topics) => async () => {const result = await Topic.bulkOperation(topics, operation, options);this.processedTopicCount += topics.length;@@ -246,6 +253,17 @@ export default class BulkTopicActions extends Component {return this.args.model.action === "update-category";}+ @computed("action")+ get isCloseAction() {+ return this.args.model.action === "close";+ }++ @action+ updateCloseNote(event) {+ event.preventDefault();+ this.closeNote = event.target.value;+ }+get notificationLevels() {return topicLevels.map((level) => ({id: level.id.toString(),@@ -322,6 +340,22 @@ export default class BulkTopicActions extends Component {onRegisterAction=this.registerCustomAction}}{{/if}}++ {{#if this.isCloseAction}}+ <div class="bulk-close-note-section">+ <label>+ {{i18n "topic_bulk_actions.close_topics.note"}} <span+ class="label-optional"+ >{{i18n "topic_bulk_actions.close_topics.optional"}}</span>+ </label>++ <textarea+ id="bulk-close-note"+ {{on "input" this.updateCloseNote}}+ {{autoFocus}}+ >{{this.closeNote}}</textarea>+ </div>+ {{/if}}</ConditionalLoadingSection></:body>diff --git a/app/assets/stylesheets/common/modal/modal-overrides.scss b/app/assets/stylesheets/common/modal/modal-overrides.scssindex ce989b511d3..db219f56d7e 100644--- a/app/assets/stylesheets/common/modal/modal-overrides.scss+++ b/app/assets/stylesheets/common/modal/modal-overrides.scss@@ -230,6 +230,9 @@#bulk-topics-cancel {margin-left: auto;}+ .bulk-close-note-section {+ margin-top: 1em;+ }}.d-modal.edit-slow-mode-modal {diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 087dc15a6ef..c64e36c15b0 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -1010,6 +1010,7 @@ class TopicsController < ApplicationController:group,:category_id,:notification_level_id,+ :message,*DiscoursePluginRegistry.permitted_bulk_action_parameters,tags: [],)diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 2d5d7710217..f3fcac39e69 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3028,6 +3028,8 @@ en:topic_bulk_actions:close_topics:name: "Close Topics"+ note: "Note"+ optional: (optional)archive_topics:name: "Archive Topics"unlist_topics:diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rbindex 3226e71a418..97f02666974 100644--- a/lib/topics_bulk_action.rb+++ b/lib/topics_bulk_action.rb@@ -165,7 +165,7 @@ class TopicsBulkActiondef closetopics.each do |t|if guardian.can_moderate?(t)- t.update_status("closed", true, @user)+ t.update_status("closed", true, @user, { message: @operation[:message] })@changed_ids << t.idendend@@ -174,7 +174,7 @@ class TopicsBulkActiondef silent_closetopics.each do |t|if guardian.can_moderate?(t)- t.update_status("autoclosed", true, @user)+ t.update_status("autoclosed", true, @user, { message: @operation[:message] })@changed_ids << t.idendenddiff --git a/spec/system/page_objects/components/topic_list_header.rb b/spec/system/page_objects/components/topic_list_header.rbindex 81191c5ba14..79a96430984 100644--- a/spec/system/page_objects/components/topic_list_header.rb+++ b/spec/system/page_objects/components/topic_list_header.rb@@ -50,6 +50,10 @@ module PageObjectsfind("#topic-bulk-action-options__silent").clickend+ def fill_in_close_note(message)+ find("#bulk-close-note").set(message)+ end+def click_dismiss_read_confirmfind("#dismiss-read-confirm").clickenddiff --git a/spec/system/topic_bulk_select_spec.rb b/spec/system/topic_bulk_select_spec.rbindex 48073907c12..17d365c8a92 100644--- a/spec/system/topic_bulk_select_spec.rb+++ b/spec/system/topic_bulk_select_spec.rb@@ -88,6 +88,25 @@ describe "Topic bulk select", type: :system doexpect(topic_list).to have_no_unread_badge(topics.first)end+ it "closes topics with message" do+ # Bulk close the topic with a message+ sign_in(admin)+ visit("/latest")+ topic = topics.first+ topic_list_header.click_bulk_select_button+ topic_list.click_topic_checkbox(topics.first)+ topic_list_header.click_bulk_select_topics_dropdown+ topic_list_header.click_close_topics_button++ # Fill in message+ topic_list_header.fill_in_close_note("My message")+ topic_list_header.click_bulk_topics_confirm++ # Check that the topic now has the message+ visit("/t/#{topic.slug}/#{topic.id}")+ expect(topic_page).to have_content("My message")+ end+it "works with keyboard shortcuts" dosign_in(admin)visit("/latest")