Skip to content

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

FEATURE: Add full app mode toggle to embedding admin page (#39052)

Rafael dos Santos Silva6c2d77ef6699
diff --git a/app/assets/stylesheets/admin/customize.scss b/app/assets/stylesheets/admin/customize.scss
index dd5e3d83db9..6efae03c06e 100644
--- a/app/assets/stylesheets/admin/customize.scss
+++ b/app/assets/stylesheets/admin/customize.scss
@@ -775,6 +775,28 @@
}
.admin-embedding {
+ .admin-embedding-index__full-app-toggle {
+ display: flex;
+ align-items: flex-start;
+ gap: var(--space-3);
+ margin-bottom: var(--space-4);
+ }
+
+ .admin-embedding-index__full-app-toggle-text {
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-1);
+ }
+
+ .admin-embedding-index__full-app-toggle-label {
+ font-weight: 700;
+ }
+
+ .admin-embedding-index__full-app-toggle-description {
+ color: var(--primary-medium);
+ font-size: var(--font-down-1);
+ }
+
.admin-embeddable-host-item__delete {
&:hover {
svg.d-icon {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 953ca77c4dc..433b8c85823 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -8992,6 +8992,8 @@ en:
crawler_settings_saved: "Crawler settings saved"
back: "Back to embedding"
configuration_snippet: "Configuration snippet"
+ full_app_mode: "Full app mode"
+ full_app_mode_description: "Load the full Discourse application in the embed iframe, allowing users to reply, like, quote, and interact with topics directly"
host_form:
add_header: "Add host"
edit_header: "Edit host"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 18072d9c3e5..06505f80451 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2555,6 +2555,7 @@ en:
embed_support_markdown: "Support Markdown formatting for embedded posts."
allowed_embed_selectors: "A comma separated list of CSS elements that are allowed in embeds."
allowed_href_schemes: "Schemes allowed in links in addition to http and https."
+ embed_full_app: "Enable full app mode for embedded comments. When enabled, embedded comments will load the full Discourse application in an iframe, allowing users to interact with topics directly"
embed_post_limit: "Maximum number of posts to embed."
embed_username_required: "The username for topic creation is required."
notify_about_reviewable_item_after: "If there are reviewable items that haven’t been handled after this many hours, send a personal message to moderators. Set to 0 to disable."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 48ac648bf2d..9813d78cda9 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -3192,7 +3192,8 @@ navigation:
embedding:
embed_full_app:
default: false
- hidden: true
+ client: true
+ area: "embedding"
embed_by_username:
default: ""
type: username
diff --git a/frontend/discourse/admin/controllers/admin-embedding/index.js b/frontend/discourse/admin/controllers/admin-embedding/index.js
index d8749bb2376..534aeee9c6a 100644
--- a/frontend/discourse/admin/controllers/admin-embedding/index.js
+++ b/frontend/discourse/admin/controllers/admin-embedding/index.js
@@ -1,12 +1,19 @@
import Controller, { inject as controller } from "@ember/controller";
import { action } from "@ember/object";
import { service } from "@ember/service";
+import SiteSetting from "discourse/admin/models/site-setting";
+import { popupAjaxError } from "discourse/lib/ajax-error";
import { removeValueFromArray } from "discourse/lib/array-tools";
export default class AdminEmbeddingIndexController extends Controller {
@service site;
+ @service siteSettings;
@controller adminEmbedding;
+ get fullAppMode() {
+ return this.siteSettings.embed_full_app;
+ }
+
get embedding() {
return this.adminEmbedding.embedding;
}
@@ -16,13 +23,19 @@ export default class AdminEmbeddingIndexController extends Controller {
}
get embeddingCode() {
+ const fullAppLines = this.fullAppMode
+ ? `
+ fullApp: true,
+ embedHeight: '800px',`
+ : "";
+
const html = `<div id='discourse-comments'></div>
<meta name='discourse-username' content='DISCOURSE_USERNAME'>
<script type="text/javascript">
DiscourseEmbed = {
discourseUrl: '${this.embedding.base_url}/',
- discourseEmbedUrl: 'EMBED_URL',
+ discourseEmbedUrl: 'EMBED_URL',${fullAppLines}
// className: 'CLASS_NAME',
};
@@ -36,6 +49,19 @@ export default class AdminEmbeddingIndexController extends Controller {
return html;
}
+ @action
+ async toggleFullAppMode() {
+ const previousValue = this.siteSettings.embed_full_app;
+ this.siteSettings.embed_full_app = !previousValue;
+
+ try {
+ await SiteSetting.update("embed_full_app", !previousValue);
+ } catch (err) {
+ this.siteSettings.embed_full_app = previousValue;
+ popupAjaxError(err);
+ }
+ }
+
@action
deleteHost(host) {
removeValueFromArray(this.embedding.embeddable_hosts, host);
diff --git a/frontend/discourse/admin/templates/admin-embedding/index.gjs b/frontend/discourse/admin/templates/admin-embedding/index.gjs
index 3adf311ac79..118aa4efe2b 100644
--- a/frontend/discourse/admin/templates/admin-embedding/index.gjs
+++ b/frontend/discourse/admin/templates/admin-embedding/index.gjs
@@ -1,7 +1,9 @@
+import { on } from "@ember/modifier";
import { trustHTML } from "@ember/template";
import AdminConfigAreaCard from "discourse/admin/components/admin-config-area-card";
import AdminConfigAreaEmptyList from "discourse/admin/components/admin-config-area-empty-list";
import EmbeddableHost from "discourse/admin/components/embeddable-host";
+import DToggleSwitch from "discourse/components/d-toggle-switch";
import HighlightedCode from "discourse/components/highlighted-code";
import PluginOutlet from "discourse/components/plugin-outlet";
import lazyHash from "discourse/helpers/lazy-hash";
@@ -9,6 +11,22 @@ import { i18n } from "discourse-i18n";
export default <template>
{{#if @controller.embedding.embeddable_hosts}}
+ <div class="admin-embedding-index__full-app-toggle">
+ <DToggleSwitch
+ @state={{@controller.fullAppMode}}
+ aria-label={{i18n "admin.embedding.full_app_mode"}}
+ {{on "click" @controller.toggleFullAppMode}}
+ />
+ <div class="admin-embedding-index__full-app-toggle-text">
+ <span class="admin-embedding-index__full-app-toggle-label">
+ {{i18n "admin.embedding.full_app_mode"}}
+ </span>
+ <span class="admin-embedding-index__full-app-toggle-description">
+ {{i18n "admin.embedding.full_app_mode_description"}}
+ </span>
+ </div>
+ </div>
+
{{#if @controller.showEmbeddingCode}}
<AdminConfigAreaCard
@heading="admin.embedding.configuration_snippet"
diff --git a/spec/system/admin_embeddable_hosts_spec.rb b/spec/system/admin_embeddable_hosts_spec.rb
index 0dc6ff4d46e..3c774772f2f 100644
--- a/spec/system/admin_embeddable_hosts_spec.rb
+++ b/spec/system/admin_embeddable_hosts_spec.rb
@@ -60,6 +60,29 @@ RSpec.describe "Admin EmbeddableHost Management" do
expect(page).not_to have_css(".admin-embedding-index__code")
end
+ it "allows admin to toggle full app mode and updates the snippet" do
+ Fabricate(:embeddable_host)
+
+ admin_embedding_page.visit
+ admin_embedding_page.expand_snippet
+
+ expect(admin_embedding_page).to have_full_app_mode_disabled
+ expect(admin_embedding_page).to have_no_snippet_containing("fullApp")
+
+ admin_embedding_page.click_full_app_mode_toggle
+
+ expect(admin_embedding_page).to have_full_app_mode_enabled
+ expect(admin_embedding_page).to have_snippet_containing("fullApp")
+ expect(admin_embedding_page).to have_snippet_containing("embedHeight")
+ expect(SiteSetting.embed_full_app).to eq(true)
+
+ admin_embedding_page.click_full_app_mode_toggle
+
+ expect(admin_embedding_page).to have_full_app_mode_disabled
+ expect(admin_embedding_page).to have_no_snippet_containing("fullApp")
+ expect(SiteSetting.embed_full_app).to eq(false)
+ end
+
it "allows admin to save posts and topics settings" do
Fabricate(:embeddable_host)
diff --git a/spec/system/page_objects/pages/admin_embedding.rb b/spec/system/page_objects/pages/admin_embedding.rb
index 296c56a5d01..b32144b842d 100644
--- a/spec/system/page_objects/pages/admin_embedding.rb
+++ b/spec/system/page_objects/pages/admin_embedding.rb
@@ -23,6 +23,38 @@ module PageObjects
self
end
+ def full_app_mode_toggle
+ PageObjects::Components::DToggleSwitch.new(
+ ".admin-embedding-index__full-app-toggle .d-toggle-switch__checkbox",
+ )
+ end
+
+ def click_full_app_mode_toggle
+ full_app_mode_toggle.toggle
+ self
+ end
+
+ def has_full_app_mode_enabled?
+ full_app_mode_toggle.checked?
+ end
+
+ def has_full_app_mode_disabled?
+ full_app_mode_toggle.unchecked?
+ end
+
+ def expand_snippet
+ find(".admin-embedding-index__code .admin-config-area-card__toggle-button").click
+ self
+ end
+
+ def has_snippet_containing?(text)
+ page.has_css?(".admin-embedding-index__code code", text: text)
+ end
+
+ def has_no_snippet_containing?(text)
+ page.has_no_css?(".admin-embedding-index__code code", text: text)
+ end
+
def click_delete
open_embedding_host_menu
find(".admin-embeddable-host-item__delete").click