Skip to content

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

FEATURE: Enable high context topic cards in Horizon by default (#39959)

Martin Brennanaf5a05c2804f
diff --git a/app/services/themes/action/horizon_high_context_topic_cards_toggled.rb b/app/services/themes/action/horizon_high_context_topic_cards_toggled.rb
new file mode 100644
index 00000000000..e50b7967734
--- /dev/null
+++ b/app/services/themes/action/horizon_high_context_topic_cards_toggled.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class Themes::Action::HorizonHighContextTopicCardsToggled < Service::ActionBase
+ option :enabled
+
+ def call
+ theme = Theme.find_by(id: Theme::CORE_THEMES["horizon"])
+ return if theme.blank?
+ return if theme.settings.blank?
+
+ setting = theme.settings[:topic_card_high_context]
+ return if setting.blank? || setting.value == enabled
+
+ theme.update_setting(:topic_card_high_context, enabled)
+ theme.save!
+ end
+
+ def self.should_display_upcoming_change?
+ horizon_theme_available? &&
+ # If the theme setting exists, this means this is an existing
+ # site that got the legacy migration. If no setting exists,
+ # it's a new site which has the theme setting for high-context topic cards
+ # enabled by default.
+ ThemeSetting.exists?(theme_id: Theme::CORE_THEMES["horizon"], name: :topic_card_high_context)
+ end
+
+ def self.horizon_theme_available?
+ horizon_theme = Theme.find_by(id: Theme::CORE_THEMES["horizon"])
+ return false if horizon_theme.blank? || !horizon_theme.enabled?
+ return false if !horizon_theme.user_selectable? && !horizon_theme.default?
+ horizon_theme.default? || horizon_theme.user_selectable?
+ end
+end
diff --git a/config/initializers/015-track-upcoming-change-toggle.rb b/config/initializers/015-track-upcoming-change-toggle.rb
index 1f804ba3f12..c21d38ea991 100644
--- a/config/initializers/015-track-upcoming-change-toggle.rb
+++ b/config/initializers/015-track-upcoming-change-toggle.rb
@@ -20,6 +20,8 @@ DiscourseEvent.on(:upcoming_change_enabled) do |setting_name|
# Respond to event here, e.g. if setting_name == :enable_form_templates do X.
if setting_name == :simple_email_subject
SiteSetting::Action::SimpleEmailSubjectToggled.call(params: { setting_enabled: true })
+ elsif setting_name == :enable_horizon_high_context_topic_cards
+ Themes::Action::HorizonHighContextTopicCardsToggled.call(enabled: true)
end
end
@@ -27,5 +29,7 @@ DiscourseEvent.on(:upcoming_change_disabled) do |setting_name|
# Respond to event here, e.g. if setting_name == :enable_form_templates do X.
if setting_name == :simple_email_subject
SiteSetting::Action::SimpleEmailSubjectToggled.call(params: { setting_enabled: false })
+ elsif setting_name == :enable_horizon_high_context_topic_cards
+ Themes::Action::HorizonHighContextTopicCardsToggled.call(enabled: false)
end
end
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 90e7ec5145b..5948264e5ad 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2820,6 +2820,7 @@ en:
rename_faq_to_guidelines: "This change renames the FAQ page to Guidelines. The FAQ page will still be available at /faq. The 'faq url' setting works as before."
enable_simplified_category_creation: "Enables a simplified category creation flow with fewer options and a cleaner interface."
modernize_foundation_theme: "This change introduces design modifcations to the Foundation theme in Discourse."
+ enable_horizon_high_context_topic_cards: "Shows richer topic cards in the Horizon theme, including topic excerpts, tags, and plugin extended information."
reporting_improvements: "Improvements to navigation, design, and usability for Discourse's admin reports."
granular_anonymous_and_logged_in_groups_permissions: "Makes group-based site setting permissions treat 'everyone' as 'all logged-in users', and enables the new 'anonymous' and 'logged_in_users' pseudogroups so admins can explicitly target anonymous visitors and authenticated users."
dashboard_improvements: "Improvements to navigation, design, and usability for the Discourse admin dashboard."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 4b6ec478e80..07d70d3eee3 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4505,6 +4505,17 @@ experimental:
impact: "feature,all_members"
status: "beta"
learn_more_url: "https://meta.discourse.org/t/-/395331"
+ enable_horizon_high_context_topic_cards:
+ default: false
+ client: true
+ hidden: true
+ area: "experimental"
+ upcoming_change:
+ status: "alpha"
+ impact: "site_setting_default,all_members"
+ learn_more_url: "http://meta.discourse.org/t/-/402843"
+ allow_enabled_for:
+ - everyone
granular_anonymous_and_logged_in_groups_permissions:
default: false
client: true
diff --git a/db/migrate/20260513055222_disable_horizon_high_context_topic_cards_for_existing_sites.rb b/db/migrate/20260513055222_disable_horizon_high_context_topic_cards_for_existing_sites.rb
new file mode 100644
index 00000000000..0901360162e
--- /dev/null
+++ b/db/migrate/20260513055222_disable_horizon_high_context_topic_cards_for_existing_sites.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+class DisableHorizonHighContextTopicCardsForExistingSites < ActiveRecord::Migration[8.0]
+ def up
+ return if Migration::Helpers.new_site?
+
+ execute <<~SQL
+ INSERT INTO theme_settings(name, data_type, value, theme_id, created_at, updated_at)
+ SELECT 'topic_card_high_context', 3, 'false', -2, NOW(), NOW()
+ WHERE EXISTS(
+ SELECT 1 FROM themes
+ WHERE id = -2
+ ) AND NOT EXISTS(
+ SELECT 1 FROM theme_settings
+ WHERE theme_id = -2 AND name = 'topic_card_high_context'
+ )
+ SQL
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/lib/upcoming_changes.rb b/lib/upcoming_changes.rb
index b20df3af18b..cd0ae21f00c 100644
--- a/lib/upcoming_changes.rb
+++ b/lib/upcoming_changes.rb
@@ -22,6 +22,10 @@ module UpcomingChanges
true
end
+
+ def self.should_display_enable_horizon_high_context_topic_cards?
+ Themes::Action::HorizonHighContextTopicCardsToggled.should_display_upcoming_change?
+ end
end
def self.user_enabled_reasons
diff --git a/spec/services/themes/horizon_high_context_topic_cards_spec.rb b/spec/services/themes/horizon_high_context_topic_cards_spec.rb
new file mode 100644
index 00000000000..626f9bdf81e
--- /dev/null
+++ b/spec/services/themes/horizon_high_context_topic_cards_spec.rb
@@ -0,0 +1,97 @@
+# frozen_string_literal: true
+
+RSpec.describe Themes::Action::HorizonHighContextTopicCardsToggled do
+ fab!(:horizon_theme) { Theme.horizon_theme }
+
+ before do
+ horizon_theme.set_field(
+ target: :settings,
+ name: "yaml",
+ value: File.read(Rails.root.join("themes/horizon/settings.yml")),
+ )
+ horizon_theme.save!
+ horizon_theme.update_columns(enabled: true, user_selectable: true)
+ horizon_theme.theme_settings.where(name: "topic_card_high_context").delete_all
+ horizon_theme.reload
+ end
+
+ describe ".should_display_upcoming_change?" do
+ before do
+ ThemeSetting.create!(
+ theme: horizon_theme,
+ name: "topic_card_high_context",
+ data_type: ThemeSetting.types[:bool],
+ value: "false",
+ )
+ end
+
+ it "returns true when Horizon is enabled and user-selectable" do
+ expect(described_class.should_display_upcoming_change?).to eq(true)
+ expect(
+ UpcomingChanges::ConditionalDisplay.should_display?(
+ :enable_horizon_high_context_topic_cards,
+ ),
+ ).to eq(true)
+ end
+
+ it "returns false when Horizon is disabled" do
+ horizon_theme.update_columns(enabled: false)
+
+ expect(described_class.should_display_upcoming_change?).to eq(false)
+ end
+
+ it "returns false when Horizon is not user-selectable and is not the default theme" do
+ horizon_theme.update_columns(user_selectable: false)
+ SiteSetting.default_theme_id = Theme.find(Theme::CORE_THEMES["foundation"]).id
+
+ expect(described_class.should_display_upcoming_change?).to eq(false)
+ end
+
+ it "returns true when Horizon is the default theme" do
+ horizon_theme.update_columns(user_selectable: false)
+ SiteSetting.default_theme_id = horizon_theme.id
+
+ expect(described_class.should_display_upcoming_change?).to eq(true)
+ end
+
+ it "returns true when Horizon is user-selectable but not the default theme" do
+ horizon_theme.update_columns(user_selectable: true)
+ SiteSetting.default_theme_id = Theme.find(Theme::CORE_THEMES["foundation"]).id
+
+ expect(described_class.should_display_upcoming_change?).to eq(true)
+ end
+
+ it "returns false when Horizon has no high-context override" do
+ horizon_theme.theme_settings.where(name: "topic_card_high_context").delete_all
+
+ expect(described_class.should_display_upcoming_change?).to eq(false)
+ end
+ end
+
+ describe ".call" do
+ it "enables high-context topic cards" do
+ horizon_theme.update_setting(:topic_card_high_context, false)
+ horizon_theme.save!
+
+ described_class.call(enabled: true)
+
+ expect(horizon_theme.reload.get_setting(:topic_card_high_context)).to eq(true)
+ end
+
+ it "disables high-context topic cards" do
+ described_class.call(enabled: false)
+
+ expect(horizon_theme.reload.get_setting(:topic_card_high_context)).to eq(false)
+ end
+ end
+
+ describe "upcoming change event handlers" do
+ it "updates Horizon high-context topic cards when the upcoming change toggles" do
+ DiscourseEvent.trigger(:upcoming_change_enabled, :enable_horizon_high_context_topic_cards)
+ expect(horizon_theme.reload.get_setting(:topic_card_high_context)).to eq(true)
+
+ DiscourseEvent.trigger(:upcoming_change_disabled, :enable_horizon_high_context_topic_cards)
+ expect(horizon_theme.reload.get_setting(:topic_card_high_context)).to eq(false)
+ end
+ end
+end
diff --git a/themes/horizon/locales/en.yml b/themes/horizon/locales/en.yml
index a42ef5c8827..c2b81aed834 100644
--- a/themes/horizon/locales/en.yml
+++ b/themes/horizon/locales/en.yml
@@ -17,4 +17,4 @@ en:
description: "A simple, beautiful theme that improves the out of the box experience for Discourse sites."
settings:
topic_card_high_context:
- description: "When enabled, displays additional context on topic cards including tags, excerpts, solved status, assigned users, and vote counts (experimental)"
+ description: "When enabled, displays additional context on topic cards including tags, excerpts, solved status, assigned users, and vote counts"
diff --git a/themes/horizon/settings.yml b/themes/horizon/settings.yml
index ad087894fb0..95014f3e2ef 100644
--- a/themes/horizon/settings.yml
+++ b/themes/horizon/settings.yml
@@ -1,3 +1,3 @@
topic_card_high_context:
type: bool
- default: false
+ default: true
diff --git a/themes/horizon/spec/system/horizon_high_level_spec.rb b/themes/horizon/spec/system/horizon_high_level_spec.rb
index 314d4fda0a0..aba7a8df99f 100644
--- a/themes/horizon/spec/system/horizon_high_level_spec.rb
+++ b/themes/horizon/spec/system/horizon_high_level_spec.rb
@@ -3,7 +3,7 @@
require_relative "page_objects/components/user_color_palette_selector"
describe "Horizon theme | High level" do
- let!(:theme) do
+ let!(:horizon_theme) do
horizon_theme = upload_theme
ColorScheme
.where(theme_id: horizon_theme.id)
@@ -36,14 +36,7 @@ describe "Horizon theme | High level" do
#
# NOTE(martin): Maybe there is a better way to do this in a qunit test instead.
topic_item = find(topic_list.topic_list_item_class(topic_1))
- expect(topic_item.all("td").map { |el| el["class"] }).to eq(
- [
- "main-link topic-list-data",
- "topic-category-data",
- "topic-creator-data",
- "topic-activity-data",
- ],
- )
+ expect(topic_item.all("td").map { |el| el["class"] }).to eq(["hc-topic-card"])
# Can see a topic in the list and navigate to it successfully.
topic_list.visit_topic(topic_1)
@@ -51,7 +44,7 @@ describe "Horizon theme | High level" do
# Can change site colors from the sidebar palette, which are remembered
# across page reloads.
- marigold_palette = theme.color_schemes.find_by(name: "Marigold")
+ marigold_palette = horizon_theme.color_schemes.find_by(name: "Marigold")
palette_selector.open_palette_menu
palette_selector.click_palette_menu_item(marigold_palette.name)
expect(palette_selector).to have_no_palette_menu
@@ -59,6 +52,22 @@ describe "Horizon theme | High level" do
page.refresh
expect(palette_selector).to have_selected_palette(marigold_palette)
expect(palette_selector).to have_tertiary_color(marigold_palette)
+
+ # Navigating topic list when high context topic cards are not enabled
+ horizon_theme.update_setting(:topic_card_high_context, false)
+ horizon_theme.save!
+ page.refresh
+ visit "/"
+ expect(topic_item.all("td").map { |el| el["class"] }).to eq(
+ [
+ "main-link topic-list-data",
+ "topic-category-data",
+ "topic-creator-data",
+ "topic-activity-data",
+ ],
+ )
+ topic_list.visit_topic(topic_1)
+ expect(topic_page).to have_topic_title(topic_1.title)
end
it "works for anon" do