A platform for community discussion. Free, open, simple.
UX: Simplify admin theme editor (#31561)
David Taylor1bd61630ef30
diff --git a/app/assets/javascripts/admin/addon/components/admin-theme-editor.hbs b/app/assets/javascripts/admin/addon/components/admin-theme-editor.hbsindex 366e13b1bef..410ab1397f5 100644--- a/app/assets/javascripts/admin/addon/components/admin-theme-editor.hbs+++ b/app/assets/javascripts/admin/addon/components/admin-theme-editor.hbs@@ -1,39 +1,37 @@-<div class="edit-main-nav admin-controls">- <nav>- <ul class="nav nav-pills target">- {{#each this.visibleTargets as |target|}}+{{#if (gt this.visibleTargets.length 1)}}+ <div class="edit-main-nav admin-controls">+ <nav>+ <ul class="nav nav-pills target">+ {{#each this.visibleTargets as |target|}}+ <li>+ <LinkTo+ @route={{this.editRouteName}}+ @models={{array this.theme.id target.name this.fieldName}}+ @replace={{true}}+ title={{this.field.title}}+ class={{if target.edited "edited" "blank"}}+ >+ {{#if target.error}}{{d-icon "triangle-exclamation"}}{{/if}}+ {{#if target.icon}}{{d-icon target.icon}}{{/if}}+ {{i18n (concat "admin.customize.theme." target.name)}}+ </LinkTo>+ </li>+ {{/each}}+ <li class="spacer"></li><li>- <LinkTo- @route={{this.editRouteName}}- @models={{array this.theme.id target.name this.fieldName}}- @replace={{true}}- title={{this.field.title}}- class={{if target.edited "edited" "blank"}}- >- {{#if target.error}}{{d-icon "triangle-exclamation"}}{{/if}}- {{#if target.icon}}{{d-icon target.icon}}{{/if}}- {{i18n (concat "admin.customize.theme." target.name)}}- </LinkTo>+ <label>+ <Input+ @type="checkbox"+ @checked={{this.showAdvanced}}+ {{on "click" this.toggleShowAdvanced}}+ />+ {{i18n "admin.customize.theme.show_advanced"}}+ </label></li>- {{/each}}-- <li class="spacer"></li>- <li>- <label>- <Input- @type="checkbox"- @checked={{this.onlyOverridden}}- {{on- "click"- (action this.onlyOverriddenChanged value="target.checked")- }}- />- {{i18n "admin.customize.theme.hide_unused_fields"}}- </label>- </li>- </ul>- </nav>-</div>+ </ul>+ </nav>+ </div>+{{/if}}<div class="admin-controls"><nav>@@ -56,6 +54,16 @@<li class="spacer"></li><li>+ {{#if (lte this.visibleTargets.length 1)}}+ <label>+ <Input+ @type="checkbox"+ @checked={{this.showAdvanced}}+ {{on "click" this.toggleShowAdvanced}}+ />+ {{i18n "admin.customize.theme.show_advanced"}}+ </label>+ {{/if}}<a href {{on "click" this.toggleMaximize}} class="no-text">{{d-icon this.maximizeIcon}}</a>@@ -72,6 +80,10 @@<pre class="field-warning">{{html-safe this.warning}}</pre>{{/if}}+<div class="field-info">+ {{this.currentField.title}}+</div>+<AceEditor@content={{this.activeSection}}@onChange={{fn (mut this.activeSection)}}diff --git a/app/assets/javascripts/admin/addon/components/admin-theme-editor.js b/app/assets/javascripts/admin/addon/components/admin-theme-editor.jsindex b721eb05035..e9a3b3cd583 100644--- a/app/assets/javascripts/admin/addon/components/admin-theme-editor.js+++ b/app/assets/javascripts/admin/addon/components/admin-theme-editor.js@@ -1,6 +1,8 @@+import { tracked } from "@glimmer/tracking";import Component from "@ember/component";import { action, computed } from "@ember/object";import { next } from "@ember/runloop";+import { service } from "@ember/service";import { fmt } from "discourse/lib/computed";import discourseComputed from "discourse/lib/decorators";import { isDocumentRTL } from "discourse/lib/text-direction";@@ -13,30 +15,59 @@ export default apiInitializer((api) => {});`;+const ADVANCED_TARGETS = ["desktop", "mobile"];++const ADVANCED_FIELDS = [+ "embedded_scss",+ "embedded_header",+ "color_definitions",+ "body_tag",+];+export default class AdminThemeEditor extends Component {+ @service router;++ @tracked showAdvanced;+ @tracked onlyOverridden;+ @tracked currentTargetName;+warning = null;@fmt("fieldName", "currentTargetName", "%@|%@") editorId;- @discourseComputed("theme.targets", "onlyOverridden")- visibleTargets(targets, onlyOverridden) {- return targets.filter((target) => {- if (!onlyOverridden) {+ get visibleTargets() {+ return this.theme.targets.filter((target) => {+ if (target.edited) {+ return true;+ }+ if (!this.showAdvanced && ADVANCED_TARGETS.includes(target.name)) {+ return false;+ }+ if (!this.onlyOverridden) {return true;}- return target.edited;});}- @discourseComputed("currentTargetName", "onlyOverridden", "theme.fields")- visibleFields(targetName, onlyOverridden, fields) {- fields = fields[targetName];- if (onlyOverridden) {+ get visibleFields() {+ let fields = this.theme.fields[this.currentTargetName];+ if (this.onlyOverridden) {fields = fields.filter((field) => field.edited);}+ if (!this.showAdvanced) {+ fields = fields.filter(+ (field) => field.edited || !ADVANCED_FIELDS.includes(field.name)+ );+ }return fields;}+ get currentField() {+ return this.theme.fields[this.currentTargetName].find(+ (field) => field.name === this.fieldName+ );+ }+@discourseComputed("currentTargetName", "fieldName")activeSectionMode(targetName, fieldName) {if (fieldName === "color_definitions") {@@ -107,4 +138,20 @@ export default class AdminThemeEditor extends Component {setWarning(message) {this.set("warning", message);}++ @action+ toggleShowAdvanced() {+ this.showAdvanced = !this.showAdvanced;+ if (+ !this.visibleTargets.some((t) => t.name === this.currentTargetName) ||+ !this.visibleFields.some((f) => f.name === this.fieldName)+ ) {+ this.router.replaceWith(+ this.editRouteName,+ this.theme.id,+ this.visibleTargets[0].name,+ this.visibleFields[0].name+ );+ }+ }}diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-edit.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-edit.jsindex b53cf9c3a36..7ebcc47f429 100644--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-edit.js+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-themes-edit.js@@ -59,25 +59,6 @@ export default class AdminCustomizeThemesEditController extends Controller {);}- @action- onlyOverriddenChanged(onlyShowOverridden) {- if (onlyShowOverridden) {- if (!this.model.hasEdited(this.currentTargetName, this.fieldName)) {- let firstTarget = this.get("model.targets").find((t) => t.edited);- let firstField = this.get(`model.fields.${firstTarget.name}`).find(- (f) => f.edited- );-- this.router.replaceWith(- this.editRouteName,- this.get("model.id"),- firstTarget.name,- firstField.name- );- }- }- }-@actiongoBack() {this.router.replaceWith(this.showRouteName, this.model.id);diff --git a/app/assets/javascripts/admin/addon/templates/customize-themes-edit.hbs b/app/assets/javascripts/admin/addon/templates/customize-themes-edit.hbsindex 1267773b1c0..12933e8f173 100644--- a/app/assets/javascripts/admin/addon/templates/customize-themes-edit.hbs+++ b/app/assets/javascripts/admin/addon/templates/customize-themes-edit.hbs@@ -28,7 +28,6 @@@fieldName={{this.fieldName}}@fieldAdded={{action "fieldAdded"}}@maximized={{this.maximized}}- @onlyOverriddenChanged={{action "onlyOverriddenChanged"}}@save={{action "save"}}/>diff --git a/app/assets/stylesheets/admin/customize.scss b/app/assets/stylesheets/admin/customize.scssindex 3b57ece9b14..62cb2e20f12 100644--- a/app/assets/stylesheets/admin/customize.scss+++ b/app/assets/stylesheets/admin/customize.scss@@ -108,6 +108,12 @@background-color: var(--highlight-bg);}+ .field-info {+ background-color: var(--tertiary-low);+ padding: 10px;+ margin: 10px 0;+ }+.admin-container {padding-left: 10px;padding-right: 10px;diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 49644b53be7..76458e933ff 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -6180,7 +6180,7 @@ en:extra_files_remote: "Export theme or check the git repository to view these files."preview: "Preview"settings_editor: "Settings Editor"- hide_unused_fields: "Hide unused fields"+ show_advanced: "Show advanced"is_default: "Theme is enabled by default"user_selectable: "Theme can be selected by users"color_scheme_user_selectable: "Color palette can be selected by users"@@ -6234,9 +6234,9 @@ en:unsaved_parent_themes: "You haven't assigned the component to themes, do you want to move on?"discard: "Discard"stay: "Stay"- css_html: "Custom CSS/HTML"- edit_css_html: "Edit CSS/HTML"- edit_css_html_help: "You have not edited any CSS or HTML"+ css_html: "Custom Code"+ edit_css_html: "Edit Code"+ edit_css_html_help: "You have not edited any code yet."delete_upload_confirm: "Delete this upload? (Theme CSS may stop working!)"component_on_themes: "Include component on these themes"included_components: "Included components"@@ -6297,22 +6297,22 @@ en:imported_from_archive: "This theme was imported from a .zip file"scss:text: "CSS"- title: "Enter custom CSS, we accept all valid CSS and SCSS styles"+ title: "Custom CSS rules with support for SCSS syntax"header:- text: "Header"- title: "Enter HTML to display above site header"+ text: "Before Header"+ title: "Basic HTML to be rendered above the Discourse header"after_header:text: "After Header"- title: "Enter HTML to display on all pages after header"+ title: "Basic HTML to be rendered below the Discourse header"footer:text: "Footer"- title: "Enter HTML to display on page footer"+ title: "Basic HTML to be rendered at the bottom of the page"embedded_scss:text: "Embedded CSS"- title: "Enter custom CSS to deliver with embedded version of comments"+ title: "CSS to be included when Discourse comments are embedded in another site"embedded_header:text: "Embedded Header"- title: "Enter HTML to display above the embedded version of comments"+ title: "Basic HTML which will be rendered above the Discourse comments when embedded in another site"color_definitions:text: "Color Definitions"title: "Enter custom color definitions (advanced users only)"@@ -6326,17 +6326,14 @@ en:Prefixing the property names is highly recommended to avoid conflicts with plugins and/or core.head_tag:- text: "Head"- title: "HTML that will be inserted before the head tag"+ text: "<head>"+ title: "HTML to insert at the end of the <head>, with support for script tags"body_tag:- text: "Body"- title: "HTML that will be inserted before the body tag"- yaml:- text: "YAML"- title: "Define theme settings in YAML format"+ text: "<body>"+ title: "HTML to insert at the end of the <body>, with support for script tags"js:text: "JS"- title: "Define a JavaScript initializer"+ title: "JavaScript initializer with support for Ember's 'template tag' syntax"scss_color_variables_warning: 'Using core SCSS color variables in themes is deprecated. Please use CSS custom properties instead. See <a href="https://meta.discourse.org/t/-/77551#color-variables-2" target="_blank">this guide</a> for more details.'scss_warning_inline: "Using core SCSS color variables in themes is deprecated."all_filter: "All"