Skip to content

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

UX: let automation d-editor respect user's editor mode preference (#38622)

Renato Atilio411eb178455a
diff --git a/app/assets/stylesheets/common/d-editor.scss b/app/assets/stylesheets/common/d-editor.scss
index 9ca14891869..7840c433028 100644
--- a/app/assets/stylesheets/common/d-editor.scss
+++ b/app/assets/stylesheets/common/d-editor.scss
@@ -113,7 +113,8 @@
}
}
-.hide-preview .d-editor-preview-wrapper {
+.hide-preview .d-editor-preview-wrapper,
+.--rich-editor-enabled .d-editor-preview-wrapper {
display: none;
flex: 0;
}
diff --git a/frontend/discourse/tests/integration/components/d-editor-test.gjs b/frontend/discourse/tests/integration/components/d-editor-test.gjs
index f5280e79276..46fe1b0ae78 100644
--- a/frontend/discourse/tests/integration/components/d-editor-test.gjs
+++ b/frontend/discourse/tests/integration/components/d-editor-test.gjs
@@ -1480,6 +1480,20 @@ third line`
module("Integration | Component | d-editor | rich editor", function (hooks) {
setupRenderingTest(hooks);
+ test("hides preview when rich editor is enabled", async function (assert) {
+ this.siteSettings.rich_editor = true;
+
+ await render(<template><DEditor /></template>);
+ await click(".composer-toggle-switch");
+
+ assert
+ .dom(".d-editor-container.--rich-editor-enabled")
+ .exists("rich editor is active");
+ assert
+ .dom(".d-editor-preview-wrapper")
+ .isNotVisible("preview is hidden in rich editor mode");
+ });
+
test("replaceText escapes markdown symbols that could be regexp symbols", async function (assert) {
this.siteSettings.rich_editor = true;
diff --git a/plugins/automation/admin/assets/javascripts/admin/components/fields/da-pms-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-pms-field.gjs
index bbcd56627e7..a34c85d015b 100644
--- a/plugins/automation/admin/assets/javascripts/admin/components/fields/da-pms-field.gjs
+++ b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-pms-field.gjs
@@ -8,7 +8,6 @@ import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import DEditor from "discourse/components/d-editor";
import { removeValueFromArray } from "discourse/lib/array-tools";
-import { USER_OPTION_COMPOSITION_MODES } from "discourse/lib/constants";
import { i18n } from "discourse-i18n";
import PlaceholdersList from "../placeholders-list";
import BaseField from "./da-base-field";
@@ -68,11 +67,7 @@ export default class PmsField extends BaseField {
<DAFieldLabel @label={{this.rawLabel}} @field={{@field}} />
<div class="controls">
<div class="field-wrapper">
- <DEditor
- @value={{pm.raw}}
- @forceEditorMode={{USER_OPTION_COMPOSITION_MODES.rich}}
- @processPreview={{false}}
- />
+ <DEditor @value={{pm.raw}} />
{{#if this.displayPlaceholders}}
<PlaceholdersList
diff --git a/plugins/automation/admin/assets/javascripts/admin/components/fields/da-post-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-post-field.gjs
index b126c037020..44306dd387c 100644
--- a/plugins/automation/admin/assets/javascripts/admin/components/fields/da-post-field.gjs
+++ b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-post-field.gjs
@@ -1,5 +1,4 @@
import DEditor from "discourse/components/d-editor";
-import { USER_OPTION_COMPOSITION_MODES } from "discourse/lib/constants";
import PlaceholdersList from "../placeholders-list";
import BaseField from "./da-base-field";
import DAFieldDescription from "./da-field-description";
@@ -13,11 +12,7 @@ export default class PostField extends BaseField {
<div class="controls">
<div class="field-wrapper">
- <DEditor
- @value={{@field.metadata.value}}
- @forceEditorMode={{USER_OPTION_COMPOSITION_MODES.rich}}
- @processPreview={{false}}
- />
+ <DEditor @value={{@field.metadata.value}} />
<DAFieldDescription @description={{@description}} />
diff --git a/plugins/automation/spec/system/new_automation_spec.rb b/plugins/automation/spec/system/new_automation_spec.rb
index 985eb312f56..27433dea5f3 100644
--- a/plugins/automation/spec/system/new_automation_spec.rb
+++ b/plugins/automation/spec/system/new_automation_spec.rb
@@ -9,7 +9,6 @@ describe "DiscourseAutomation | New automation" do
end
let(:new_automation_page) { PageObjects::Pages::NewAutomation.new }
- let(:composer) { PageObjects::Components::Composer.new }
context "when a script is clicked" do
it "navigates to automation edit route" do
@@ -22,7 +21,7 @@ describe "DiscourseAutomation | New automation" do
new_automation_page.select_trigger("recurring")
expect(page).to have_css(".scriptables")
- expect(composer).to have_rich_editor
+ expect(page).to have_css(".d-editor")
end
end
end