A platform for community discussion. Free, open, simple.
FEATURE: Move theme site settings config page to a tab in the customize page (#34376)
Martin Brennan62f6ee0b1f68
diff --git a/app/assets/javascripts/admin/addon/components/admin-config-areas/themes.gjs b/app/assets/javascripts/admin/addon/components/admin-config-areas/themes.gjsindex 7ac0fc7e59c..82d750f8909 100644--- a/app/assets/javascripts/admin/addon/components/admin-config-areas/themes.gjs+++ b/app/assets/javascripts/admin/addon/components/admin-config-areas/themes.gjs@@ -90,7 +90,9 @@ export default class AdminConfigAreasThemes extends Component {}}@descriptionLabel={{i18n"admin.config_areas.themes_and_components.themes.description"- themeSiteSettingsUrl=(getURL "/admin/config/theme-site-settings")+ themeSiteSettingsUrl=(getURL+ "/admin/config/customize/theme-site-settings"+ )}}><:actions as |actions|>diff --git a/app/assets/javascripts/admin/addon/components/theme-site-settings.gjs b/app/assets/javascripts/admin/addon/components/theme-site-settings.gjsindex 0408b6bf930..de2aa455ff5 100644--- a/app/assets/javascripts/admin/addon/components/theme-site-settings.gjs+++ b/app/assets/javascripts/admin/addon/components/theme-site-settings.gjs@@ -11,6 +11,7 @@ import basePath from "discourse/helpers/base-path";import { ajax } from "discourse/lib/ajax";import { currentThemeId, listThemes } from "discourse/lib/theme-selector";import { i18n } from "discourse-i18n";+import AdminFilterControls from "admin/components/admin-filter-controls";import DTooltip from "float-kit/components/d-tooltip";export default class ThemeSiteSettings extends Component {@@ -33,13 +34,9 @@ export default class ThemeSiteSettings extends Component {});}- isLastThemeSettingOverride(overrides, theme) {- return theme === overrides.themes.at(-1);- }-@actionasync loadThemeSiteSettings() {- let url = "/admin/config/theme-site-settings.json";+ let url = "/admin/config/customize/theme-site-settings.json";const response = await ajax(url, {method: "GET",});@@ -56,76 +53,117 @@ export default class ThemeSiteSettings extends Component {return this.themesWithSiteSettingOverrides;}+ isLastThemeSettingOverride(overrides, theme) {+ return theme === overrides.themes.at(-1);+ }++ filterableSettings(settings) {+ if (!settings) {+ return [];+ }++ const filterableSettings = [];+ for (const [settingName, overrides] of Object.entries(settings)) {+ filterableSettings.push({+ humanized_name: overrides.humanized_name,+ name: settingName,+ description: overrides.description,+ default: overrides.default,+ themeNames:+ overrides.themes?.map((t) => t.theme_name.toLowerCase()).join(",") ||+ "",+ themes: overrides.themes,+ });+ }++ return filterableSettings;+ }+<template><div class="theme-site-settings">+ <DPageSubheader+ @descriptionLabel={{i18n+ "admin.theme_site_settings.help"+ currentTheme=this.currentTheme.name+ basePath=basePath+ currentThemeId=this.currentThemeIdValue+ }}+ />+<AsyncContent @asyncData={{this.loadThemeSiteSettings}}><:content as |content|>- <DPageSubheader- @descriptionLabel={{i18n- "admin.theme_site_settings.help"- currentTheme=this.currentTheme.name- basePath=basePath- currentThemeId=this.currentThemeIdValue+ <AdminFilterControls+ @array={{this.filterableSettings content}}+ @searchableProps={{array+ "humanized_name"+ "name"+ "description"+ "themeNames"+ }}+ @inputPlaceholder={{i18n "admin.theme_site_settings.filter"}}+ @noResultsMessage={{i18n+ "admin.theme_site_settings.filter_no_results"}}- />- <table class="d-admin-table admin-theme-site-settings">- <thead>- <tr>- <th>{{i18n "admin.theme_site_settings.setting"}}</th>- <th>{{i18n "admin.theme_site_settings.default_value"}}</th>- <th>{{i18n "admin.theme_site_settings.overridden_by"}}</th>- </tr>- </thead>- <tbody>- {{#each-in content as |settingName overrides|}}- <tr- class="admin-theme-site-settings-row d-admin-row__content"- data-setting-name={{settingName}}- >- <td class="admin-theme-site-settings-row__setting">- <p class="setting-label">{{overrides.humanized_name}}</p>- <div- class="setting-description"- >{{overrides.description}}</div>- </td>- <td class="admin-theme-site-settings-row__default">- {{overrides.default}}- </td>- <td class="admin-theme-site-settings-row__overridden">- {{#each overrides.themes as |theme|}}- <DTooltip>- <:trigger>- <LinkTo- @route="adminCustomizeThemes.show"- @models={{array "themes" theme.theme_id}}- class="theme-link"- data-theme-id={{theme.theme_id}}- >- {{theme.theme_name}}- </LinkTo>- </:trigger>- <:content>- {{i18n- "admin.theme_site_settings.overridden_value"- value=theme.value- }}- </:content>- </DTooltip>- {{#unless- (this.isLastThemeSettingOverride overrides theme)- }},{{/unless}}- {{/each}}- {{#unless overrides.themes}}- -- {{/unless}}- </td>- </tr>- {{/each-in}}- </tbody>- </table>+ >+ <:content as |filteredSettings|>+ <table class="d-admin-table admin-theme-site-settings">+ <thead>+ <tr>+ <th>{{i18n "admin.theme_site_settings.setting"}}</th>+ <th>{{i18n "admin.theme_site_settings.default_value"}}</th>+ <th>{{i18n "admin.theme_site_settings.overridden_by"}}</th>+ </tr>+ </thead>+ <tbody>+ {{#each filteredSettings as |fs|}}+ <tr+ class="admin-theme-site-settings-row d-admin-row__content"+ data-setting-name={{fs.name}}+ >+ <td class="admin-theme-site-settings-row__setting">+ <p class="setting-label">{{fs.humanized_name}}</p>+ <div+ class="setting-description"+ >{{fs.description}}</div>+ </td>+ <td class="admin-theme-site-settings-row__default">+ {{fs.default}}+ </td>+ <td class="admin-theme-site-settings-row__overridden">+ {{#each fs.themes as |theme|}}+ <DTooltip>+ <:trigger>+ <LinkTo+ @route="adminCustomizeThemes.show"+ @models={{array "themes" theme.theme_id}}+ class="theme-link"+ data-theme-id={{theme.theme_id}}+ >+ {{theme.theme_name}}+ </LinkTo>+ </:trigger>+ <:content>+ {{i18n+ "admin.theme_site_settings.overridden_value"+ value=theme.value+ }}+ </:content>+ </DTooltip>+ {{#unless+ (this.isLastThemeSettingOverride fs theme)+ }},{{/unless}}+ {{/each}}+ {{#unless fs.themes}}+ -+ {{/unless}}+ </td>+ </tr>+ {{/each}}+ </tbody>+ </table>+ </:content>+ </AdminFilterControls></:content>- <:empty>- </:empty></AsyncContent></div></template>diff --git a/app/assets/javascripts/admin/addon/routes/admin-route-map.js b/app/assets/javascripts/admin/addon/routes/admin-route-map.jsindex 94636133dbb..85108925f83 100644--- a/app/assets/javascripts/admin/addon/routes/admin-route-map.js+++ b/app/assets/javascripts/admin/addon/routes/admin-route-map.js@@ -322,6 +322,7 @@ export default function () {this.route("customize", function () {this.route("themes");this.route("components");+ this.route("themeSiteSettings", { path: "/theme-site-settings" });});this.route("adminAnalytics",@@ -380,7 +381,6 @@ export default function () {this.route("spam", function () {this.route("settings", { path: "/" });});- this.route("theme-site-settings");this.route("colorPalettes",diff --git a/app/assets/javascripts/admin/addon/templates/config-customize-theme-site-settings.gjs b/app/assets/javascripts/admin/addon/templates/config-customize-theme-site-settings.gjsnew file mode 100644index 00000000000..808e346b32a--- /dev/null+++ b/app/assets/javascripts/admin/addon/templates/config-customize-theme-site-settings.gjs@@ -0,0 +1,27 @@+import RouteTemplate from "ember-route-template";+import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";+import DPageSubheader from "discourse/components/d-page-subheader";+import { i18n } from "discourse-i18n";+import ThemeSiteSettings from "admin/components/theme-site-settings";++export default RouteTemplate(+ <template>+ <DBreadcrumbsItem+ @path="/admin/config/customize/theme-site-settings"+ @label={{i18n+ "admin.config_areas.themes_and_components.theme_site_settings.title"+ }}+ />++ <DPageSubheader+ @titleLabel={{i18n+ "admin.config_areas.themes_and_components.theme_site_settings.title"+ }}+ @descriptionLabel={{i18n+ "admin.config_areas.themes_and_components.theme_site_settings.description"+ }}+ />++ <ThemeSiteSettings />+ </template>+);diff --git a/app/assets/javascripts/admin/addon/templates/config-customize.gjs b/app/assets/javascripts/admin/addon/templates/config-customize.gjsindex 9b97df69e58..faae24d0163 100644--- a/app/assets/javascripts/admin/addon/templates/config-customize.gjs+++ b/app/assets/javascripts/admin/addon/templates/config-customize.gjs@@ -27,6 +27,10 @@ export default RouteTemplate(@route="adminConfig.customize.components"@label="admin.config.components.title"/>+ <NavItem+ @route="adminConfig.customize.themeSiteSettings"+ @label="admin.config.theme_site_settings.title"+ /></:tabs></DPageHeader>diff --git a/app/assets/javascripts/admin/addon/templates/config-theme-site-settings.gjs b/app/assets/javascripts/admin/addon/templates/config-theme-site-settings.gjsdeleted file mode 100644index f7d26c21c68..00000000000--- a/app/assets/javascripts/admin/addon/templates/config-theme-site-settings.gjs+++ /dev/null@@ -1,29 +0,0 @@-import RouteTemplate from "ember-route-template";-import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";-import DPageHeader from "discourse/components/d-page-header";-import { i18n } from "discourse-i18n";-import ThemeSiteSettings from "admin/components/theme-site-settings";--export default RouteTemplate(- <template>- <DPageHeader- @hideTabs={{true}}- @titleLabel={{i18n "admin.config.theme_site_settings.title"}}- @descriptionLabel={{i18n- "admin.config.theme_site_settings.header_description"- }}- >- <:breadcrumbs>- <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />- <DBreadcrumbsItem- @path="/admin/config/theme-site-settings"- @label={{i18n "admin.config.theme_site_settings.title"}}- />- </:breadcrumbs>- </DPageHeader>-- <div class="admin-config-page__main-area">- <ThemeSiteSettings />- </div>- </template>-);diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs b/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjsindex 92ef3a1d918..2246124670c 100644--- a/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-show-index.gjs@@ -360,7 +360,7 @@ export default RouteTemplate((i18n"admin.customize.theme.overriden_site_settings_explanation"themeSiteSettingsConfigUrl=(getURL- "/admin/config/theme-site-settings"+ "/admin/config/customize/theme-site-settings"))}}</i></p>diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.jsindex bb2d63507f2..51717c0401c 100644--- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js+++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js@@ -275,7 +275,7 @@ export const ADMIN_NAV_MAP = [links: [{name: "admin_theme_site_settings",- route: "adminConfig.theme-site-settings",+ route: "adminConfig.customize.themeSiteSettings",label: "admin.config.theme_site_settings.title",description: "admin.config.theme_site_settings.header_description",icon: "gear",diff --git a/app/controllers/admin/config/customize_controller.rb b/app/controllers/admin/config/customize_controller.rbindex 98ab25a8e43..f79401c502e 100644--- a/app/controllers/admin/config/customize_controller.rb+++ b/app/controllers/admin/config/customize_controller.rb@@ -47,4 +47,27 @@ class Admin::Config::CustomizeController < Admin::AdminControllerrender json: { has_more:, components: serialize_data(components, ComponentIndexSerializer) }end++ def theme_site_settings+ themes_with_site_setting_overrides = {}++ SiteSetting.themeable_site_settings.each do |setting_name|+ themes_with_site_setting_overrides[setting_name] = SiteSetting.setting_metadata_hash(+ setting_name,+ ).merge(themes: [])+ end++ ThemeSiteSetting.themes_with_overridden_settings.each do |row|+ themes_with_site_setting_overrides[row.setting_name][:themes] << {+ theme_id: row.theme_id,+ theme_name: row.theme_name,+ value: row.value,+ }+ end++ render_json_dump(+ themeable_site_settings: SiteSetting.themeable_site_settings,+ themes_with_site_setting_overrides: themes_with_site_setting_overrides,+ )+ endenddiff --git a/app/controllers/admin/config/theme_site_settings_controller.rb b/app/controllers/admin/config/theme_site_settings_controller.rbdeleted file mode 100644index 9b61323d8b7..00000000000--- a/app/controllers/admin/config/theme_site_settings_controller.rb+++ /dev/null@@ -1,30 +0,0 @@-# frozen_string_literal: true--class Admin::Config::ThemeSiteSettingsController < Admin::AdminController- def index- respond_to do |format|- format.json do- themes_with_site_setting_overrides = {}-- SiteSetting.themeable_site_settings.each do |setting_name|- themes_with_site_setting_overrides[setting_name] = SiteSetting.setting_metadata_hash(- setting_name,- ).merge(themes: [])- end-- ThemeSiteSetting.themes_with_overridden_settings.each do |row|- themes_with_site_setting_overrides[row.setting_name][:themes] << {- theme_id: row.theme_id,- theme_name: row.theme_name,- value: row.value,- }- end-- render_json_dump(- themeable_site_settings: SiteSetting.themeable_site_settings,- themes_with_site_setting_overrides: themes_with_site_setting_overrides,- )- end- end- end-enddiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 332421fbc67..7bb2c8fc1a9 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -5951,6 +5951,8 @@ en:select_setting: "Select a site setting to see current theme values"add: "Go to theme site settings"help: "The theme you are currently using is <a href='%{basePath}/admin/customize/themes/%{currentThemeId}'>%{currentTheme}</a>. Go to the <a href='%{basePath}/admin/customize/themes/%{currentThemeId}'>theme config page</a> to alter theme site settings, or click on a linked theme in the table below to edit its settings."+ filter: "Filter theme site settings by setting name, description, or theme name..."+ filter_no_results: "No theme site settings match your filter"search:modal_title: "Search everything in admin"@@ -6642,9 +6644,12 @@ en:themes_and_components:breadcrumb_title: "Customize"install: "Install"+ theme_site_settings:+ title: "Theme site settings"+ description: "Settings that allow themes to have greater control over the full site experience by overriding a small subset of core site settings."themes:title: "Themes"- description: 'Site-wide themes that change the overall look and feel of your site for all users. Want to check which site settings your themes override? <a href="%{themeSiteSettingsUrl}">View theme site settings</a>'+ description: 'Site-wide themes that change the overall look and feel of your site for all users.'themes_intro: "Install a new theme to get started, or create your own from scratch using these resources."new_theme: "New theme"back: "Back to themes"diff --git a/config/routes.rb b/config/routes.rbindex 1ad1698545e..6e6595a2379 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -438,7 +438,6 @@ Discourse::Application.routes.draw doput "/logo" => "logo#update"put "/fonts" => "fonts#update"get "colors/:id" => "color_palettes#show"- get "theme-site-settings" => "theme_site_settings#index"get "colors" => "color_palettes#index"resources :flags, only: %i[index new create update destroy] do@@ -458,6 +457,7 @@ Discourse::Application.routes.draw docollection doget "/themes" => "customize#themes"get "/components" => "customize#components"+ get "/theme-site-settings" => "customize#theme_site_settings"endendenddiff --git a/spec/requests/admin/config/customize_controller_spec.rb b/spec/requests/admin/config/customize_controller_spec.rbindex 2fdffa5732c..f635f332670 100644--- a/spec/requests/admin/config/customize_controller_spec.rb+++ b/spec/requests/admin/config/customize_controller_spec.rb@@ -182,4 +182,80 @@ RSpec.describe Admin::Config::CustomizeController doendendend++ describe "#theme_site_settings" do+ fab!(:theme_1, :theme)+ fab!(:theme_2, :theme)+ fab!(:theme_3, :theme)+ fab!(:theme_1_theme_site_setting) do+ Fabricate(+ :theme_site_setting_with_service,+ theme: theme_1,+ name: "search_experience",+ value: "search_field",+ )+ end+ fab!(:theme_2_theme_site_setting) do+ Fabricate(+ :theme_site_setting_with_service,+ theme: theme_2,+ name: "enable_welcome_banner",+ value: false,+ )+ end++ it "gets all theme site settings and the themes which have overridden values for these settings" do+ get "/admin/config/customize/theme-site-settings.json"++ expect(response.status).to eq(200)+ json = response.parsed_body++ expect(json["themeable_site_settings"]).to include(+ "search_experience",+ "enable_welcome_banner",+ )++ search_setting =+ json["themes_with_site_setting_overrides"]["search_experience"].deep_symbolize_keys+ expect(search_setting[:setting]).to eq("search_experience")+ expect(search_setting[:default]).to eq("search_icon")+ expect(search_setting[:description]).to eq(I18n.t("site_settings.search_experience"))+ expect(search_setting[:type]).to eq("enum")+ expect(search_setting[:themes].find { |t| t[:theme_id] == theme_1.id }).to include(+ theme_name: theme_1.name,+ theme_id: theme_1.id,+ value: "search_field",+ )++ welcome_banner_setting =+ json["themes_with_site_setting_overrides"]["enable_welcome_banner"].deep_symbolize_keys+ expect(welcome_banner_setting[:setting]).to eq("enable_welcome_banner")+ expect(welcome_banner_setting[:default]).to eq(true)+ expect(welcome_banner_setting[:description]).to eq(+ I18n.t("site_settings.enable_welcome_banner"),+ )+ expect(welcome_banner_setting[:type]).to eq("bool")+ expect(welcome_banner_setting[:themes].find { |t| t[:theme_id] == theme_2.id }).to include(+ theme_name: theme_2.name,+ theme_id: theme_2.id,+ value: false,+ )+ end++ it "does not count theme site settings with same value as site setting default as overridden" do+ theme_2_theme_site_setting.update!(+ value: SiteSetting.type_supervisor.to_db_value(:enable_welcome_banner, true).first,+ )++ get "/admin/config/customize/theme-site-settings.json"++ expect(response.status).to eq(200)+ json = response.parsed_body++ welcome_banner_setting =+ json["themes_with_site_setting_overrides"]["enable_welcome_banner"].deep_symbolize_keys++ expect(welcome_banner_setting[:themes].find { |t| t[:theme_id] == theme_2.id }).to be_nil+ end+ endenddiff --git a/spec/requests/admin/theme_site_settings_controller_spec.rb b/spec/requests/admin/theme_site_settings_controller_spec.rbdeleted file mode 100644index d7b6dd06b52..00000000000--- a/spec/requests/admin/theme_site_settings_controller_spec.rb+++ /dev/null@@ -1,82 +0,0 @@-# frozen_string_literal: true--RSpec.describe Admin::Config::ThemeSiteSettingsController do- fab!(:admin)- fab!(:theme_1) { Fabricate(:theme) }- fab!(:theme_2) { Fabricate(:theme) }- fab!(:theme_3) { Fabricate(:theme) }- fab!(:theme_1_theme_site_setting) do- Fabricate(- :theme_site_setting_with_service,- theme: theme_1,- name: "search_experience",- value: "search_field",- )- end- fab!(:theme_2_theme_site_setting) do- Fabricate(- :theme_site_setting_with_service,- theme: theme_2,- name: "enable_welcome_banner",- value: false,- )- end-- before { sign_in(admin) }-- describe "#index" do- it "gets all theme site settings and the themes which have overridden values for these settings" do- get "/admin/config/theme-site-settings.json"-- expect(response.status).to eq(200)- json = response.parsed_body-- expect(json["themeable_site_settings"]).to include(- "search_experience",- "enable_welcome_banner",- )-- search_setting =- json["themes_with_site_setting_overrides"]["search_experience"].deep_symbolize_keys- expect(search_setting[:setting]).to eq("search_experience")- expect(search_setting[:default]).to eq("search_icon")- expect(search_setting[:description]).to eq(I18n.t("site_settings.search_experience"))- expect(search_setting[:type]).to eq("enum")- expect(search_setting[:themes].find { |t| t[:theme_id] == theme_1.id }).to include(- theme_name: theme_1.name,- theme_id: theme_1.id,- value: "search_field",- )-- welcome_banner_setting =- json["themes_with_site_setting_overrides"]["enable_welcome_banner"].deep_symbolize_keys- expect(welcome_banner_setting[:setting]).to eq("enable_welcome_banner")- expect(welcome_banner_setting[:default]).to eq(true)- expect(welcome_banner_setting[:description]).to eq(- I18n.t("site_settings.enable_welcome_banner"),- )- expect(welcome_banner_setting[:type]).to eq("bool")- expect(welcome_banner_setting[:themes].find { |t| t[:theme_id] == theme_2.id }).to include(- theme_name: theme_2.name,- theme_id: theme_2.id,- value: false,- )- end-- it "does not count theme site settings with same value as site setting default as overridden" do- theme_2_theme_site_setting.update!(- value: SiteSetting.type_supervisor.to_db_value(:enable_welcome_banner, true).first,- )-- get "/admin/config/theme-site-settings.json"-- expect(response.status).to eq(200)- json = response.parsed_body-- welcome_banner_setting =- json["themes_with_site_setting_overrides"]["enable_welcome_banner"].deep_symbolize_keys-- expect(welcome_banner_setting[:themes].find { |t| t[:theme_id] == theme_2.id }).to be_nil- end- end-enddiff --git a/spec/system/admin_config_theme_site_settings_spec.rb b/spec/system/admin_config_theme_site_settings_spec.rbindex 1c1689d1aa1..90f0f205e92 100644--- a/spec/system/admin_config_theme_site_settings_spec.rb+++ b/spec/system/admin_config_theme_site_settings_spec.rb@@ -26,13 +26,13 @@ describe "Admin Theme Site Settings", type: :system dobefore { sign_in(current_user) }it "shows the themeable site settings and their name, description, and default value" do- visit "/admin/config/theme-site-settings"+ visit "/admin/config/customize/theme-site-settings"expect(theme_site_settings_page).to have_setting_with_default("enable_welcome_banner")expect(theme_site_settings_page).to have_setting_with_default("search_experience")endit "shows links to each theme that overrides the default and overridden values" do- visit "/admin/config/theme-site-settings"+ visit "/admin/config/customize/theme-site-settings"expect(theme_site_settings_page).to have_theme_overriding("enable_welcome_banner",theme_1,