A platform for community discussion. Free, open, simple.
UX: show SCSS files in theme admin "extra files" section (#35300)
Krisbc9a661378f7
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes/show/index.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes/show/index.jsindex 72f71fd855e..62ae4d1e74e 100644--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes/show/index.js+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes/show/index.js@@ -44,7 +44,6 @@ export default class AdminCustomizeThemesShowIndexController extends Controller@mapBy("availableChildThemes", "name") availableComponentsNames;@mapBy("availableActiveChildThemes", "name") availableActiveComponentsNames;@mapBy("model.childThemes", "name") childThemesNames;- @filterBy("model.theme_fields", "target", "extra_js") extraFiles;@notEmpty("settings") hasSettings;@notEmpty("translations") hasTranslations;@notEmpty("model.themeable_site_settings") hasThemeableSiteSettings;@@ -56,6 +55,17 @@ export default class AdminCustomizeThemesShowIndexController extends Controllerreturn !this.model.component || this.model.remote_theme;}+ @discourseComputed("model.theme_fields.[]")+ extraFiles() {+ return this.model.theme_fields+ ?.filter(+ ({ target, type_id }) =>+ (target === "extra_js" && type_id === 6) ||+ (target === "extra_scss" && type_id === 1)+ )+ ?.sort((a, b) => (a.file_path || "").localeCompare(b.file_path || ""));+ }+@discourseComputed("model.editedFields")editedFieldsFormatted() {const descriptions = [];diff --git a/app/assets/javascripts/admin/addon/templates/admin-customize-themes/show/index.gjs b/app/assets/javascripts/admin/addon/templates/admin-customize-themes/show/index.gjsindex 98afe392606..b12e8bd83c1 100644--- a/app/assets/javascripts/admin/addon/templates/admin-customize-themes/show/index.gjs+++ b/app/assets/javascripts/admin/addon/templates/admin-customize-themes/show/index.gjs@@ -342,7 +342,7 @@ export default RouteTemplate(</summary><ul>{{#each @controller.extraFiles as |extraFile|}}- <li>{{extraFile.name}}</li>+ <li>{{extraFile.file_path}}</li>{{/each}}</ul></details>diff --git a/app/serializers/theme_field_serializer.rb b/app/serializers/theme_field_serializer.rbindex 19d0905e329..f75a14ca56c 100644--- a/app/serializers/theme_field_serializer.rb+++ b/app/serializers/theme_field_serializer.rb@@ -1,7 +1,16 @@# frozen_string_literal: trueclass ThemeFieldSerializer < ApplicationSerializer- attributes :name, :target, :value, :error, :type_id, :upload_id, :url, :filename, :migrated+ attributes :name,+ :target,+ :value,+ :error,+ :type_id,+ :upload_id,+ :url,+ :filename,+ :migrated,+ :file_pathdef include_url?object.uploaddiff --git a/spec/services/staff_action_logger_spec.rb b/spec/services/staff_action_logger_spec.rbindex 541330d225c..bb78775b4fe 100644--- a/spec/services/staff_action_logger_spec.rb+++ b/spec/services/staff_action_logger_spec.rb@@ -238,6 +238,7 @@ RSpec.describe StaffActionLogger doexpect(json["theme_fields"]).to eq([{+ "file_path" => "common/common.scss","name" => "scss","target" => "common","value" => "body{margin: 10px;}",@@ -278,6 +279,7 @@ RSpec.describe StaffActionLogger doexpect(json["theme_fields"]).to eq([{+ "file_path" => "common/common.scss","name" => "scss","target" => "common","value" => "body{margin: 10px;}",diff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rbindex a92d58a3e18..d684dd726d4 100644--- a/spec/system/admin_customize_themes_spec.rb+++ b/spec/system/admin_customize_themes_spec.rb@@ -116,9 +116,9 @@ describe "Admin Customize Themes", type: :system doendit "hides unecessary sections and buttons for system themes" do- theme.theme_fields.create!(- name: "js",- target_id: Theme.targets[:extra_js],+ theme.set_field(+ target: :extra_js,+ name: "discourse/api-initializers/test.js",value: "console.log('second test')",)yaml = <<~YAML@@ -149,6 +149,24 @@ describe "Admin Customize Themes", type: :system doexpect(page).to have_css(".theme-settings")end+ it "shows both JS and SCSS extra files with canonical paths" do+ theme.set_field(+ target: :extra_js,+ name: "discourse/api-initializers/canvas.js",+ value: "console.log('extra js')",+ )+ theme.set_field(target: :extra_scss, name: "properties", value: ".custom { color: red; }")+ theme.save!++ theme_page.visit(theme)++ extra_files = find(".extra-files")+ extra_files.find("summary").click++ expect(extra_files).to have_content("javascripts/discourse/api-initializers/canvas.js")+ expect(extra_files).to have_content("stylesheets/properties.scss")+ end+describe "when editing theme translations" doit "should allow admin to edit and save the theme translations" dotheme.set_field(