A platform for community discussion. Free, open, simple.
UX: adds create PM action option in composer's new topic mode (#35764)
Yuriy Kurante9fbf090e50d
diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 0fac7217b0e..84fd38de84b 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3097,6 +3097,9 @@ en:create_topic:label: "New Topic"desc: Create a new topic+ create_personal_message:+ label: "New message"+ desc: "Create a new personal message"shared_draft:label: "Shared Draft"desc: "Draft a topic that will only be visible to allowed users"diff --git a/frontend/discourse/tests/acceptance/composer-actions-test.js b/frontend/discourse/tests/acceptance/composer-actions-test.jsindex 16a34f875e6..1f48b3c884e 100644--- a/frontend/discourse/tests/acceptance/composer-actions-test.js+++ b/frontend/discourse/tests/acceptance/composer-actions-test.js@@ -250,7 +250,11 @@ import { i18n } from "discourse-i18n";composerActions.rowByIndex(3).value(),"shared_draft");- assert.strictEqual(composerActions.rows().length, 4);+ assert.strictEqual(+ composerActions.rowByIndex(4).value(),+ "create_private_message"+ );+ assert.strictEqual(composerActions.rows().length, 5);});test("interactions - private message", async function (assert) {diff --git a/frontend/select-kit/addon/components/composer-actions.js b/frontend/select-kit/addon/components/composer-actions.jsindex d68862f916b..6650cdb93bf 100644--- a/frontend/select-kit/addon/components/composer-actions.js+++ b/frontend/select-kit/addon/components/composer-actions.js@@ -249,6 +249,22 @@ export default class ComposerActions extends DropdownSelectBoxComponent {});}+ if (+ this.currentUser.can_send_private_messages &&+ this.action !== PRIVATE_MESSAGE &&+ this.action !== REPLY &&+ !this.isEditing+ ) {+ items.push({+ name: i18n("composer.composer_actions.create_personal_message.label"),+ description: i18n(+ "composer.composer_actions.create_personal_message.desc"+ ),+ icon: "envelope",+ id: "create_private_message",+ });+ }+return items;}@@ -382,6 +398,11 @@ export default class ComposerActions extends DropdownSelectBoxComponent {this._switchCreate(options, CREATE_SHARED_DRAFT);}+ createPrivateMessageSelected(options) {+ options.archetypeId = "private_message";+ this._switchCreate(options, PRIVATE_MESSAGE);+ }+@actiononChange(value) {const composerAction = `${camelize(value)}Selected`;diff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rbindex d22a166eee0..01be8feaa0b 100644--- a/spec/system/page_objects/components/composer.rb+++ b/spec/system/page_objects/components/composer.rb@@ -104,6 +104,10 @@ module PageObjectscomposer_popup.has_content?(content)end+ def has_no_action?(action)+ !actions.include?(action)+ end+def select_action(action)find(action(action)).clickself@@ -121,6 +125,10 @@ module PageObjects".composer-action-title .select-kit-collection li[title='#{action_title}']"end+ def actions+ all(".composer-action-title .select-kit-collection li").map { |el| el[:title] }+ end+def button_labelfind("#{@composer_id} .btn-primary .d-button-label")enddiff --git a/spec/system/private_message_spec.rb b/spec/system/private_message_spec.rbindex baad7ba5636..75ea2ac2c83 100644--- a/spec/system/private_message_spec.rb+++ b/spec/system/private_message_spec.rb@@ -1,23 +1,48 @@# frozen_string_literal: truedescribe "Private Message", type: :system do- let(:sender) { Fabricate(:user) }+ let(:sender) { Fabricate(:user, refresh_auto_groups: true) }let(:recipient) { Fabricate(:user) }-- let(:post) { Fabricate(:private_message_post, user: sender, recipient: recipient) }-- before { sign_in(recipient) }+ let(:pm_post) { Fabricate(:private_message_post, user: sender, recipient: recipient) }+ let(:pm_post_obj) { PageObjects::Components::Post.new(pm_post.post_number) }+ let(:composer) { PageObjects::Components::Composer.new }context "when being removed from private conversation" do+ before { sign_in(recipient) }+it "redirects away from the private message" do- visit(post.full_url)+ visit(pm_post.full_url)- expect(page).to have_css("h1", text: post.topic.title)+ expect(page).to have_css("h1", text: pm_post.topic.title)- post.topic.remove_allowed_user(sender, recipient)+ pm_post.topic.remove_allowed_user(sender, recipient)expect(page).to have_current_path("/u/#{recipient.username}/messages")- expect(page).to have_no_css("h1", text: post.topic.title)+ expect(page).to have_no_css("h1", text: pm_post.topic.title)+ end+ end++ context "for 'new personal message' action option in composer" do+ before { sign_in(sender) }++ it "should be available in new topic" do+ visit "/new-topic"+ expect(composer).to be_opened++ composer.open_composer_actions+ composer.select_action("New message")++ expect(composer.button_label).to have_text(I18n.t("js.composer.create_pm"))+ end++ it "should not be available in private conversation reply" do+ visit(pm_post.full_url)++ pm_post_obj.reply+ expect(composer).to be_opened++ composer.open_composer_actions+ expect(composer).to have_no_action("New message")endendend