Skip to content

A platform for community discussion. Free, open, simple.

UX: improve logic for new topic and new PM composer actions (#35834)

Yuriy Kurant0c7ac4cd8f4b
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 8bd2806329b..7e8894606bb 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2998,7 +2998,7 @@ en:
reply: "Reply"
cancel: "Cancel"
create_topic: "Create Topic"
- create_pm: "Send Message"
+ create_pm: "Send message"
create_whisper: "Whisper"
create_shared_draft: "Create Shared Draft"
edit_shared_draft: "Edit Shared Draft"
diff --git a/frontend/discourse/tests/acceptance/composer-test.js b/frontend/discourse/tests/acceptance/composer-test.js
index 8c25d8d27c1..4220cb8ea5a 100644
--- a/frontend/discourse/tests/acceptance/composer-test.js
+++ b/frontend/discourse/tests/acceptance/composer-test.js
@@ -10,7 +10,7 @@ import {
visit,
waitFor,
} from "@ember/test-helpers";
-import { test } from "qunit";
+import { module, test } from "qunit";
import sinon from "sinon";
import { PLATFORM_KEY_MODIFIER } from "discourse/lib/keyboard-shortcuts";
import LinkLookup from "discourse/lib/link-lookup";
@@ -814,6 +814,51 @@ import { i18n } from "discourse-i18n";
.exists("goes back to open state if there's errors");
});
+ module(
+ "Composer can switch between new topic and new PM in different contexts",
+ function () {
+ test("within post/topic context", async function (assert) {
+ await visit("/t/this-is-a-test-topic/54081");
+ await click(".topic-post[data-post-number='1'] button.reply");
+ await selectKit(".composer-actions").expand();
+ assert.notStrictEqual(
+ selectKit(".composer-actions")
+ .rowByValue("create_private_message")
+ .exists(),
+ "New message option is not present when in reply mode"
+ );
+
+ await click("#reply-control .discard-button");
+ await visit("/");
+ await click("#create-topic");
+ await selectKit(".composer-actions").expand();
+ assert.true(
+ selectKit(".composer-actions")
+ .rowByValue("reply_to_topic")
+ .exists(),
+ "composer topic context is preserved when reopened"
+ );
+
+ await selectKit(".composer-actions").selectRowByValue(
+ "create_private_message"
+ );
+ assert.dom(".action-title").hasText(i18n("topic.private_message"));
+ assert
+ .dom(".save-or-cancel button")
+ .hasText(i18n("composer.create_pm"));
+
+ await selectKit(".composer-actions").expand();
+ await selectKit(".composer-actions").selectRowByValue(
+ "create_topic"
+ );
+ assert.dom(".action-title").hasText(i18n("topic.create_long"));
+ assert
+ .dom(".save-or-cancel button")
+ .hasText(i18n("composer.create_topic"));
+ });
+ }
+ );
+
test("Composer can toggle between reply and createTopic", async function (assert) {
await visit("/t/this-is-a-test-topic/54081");
await click(".topic-post[data-post-number='1'] button.reply");
diff --git a/frontend/select-kit/addon/components/composer-actions.js b/frontend/select-kit/addon/components/composer-actions.js
index 58d7f4b7413..d0a7bd263c3 100644
--- a/frontend/select-kit/addon/components/composer-actions.js
+++ b/frontend/select-kit/addon/components/composer-actions.js
@@ -240,7 +240,11 @@ export default class ComposerActions extends DropdownSelectBoxComponent {
});
}
- if (items.length === 0 && this.currentUser.can_create_topic) {
+ if (
+ this.currentUser.can_create_topic &&
+ this.action !== CREATE_TOPIC &&
+ (items.length === 0 || this.action === PRIVATE_MESSAGE)
+ ) {
items.push({
name: i18n("composer.composer_actions.create_topic.label"),
description: i18n("composer.composer_actions.create_topic.desc"),
diff --git a/spec/system/private_message_spec.rb b/spec/system/private_message_spec.rb
index 75ea2ac2c83..8a9def75719 100644
--- a/spec/system/private_message_spec.rb
+++ b/spec/system/private_message_spec.rb
@@ -30,7 +30,7 @@ describe "Private Message", type: :system do
expect(composer).to be_opened
composer.open_composer_actions
- composer.select_action("New message")
+ composer.select_action(I18n.t("js.composer.composer_actions.create_personal_message.label"))
expect(composer.button_label).to have_text(I18n.t("js.composer.create_pm"))
end
@@ -42,7 +42,24 @@ describe "Private Message", type: :system do
expect(composer).to be_opened
composer.open_composer_actions
- expect(composer).to have_no_action("New message")
+ expect(composer).to have_no_action(
+ I18n.t("js.composer.composer_actions.create_personal_message.label"),
+ )
+ end
+
+ it "can switch between topic and personal message modes" do
+ visit "/new-topic"
+ expect(composer).to be_opened
+
+ # Switch to personal message
+ composer.open_composer_actions
+ composer.select_action(I18n.t("js.composer.composer_actions.create_personal_message.label"))
+ expect(composer.button_label).to have_text(I18n.t("js.composer.create_pm"))
+
+ # Switch back to topic
+ composer.open_composer_actions
+ composer.select_action(I18n.t("js.composer.composer_actions.create_topic.label"))
+ expect(composer.button_label).to have_text(I18n.t("js.composer.create_topic"))
end
end
end