A platform for community discussion. Free, open, simple.
FEATURE: Enable new color palette edit page (#34566)
Osama Sayeghc2e567443d6e
diff --git a/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palette.gjs b/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palette.gjsindex 51baef856a9..51bc6100302 100644--- a/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palette.gjs+++ b/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palette.gjs@@ -1,9 +1,12 @@import Component from "@glimmer/component";import { cached, tracked } from "@glimmer/tracking";+import { array } from "@ember/helper";import { action } from "@ember/object";+import { LinkTo } from "@ember/routing";import { service } from "@ember/service";import DButton from "discourse/components/d-button";import Form from "discourse/components/form";+import icon from "discourse/helpers/d-icon";import { ajax } from "discourse/lib/ajax";import { extractError } from "discourse/lib/ajax-error";import { clipboardCopy } from "discourse/lib/utilities";@@ -44,6 +47,10 @@ export default class AdminConfigAreasColorPalette extends Component {);}+ get installedWithTheme() {+ return !!this.args.colorPalette.theme_id;+ }+@cachedget data() {return {@@ -65,6 +72,9 @@ export default class AdminConfigAreasColorPalette extends Component {@actiontoggleEditingName() {this.editingName = !this.editingName;+ if (!this.editingName) {+ this.fkApi.set("name", this.args.colorPalette.name);+ }}@action@@ -173,17 +183,16 @@ export default class AdminConfigAreasColorPalette extends Component {@actionasync duplicate() {const copy = this.args.colorPalette.copy();+ const originalName = this.args.colorPalette.name;copy.name = i18n("admin.config_areas.color_palettes.copy_of", {- name: this.args.colorPalette.name,+ name: originalName,});await copy.save();- await this.router.replaceWith("adminConfig.colorPalettes");- await this.router.refresh();await this.router.replaceWith("adminConfig.colorPalettes.show", copy);this.toasts.success({data: {message: i18n("admin.config_areas.color_palettes.copy_created", {- name: this.args.colorPalette.name,+ name: originalName,}),},});@@ -196,7 +205,6 @@ export default class AdminConfigAreasColorPalette extends Component {didConfirm: async () => {await this.args.colorPalette.destroy();await this.router.replaceWith("adminConfig.colorPalettes");- await this.router.refresh();},});}@@ -250,63 +258,88 @@ export default class AdminConfigAreasColorPalette extends Component {}<template>- <Form- data-palette-id={{@colorPalette.id}}- @data={{this.data}}- @onSubmit={{this.handleSubmit}}- @onRegisterApi={{this.onRegisterApi}}- as |form transientData|- >- <div>- <div class="admin-config-color-palettes__top-controls">- {{#if this.editingName}}- <form.Field- @name="name"- @showTitle={{false}}- @title={{i18n "admin.config_areas.color_palettes.palette_name"}}- @validation="required"- @format="full"- @onSet={{this.handleNameChange}}- as |field|- >+ <div class="admin-config-area__primary-content">+ <div class="admin-config-color-palettes__back">+ <LinkTo @route="adminConfig.colorPalettes">+ {{icon "angle-left"}}+ {{i18n "admin.customize.colors.back_to_colors"}}+ </LinkTo>+ </div>+ <Form+ data-palette-id={{@colorPalette.id}}+ @data={{this.data}}+ @onSubmit={{this.handleSubmit}}+ @onRegisterApi={{this.onRegisterApi}}+ as |form transientData|+ >+ <div class="admin-config-color-palettes__header">+ <div class="admin-config-color-palettes__top-controls">+ {{#if this.editingName}}+ <form.Field+ @name="name"+ @showTitle={{false}}+ @title={{i18n "admin.config_areas.color_palettes.palette_name"}}+ @validation="required"+ @format="full"+ @onSet={{this.handleNameChange}}+ as |field|+ >+ <div class="admin-config-color-palettes__name-control">+ <field.Input />+ <DButton+ class="btn-primary admin-config-color-palettes__save-name"+ @icon="check"+ @action={{this.triggerNameSave}}+ />+ <DButton+ class="btn-flat admin-config-color-palettes__cancel-edit-name"+ @icon="xmark"+ @action={{this.toggleEditingName}}+ />+ </div>+ </form.Field>+ {{else}}<div class="admin-config-color-palettes__name-control">- <field.Input />- <DButton- class="btn-primary admin-config-color-palettes__save-name"- @icon="check"- @action={{this.triggerNameSave}}- />- <DButton- class="btn-flat"- @icon="xmark"- @action={{this.toggleEditingName}}- />+ <h2+ class="admin-config-color-palettes__name"+ >{{@colorPalette.name}}</h2>+ {{#unless this.installedWithTheme}}+ <DButton+ class="btn-flat admin-config-color-palettes__edit-name"+ @icon="pencil"+ @action={{this.toggleEditingName}}+ />+ {{/unless}}</div>- </form.Field>- {{else}}- <div class="admin-config-color-palettes__name-control">- <h2- class="admin-config-color-palettes__name"- >{{@colorPalette.name}}</h2>+ {{/if}}+ <div class="admin-config-color-palettes__top-actions"><DButton- class="btn-flat admin-config-color-palettes__edit-name"- @icon="pencil"- @action={{this.toggleEditingName}}+ class="duplicate-palette"+ @label="admin.config_areas.color_palettes.duplicate"+ @action={{this.duplicate}}/>+ {{#unless this.installedWithTheme}}+ <DButton+ class="btn-danger delete-palette"+ @label="admin.config_areas.color_palettes.delete"+ @action={{this.delete}}+ />+ {{/unless}}</div>- {{/if}}- <div class="admin-config-color-palettes__top-actions">- <DButton- class="duplicate-palette"- @label="admin.config_areas.color_palettes.duplicate"- @action={{this.duplicate}}- />- <DButton- class="btn-danger delete-palette"- @label="admin.config_areas.color_palettes.delete"- @action={{this.delete}}- /></div>+ {{#if this.installedWithTheme}}+ <div class="admin-config-color-palettes__theme-owner">+ {{icon "circle-info"}}+ <span>{{i18n "admin.customize.theme_owner"}}+ <LinkTo+ @route="adminCustomizeThemes.show"+ @models={{array "themes" @colorPalette.theme_id}}+ >+ {{@colorPalette.theme_name}}+ </LinkTo>+ </span>+ </div>+ {{/if}}</div><div class="admin-config-color-palettes__sections"><AdminConfigAreaCard@@ -381,6 +414,7 @@ export default class AdminConfigAreasColorPalette extends Component {><field.Custom><ColorPaletteEditor+ @disabled={{this.installedWithTheme}}@colors={{transientData.colors}}@onColorChange={{this.onColorChange}}/>@@ -409,7 +443,7 @@ export default class AdminConfigAreasColorPalette extends Component {</:content></AdminConfigAreaCard></div>- </div>- </Form>+ </Form>+ </div></template>}diff --git a/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palettes.gjs b/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palettes.gjsdeleted file mode 100644index c74aeafff97..00000000000--- a/app/assets/javascripts/admin/addon/components/admin-config-areas/color-palettes.gjs+++ /dev/null@@ -1,108 +0,0 @@-import Component from "@glimmer/component";-import { action } from "@ember/object";-import { LinkTo } from "@ember/routing";-import { service } from "@ember/service";-import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";-import DButton from "discourse/components/d-button";-import DPageHeader from "discourse/components/d-page-header";-import PluginOutlet from "discourse/components/plugin-outlet";-import { i18n } from "discourse-i18n";-import ColorSchemeSelectBaseModal from "admin/components/modal/color-scheme-select-base";--export default class AdminConfigAreasColorPalettes extends Component {- @service router;- @service modal;-- @action- newColorPalette() {- // If a base palette exists in database, it should be removed from the list in the modal as potential base to not display duplicated names.- const deduplicatedColorPalettes = this.args.palettes.filter((base) => {- if (- base.id < 0 &&- this.args.palettes.find((palette) => {- return (- palette.name === base.name &&- palette.base_scheme_id === base.base_scheme_id &&- palette.id > 0- );- })- ) {- return false;- }- return true;- });- this.modal.show(ColorSchemeSelectBaseModal, {- model: {- colorSchemes: deduplicatedColorPalettes,- newColorSchemeWithBase: this.newColorPaletteWithBase,- },- });- }-- @action- async newColorPaletteWithBase(baseKey) {- const base = this.args.palettes.find((palette) => palette.id === baseKey);- const newPalette = base.copy();- newPalette.setProperties({- name: i18n("admin.customize.colors.new_name"),- base_scheme_id: base.get("id"),- });- await newPalette.save();- newPalette.colors.forEach((color) => {- color.default_hex = color.originals.hex;- });- await this.router.refresh();- this.router.replaceWith("adminConfig.colorPalettes.show", newPalette);- }-- <template>- <DPageHeader- @titleLabel={{i18n "admin.config.color_palettes.title"}}- @descriptionLabel={{i18n- "admin.config.color_palettes.header_description"- }}- @learnMoreUrl="https://meta.discourse.org/t/allow-users-to-select-new-color-palettes/60857"- @hideTabs={{true}}- >- <:breadcrumbs>- <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />- <DBreadcrumbsItem- @path="/admin/config/colors"- @label={{i18n "admin.config.color_palettes.title"}}- />- </:breadcrumbs>- </DPageHeader>-- <div class="admin-config-area">- <div class="admin-config-area__aside color-palettes-list">- <PluginOutlet @name="admin-customize-colors-new-button">- <DButton- @action={{this.newColorPalette}}- @icon="plus"- @label="admin.customize.new"- class="btn-default create-new-palette"- />- </PluginOutlet>- <ul>- {{#each @palettes as |palette|}}- {{#unless palette.is_base}}- <li data-palette-id={{palette.id}}>- <LinkTo- @route="adminConfig.colorPalettes.show"- @model={{palette}}- @replace={{true}}- >- {{palette.description}}- </LinkTo>- </li>- {{/unless}}- {{/each}}- </ul>- </div>-- <div class="admin-config-area__primary-content">- {{outlet}}- </div>- </div>- </template>-}diff --git a/app/assets/javascripts/admin/addon/components/color-palette-editor.gjs b/app/assets/javascripts/admin/addon/components/color-palette-editor.gjsindex da7bd564578..93a871e959a 100644--- a/app/assets/javascripts/admin/addon/components/color-palette-editor.gjs+++ b/app/assets/javascripts/admin/addon/components/color-palette-editor.gjs@@ -5,6 +5,7 @@ import { on } from "@ember/modifier";import { action } from "@ember/object";import didInsert from "@ember/render-modifiers/modifiers/did-insert";import { service } from "@ember/service";+import { or } from "truth-helpers";import DButton from "discourse/components/d-button";import concatClass from "discourse/helpers/concat-class";import icon from "discourse/helpers/d-icon";@@ -170,7 +171,7 @@ const Picker = class extends Component {data-position={{@position}}type="color"value={{this.activeValue}}- disabled={{@system}}+ disabled={{or @system @disabled}}title={{this.disabledEditForSystemDescription}}{{on "input" this.onInput}}{{on "change" this.onChange}}@@ -182,7 +183,7 @@ const Picker = class extends Component {data-position={{@position}}type="text"maxlength="6"- disabled={{@system}}+ disabled={{or @system @disabled}}title={{this.disabledEditForSystemDescription}}value={{this.displayedColor}}{{on "keypress" this.onTextKeypress}}@@ -239,8 +240,9 @@ export default class ColorPaletteEditor extends Component {@editorElement={{this.editorElement}}@onChange={{fn @onColorChange color}}@system={{@system}}+ @disabled={{@disabled}}/>- {{#unless @hideRevertButton}}+ {{#unless @disabled}}<DButtonclass={{concatClass"btn-flat"diff --git a/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs b/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjsindex 725935ea714..6a99ba460db 100644--- a/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs+++ b/app/assets/javascripts/admin/addon/components/color-palette-list-item.gjs@@ -158,7 +158,7 @@ export default class ColorPaletteListItem extends Component {<DButtonTooltip><:button><DButton- @route="adminCustomize.colors-show"+ @route="adminConfig.colorPalettes.show"@routeModels={{array @scheme.id}}@label={{this.editButtonLabel}}class="btn-secondary"diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js b/app/assets/javascripts/admin/addon/controllers/admin-config-color-palettes-index.jssimilarity index 98%rename from app/assets/javascripts/admin/addon/controllers/admin-customize-colors.jsrename to app/assets/javascripts/admin/addon/controllers/admin-config-color-palettes-index.jsindex 5d0f3884cdf..954b149e3d6 100644--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js+++ b/app/assets/javascripts/admin/addon/controllers/admin-config-color-palettes-index.js@@ -7,7 +7,7 @@ import { i18n } from "discourse-i18n";import ColorSchemeSelectBaseModal from "admin/components/modal/color-scheme-select-base";import { setDefaultColorScheme } from "admin/lib/color-scheme-manager";-export default class AdminCustomizeColorsController extends Controller {+export default class AdminConfigColorPalettesIndexController extends Controller {@service router;@service modal;@service store;@@ -195,7 +195,7 @@ export default class AdminCustomizeColorsController extends Controller {this.model.pushObject(newColorScheme);newColorScheme.set("savingStatus", null);- this.router.replaceWith("adminCustomize.colors-show", newColorScheme);+ this.router.replaceWith("adminConfig.colorPalettes.show", newColorScheme);});}diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js b/app/assets/javascripts/admin/addon/controllers/admin-config-color-palettes-show.jssimilarity index 77%rename from app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.jsrename to app/assets/javascripts/admin/addon/controllers/admin-config-color-palettes-show.jsindex ddec15c0fbe..9e0583c83cf 100644--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors-show.js+++ b/app/assets/javascripts/admin/addon/controllers/admin-config-color-palettes-show.js@@ -5,7 +5,7 @@ import discourseLater from "discourse/lib/later";import { clipboardCopy } from "discourse/lib/utilities";import { i18n } from "discourse-i18n";-export default class AdminCustomizeColorsShowController extends Controller {+export default class AdminConfigColorPalettesShowController extends Controller {@service dialog;@service router;@@ -50,7 +50,7 @@ export default class AdminCustomizeColorsShowController extends Controller {}@action- copy() {+ async copy() {const newColorScheme = this.model.copy();newColorScheme.set("name",@@ -58,10 +58,8 @@ export default class AdminCustomizeColorsShowController extends Controller {" " +this.get("model.name"));- newColorScheme.save().then(() => {- this.allColors.pushObject(newColorScheme);- this.router.replaceWith("adminCustomize.colors-show", newColorScheme);- });+ await newColorScheme.save();+ this.router.replaceWith("adminConfig.colorPalettes.show", newColorScheme);}@action@@ -79,11 +77,9 @@ export default class AdminCustomizeColorsShowController extends Controller {destroy() {return this.dialog.deleteConfirm({title: i18n("admin.customize.colors.delete_confirm"),- didConfirm: () => {- return this.model.destroy().then(() => {- this.allColors.removeObject(this.model);- this.router.replaceWith("adminCustomize.colors");- });+ didConfirm: async () => {+ await this.model.destroy();+ this.router.replaceWith("adminConfig.colorPalettes");},});}diff --git a/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes-index.js b/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes-index.jsnew file mode 100644index 00000000000..dee8d4f2915--- /dev/null+++ b/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes-index.js@@ -0,0 +1,29 @@+import Route from "@ember/routing/route";+import { service } from "@ember/service";+import { ajax } from "discourse/lib/ajax";+import ColorScheme from "admin/models/color-scheme";+import Theme from "admin/models/theme";++export default class AdminConfigColorPalettesIndexRoute extends Route {+ @service store;++ async model() {+ return await ajax("/admin/config/colors");+ }++ setupController(controller, model) {+ super.setupController(controller, model);+ const defaultTheme = model.extras.default_theme+ ? Theme.create(model.extras.default_theme)+ : null;+ controller.set(+ "model",+ model.palettes.map((palette) => ColorScheme.create(palette))+ );+ controller.set("defaultTheme", defaultTheme);++ if (defaultTheme) {+ controller._captureInitialState();+ }+ }+}diff --git a/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes-show.js b/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes-show.jsindex 55bb88fec27..5fdfb6e9207 100644--- a/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes-show.js+++ b/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes-show.js@@ -1,11 +1,24 @@-import DiscourseRoute from "discourse/routes/discourse";+import Route from "@ember/routing/route";+import { service } from "@ember/service";+import { ajax } from "discourse/lib/ajax";+import ColorScheme from "admin/models/color-scheme";-export default class AdminConfigColorPalettesShowRoute extends DiscourseRoute {- model(params) {- const id = parseInt(params.palette_id, 10);+export default class AdminConfigColorPalettesShowRoute extends Route {+ @service router;- return this.modelFor("adminConfig.colorPalettes").content.find(- (palette) => palette.id === id- );+ async model(params) {+ try {+ return ColorScheme.create(+ await ajax(`/admin/config/colors/${params.palette_id}`)+ );+ } catch (e) {+ // eslint-disable-next-line no-console+ console.error(e);+ this.router.replaceWith("adminConfig.colorPalettes");+ }+ }++ serialize(model) {+ return { palette_id: model.get("id") };}}diff --git a/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes.js b/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes.jsdeleted file mode 100644index d853a7b4b9f..00000000000--- a/app/assets/javascripts/admin/addon/routes/admin-config-color-palettes.js+++ /dev/null@@ -1,8 +0,0 @@-import DiscourseRoute from "discourse/routes/discourse";-import ColorScheme from "admin/models/color-scheme";--export default class AdminConfigColorPalettesRoute extends DiscourseRoute {- model() {- return ColorScheme.findAll();- }-}diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-colors-show.js b/app/assets/javascripts/admin/addon/routes/admin-customize-colors-show.jsindex 0834afc778d..108a12d3ee0 100644--- a/app/assets/javascripts/admin/addon/routes/admin-customize-colors-show.js+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-colors-show.js@@ -1,29 +1,14 @@import Route from "@ember/routing/route";import { service } from "@ember/service";-import ColorScheme from "admin/models/color-scheme";export default class AdminCustomizeColorsShowRoute extends Route {@service router;- model(params) {- return ColorScheme.findAll().then((all) => {- const model = all.findBy("id", parseInt(params.scheme_id, 10));- if (model) {- return model;- } else {- this.router.replaceWith("adminCustomize.colors");- }- });- }-- serialize(model) {- return { scheme_id: model.get("id") };- }-- setupController(controller) {- super.setupController(...arguments);- ColorScheme.findAll().then((all) => {- controller.set("allColors", all);- });+ beforeModel(transition) {+ transition.abort();+ this.router.replaceWith(+ "adminConfig.colorPalettes.show",+ transition.to.params.scheme_id+ );}}diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-colors.js b/app/assets/javascripts/admin/addon/routes/admin-customize-colors.jsindex 8dc282c7a7d..c2b08712ea9 100644--- a/app/assets/javascripts/admin/addon/routes/admin-customize-colors.js+++ b/app/assets/javascripts/admin/addon/routes/admin-customize-colors.js@@ -1,29 +1,11 @@import Route from "@ember/routing/route";import { service } from "@ember/service";-import { ajax } from "discourse/lib/ajax";-import ColorScheme from "admin/models/color-scheme";-import Theme from "admin/models/theme";export default class AdminCustomizeColorsRoute extends Route {- @service store;+ @service router;- async model() {- return await ajax("/admin/config/colors");- }-- setupController(controller, model) {- super.setupController(controller, model);- const defaultTheme = model.extras.default_theme- ? Theme.create(model.extras.default_theme)- : null;- controller.set(- "model",- model.palettes.map((palette) => ColorScheme.create(palette))- );- controller.set("defaultTheme", defaultTheme);-- if (defaultTheme) {- controller._captureInitialState();- }+ beforeModel(transition) {+ transition.abort();+ this.router.replaceWith("adminConfig.colorPalettes");}}diff --git a/app/assets/javascripts/admin/addon/templates/customize-colors.gjs b/app/assets/javascripts/admin/addon/templates/config-color-palettes-index.gjssimilarity index 97%rename from app/assets/javascripts/admin/addon/templates/customize-colors.gjsrename to app/assets/javascripts/admin/addon/templates/config-color-palettes-index.gjsindex da6b993aefb..790b9ba0647 100644--- a/app/assets/javascripts/admin/addon/templates/customize-colors.gjs+++ b/app/assets/javascripts/admin/addon/templates/config-color-palettes-index.gjs@@ -18,7 +18,7 @@ export default RouteTemplate(<:breadcrumbs><DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} /><DBreadcrumbsItem- @path="/admin/customize/colors"+ @path="/admin/config/colors"@label={{i18n "admin.config.color_palettes.title"}}/></:breadcrumbs>@@ -37,6 +37,7 @@ export default RouteTemplate(@outletArgs={{lazyHash actions=actions controller=@controller}}><actions.Primary+ class="create-new-palette"@label="admin.customize.new"@action={{@controller.newColorScheme}}@icon="plus"diff --git a/app/assets/javascripts/admin/addon/templates/config-color-palettes.gjs b/app/assets/javascripts/admin/addon/templates/config-color-palettes.gjsdeleted file mode 100644index ec8a160bf4d..00000000000--- a/app/assets/javascripts/admin/addon/templates/config-color-palettes.gjs+++ /dev/null@@ -1,6 +0,0 @@-import RouteTemplate from "ember-route-template";-import ColorPalettes from "admin/components/admin-config-areas/color-palettes";--export default RouteTemplate(- <template><ColorPalettes @palettes={{@model.content}} /></template>-);diff --git a/app/assets/javascripts/admin/addon/templates/customize-colors-show.gjs b/app/assets/javascripts/admin/addon/templates/customize-colors-show.gjsdeleted file mode 100644index cf6fdde5042..00000000000--- a/app/assets/javascripts/admin/addon/templates/customize-colors-show.gjs+++ /dev/null@@ -1,163 +0,0 @@-import { Input } from "@ember/component";-import { array, fn } from "@ember/helper";-import { LinkTo } from "@ember/routing";-import RouteTemplate from "ember-route-template";-import DButton from "discourse/components/d-button";-import TextField from "discourse/components/text-field";-import concatClass from "discourse/helpers/concat-class";-import icon from "discourse/helpers/d-icon";-import { i18n } from "discourse-i18n";-import ColorInput from "admin/components/color-input";-import InlineEditCheckbox from "admin/components/inline-edit-checkbox";--export default RouteTemplate(- <template>- <div class="back-to-color-palettes">- <LinkTo @route="adminCustomize.colors">- {{icon "angle-left"}}- {{i18n "admin.customize.colors.back_to_colors"}}- </LinkTo>- </div>-- <div class="color-scheme show-current-style">- <div class="admin-container">- <h1>{{#if- @controller.model.theme_id- }}{{@controller.model.name}}{{else}}<TextField- @value={{@controller.model.name}}- class="style-name"- />{{/if}}</h1>- <div class="controls">- {{#unless @controller.model.theme_id}}- <DButton- @action={{@controller.save}}- @disabled={{@controller.model.disableSave}}- @label="admin.customize.save"- class="btn-primary"- />- {{/unless}}- <DButton- @action={{fn @controller.copy @controller.model}}- @icon="copy"- @label="admin.customize.copy"- class="btn-default"- />- <DButton- @action={{fn @controller.copyToClipboard @controller.model}}- @icon="far-clipboard"- @label="admin.customize.copy_to_clipboard"- class="btn-default copy-to-clipboard"- />- <span- class="saving {{unless @controller.model.savingStatus 'hidden'}}"- >{{@controller.model.savingStatus}}</span>- {{#if @controller.model.theme_id}}- <span class="not-editable">- {{i18n "admin.customize.theme_owner"}}- <LinkTo- @route="adminCustomizeThemes.show"- @models={{array "themes" @controller.model.theme_id}}- >{{@controller.model.theme_name}}</LinkTo>- </span>- {{else}}- <DButton- @action={{@controller.destroy}}- @icon="trash-can"- @label="admin.customize.delete"- class="btn-danger"- />- {{/if}}- </div>-- <div class="admin-controls">- <div class="pull-left">- {{#if @controller.model.theme_id}}- <InlineEditCheckbox- @action={{@controller.applyUserSelectable}}- @labelKey="admin.customize.theme.color_scheme_user_selectable"- @checked={{@controller.model.user_selectable}}- @modelId={{@controller.model.id}}- />- {{else}}- <label class="checkbox-label">- <Input- @type="checkbox"- @checked={{@controller.model.user_selectable}}- />- {{i18n "admin.customize.theme.color_scheme_user_selectable"}}- </label>- {{/if}}- </div>-- {{#unless @controller.model.theme_id}}- <div class="pull-right">- <label class="checkbox-label">- <Input- @type="checkbox"- @checked={{@controller.onlyOverridden}}- />- {{i18n "admin.settings.show_overriden"}}- </label>- </div>- {{/unless}}- </div>-- {{#if @controller.colors.length}}- <table class="table colors">- <thead>- <tr>- <th></th>- <th class="hex">{{i18n "admin.customize.color"}}</th>- <th></th>- </tr>- </thead>- <tbody>- {{#each @controller.colors as |c|}}- <tr- class="{{if c.changed 'changed'}}- {{if c.valid 'valid' 'invalid'}}"- >- <td class="name" title={{c.name}}>- <h3>{{c.translatedName}}</h3>- <p class="description">{{c.description}}</p>- </td>- <td class="hex"><ColorInput- @hexValue={{c.hex}}- @brightnessValue={{c.brightness}}- @valid={{c.valid}}- /></td>- <td class="actions">- {{#unless @controller.model.theme_id}}- <DButton- @action={{fn @controller.revert c}}- @title="admin.customize.colors.revert_title"- @label="admin.customize.colors.revert"- class={{concatClass- "btn-default"- "revert"- (unless c.savedIsOverriden "invisible")- }}- />- <DButton- @action={{fn @controller.undo c}}- @title="admin.customize.colors.undo_title"- @label="admin.customize.colors.undo"- class={{concatClass- "btn-default"- "undo"- (unless c.changed "invisible")- }}- />- {{/unless}}- </td>- </tr>- {{/each}}- </tbody>- </table>- {{else}}- <p>{{i18n "search.no_results"}}</p>- {{/if}}- </div>- </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 bcf6cf01385..98afe392606 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@@ -148,7 +148,7 @@ export default RouteTemplate({{#if @controller.colorSchemeId}}<LinkTo- @route="adminCustomize.colors-show"+ @route="adminConfig.colorPalettes.show"@model={{@controller.colorSchemeId}}>{{i18n "admin.customize.theme.edit_colors"}}@@ -201,7 +201,7 @@ export default RouteTemplate({{#if @controller.darkColorSchemeId}}<LinkTo- @route="adminCustomize.colors-show"+ @route="adminConfig.colorPalettes.show"@model={{@controller.darkColorSchemeId}}>{{i18n "admin.customize.theme.edit_colors"}}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 51717c0401c..6f066ed882f 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@@ -233,7 +233,7 @@ export const ADMIN_NAV_MAP = [},{name: "admin_color_palettes",- route: "adminCustomize.colors",+ route: "adminConfig.colorPalettes",label: "admin.config.color_palettes.title",description: "admin.config.color_palettes.header_description",icon: "palette",diff --git a/app/assets/stylesheets/admin/admin_config_area.scss b/app/assets/stylesheets/admin/admin_config_area.scssindex 31fd014f819..52498e2a3ef 100644--- a/app/assets/stylesheets/admin/admin_config_area.scss+++ b/app/assets/stylesheets/admin/admin_config_area.scss@@ -44,7 +44,6 @@&__content {margin-top: 0.5rem;- padding-right: 15px;}}diff --git a/app/assets/stylesheets/admin/admin_config_color_palettes.scss b/app/assets/stylesheets/admin/admin_config_color_palettes.scssindex 9b9773d6005..34c6ec5024b 100644--- a/app/assets/stylesheets/admin/admin_config_color_palettes.scss+++ b/app/assets/stylesheets/admin/admin_config_color_palettes.scss@@ -39,27 +39,34 @@&__name-control {display: flex;gap: var(--space-1);-- .form-kit__container-content,- .form-kit__control-input-wrapper,- input[name="name"] {- height: 100%;- }+ align-items: flex-start;h2 {margin-bottom: 0;}}+ &__header {+ width: 100%;+ display: flex;+ flex-direction: column;+ gap: var(--space-1);+ }++ &__theme-owner {+ font-size: var(--font-down-1);+ color: var(--primary-medium);+ }+&__top-controls {display: flex;justify-content: space-between;- margin-bottom: 1em;}&__sections {display: flex;flex-direction: column;+ width: 100%;gap: var(--space-4);}@@ -80,6 +87,13 @@justify-content: flex-end;gap: 1em;}++ &__save-name,+ &__cancel-edit-name {+ // matches form kit height of inputs+ height: 2em;+ width: 2em;+ }}.alert {diff --git a/app/controllers/admin/color_schemes_controller.rb b/app/controllers/admin/color_schemes_controller.rbindex e7df21b7f0b..f04d78936df 100644--- a/app/controllers/admin/color_schemes_controller.rb+++ b/app/controllers/admin/color_schemes_controller.rb@@ -19,7 +19,20 @@ class Admin::ColorSchemesController < Admin::AdminControllerenddef update- color_scheme = ColorSchemeRevisor.revise(@color_scheme, color_scheme_params)+ update_params = color_scheme_params++ if @color_scheme.theme_id.present?+ if (update_params.key?(:name) && update_params[:name] != @color_scheme.name) ||+ update_params[:colors].present? ||+ (+ update_params.key?(:base_scheme_id) &&+ update_params[:base_scheme_id] != @color_scheme.base_scheme_id+ )+ raise Discourse::InvalidAccess+ end+ end++ color_scheme = ColorSchemeRevisor.revise(@color_scheme, update_params)update_theme_default_scheme!if color_scheme.valid?render json: color_scheme, root: false@@ -29,6 +42,8 @@ class Admin::ColorSchemesController < Admin::AdminControllerenddef destroy+ raise Discourse::InvalidAccess if @color_scheme.theme_id.present?+@color_scheme.destroyrender json: success_jsonend@@ -57,14 +72,16 @@ class Admin::ColorSchemesController < Admin::AdminControllerdef update_theme_default_scheme!update_opts = {}if color_scheme_params.has_key?(:default_light_on_theme)- update_opts[:color_scheme_id] = if color_scheme_params[:default_light_on_theme] != "false"+ update_opts[:color_scheme_id] = if color_scheme_params[:default_light_on_theme].to_s !=+ "false"@color_scheme.idelsenilendendif color_scheme_params.has_key?(:default_dark_on_theme)- update_opts[:dark_color_scheme_id] = if color_scheme_params[:default_dark_on_theme] != "false"+ update_opts[:dark_color_scheme_id] = if color_scheme_params[:default_dark_on_theme].to_s !=+ "false"@color_scheme.idelsenildiff --git a/spec/requests/admin/color_schemes_controller_spec.rb b/spec/requests/admin/color_schemes_controller_spec.rbindex 21cdc023425..d389b8ee7c9 100644--- a/spec/requests/admin/color_schemes_controller_spec.rb+++ b/spec/requests/admin/color_schemes_controller_spec.rb@@ -4,6 +4,7 @@ RSpec.describe Admin::ColorSchemesController dofab!(:admin)fab!(:moderator)fab!(:user)+ fab!(:theme)let(:valid_params) do{@@ -186,6 +187,42 @@ RSpec.describe Admin::ColorSchemesController doexpect(default_theme.color_scheme_id).to eq(existing.id)expect(default_theme.dark_color_scheme_id).to eq(existing.id)end++ it "doesn't allow editing the name or colors of a theme-owned palette" do+ existing.update!(theme_id: theme.id)++ put "/admin/color_schemes/#{existing.id}.json", params: valid_params++ expect(response.status).to eq(403)+ end++ it "allows making a theme-owned palette user selectable" do+ existing.update!(theme_id: theme.id, user_selectable: false)++ put "/admin/color_schemes/#{existing.id}.json",+ params: {+ color_scheme: {+ user_selectable: true,+ },+ }++ expect(response.status).to eq(200)+ expect(existing.reload.user_selectable).to eq(true)+ end++ it "allows making a theme-owned palette the default theme's palette" do+ existing.update!(theme_id: theme.id)++ put "/admin/color_schemes/#{existing.id}.json",+ params: {+ color_scheme: {+ default_light_on_theme: true,+ },+ }++ expect(response.status).to eq(200)+ expect(Theme.find_default.reload.color_scheme_id).to eq(existing.id)+ endendshared_examples "color scheme update not allowed" do@@ -222,6 +259,15 @@ RSpec.describe Admin::ColorSchemesController do}.by(-1)expect(response.status).to eq(200)end++ it "doesn't allow deleting a theme-owned palette" do+ existing.update!(theme_id: theme.id)++ expect { delete "/admin/color_schemes/#{existing.id}.json" }.not_to change {+ ColorScheme.count+ }+ expect(response.status).to eq(403)+ endendshared_examples "color scheme deletion not allowed" dodiff --git a/spec/system/admin_color_palette_config_area_spec.rb b/spec/system/admin_color_palette_config_area_spec.rbindex a2ade84aefa..d1a1abff688 100644--- a/spec/system/admin_color_palette_config_area_spec.rb+++ b/spec/system/admin_color_palette_config_area_spec.rb@@ -3,6 +3,7 @@describe "Admin Color Palette Config Area Page", type: :system dofab!(:admin)fab!(:color_scheme) { Fabricate(:color_scheme, user_selectable: false, name: "A Test Palette") }+ fab!(:color_scheme_2, :color_scheme)let(:config_area) { PageObjects::Pages::AdminColorPaletteConfigArea.new }let(:toasts) { PageObjects::Components::Toasts.new }@@ -205,4 +206,33 @@ describe "Admin Color Palette Config Area Page", type: :system doexpect(color.hex).to eq(clipboard_scheme["light"][color.name])endend++ it "can toggle light and dark palette as default on default theme" do+ Theme.find_default.update!(color_scheme: color_scheme)++ config_area.visit(color_scheme.id)+ expect(page).to have_text(+ I18n.t(+ "admin_js.admin.config_areas.color_palettes.color_options.toggle_default_light_on_theme",+ themeName: "Foundation",+ ),+ )+ expect(page).to have_text(+ I18n.t(+ "admin_js.admin.config_areas.color_palettes.color_options.toggle_default_dark_on_theme",+ themeName: "Foundation",+ ),+ )+ config_area.default_light_on_theme_field.have_value?(true)+ config_area.default_dark_on_theme_field.have_value?(false)+ config_area.default_light_on_theme_field.toggle+ config_area.default_dark_on_theme_field.toggle+ config_area.form.submit+ config_area.default_light_on_theme_field.have_value?(false)+ config_area.default_dark_on_theme_field.have_value?(true)++ config_area.visit(color_scheme_2.id)+ config_area.default_light_on_theme_field.have_value?(false)+ config_area.default_dark_on_theme_field.have_value?(false)+ endenddiff --git a/spec/system/admin_color_palettes_config_area_spec.rb b/spec/system/admin_color_palettes_config_area_spec.rbindex 01ceb1ad685..fb828777d45 100644--- a/spec/system/admin_color_palettes_config_area_spec.rb+++ b/spec/system/admin_color_palettes_config_area_spec.rb@@ -2,28 +2,77 @@describe "Admin Color Palettes Config Area Page", type: :system dofab!(:admin)- fab!(:palette_1) { Fabricate(:color_scheme, user_selectable: false, name: "A Test Palette 1") }- fab!(:palette_2) { Fabricate(:color_scheme, user_selectable: false, name: "A Test Palette 2") }- let(:dark_palette) { ColorScheme.find_by(name: "Dark") }+ fab!(:palette) { Fabricate(:color_scheme, user_selectable: false, name: "A Test Palette") }+ fab!(:theme) { Fabricate(:theme, name: "Test Theme") }+ fab!(:user_selectable_palette) do+ Fabricate(:color_scheme, name: "User Selectable", user_selectable: true)+ end+ fab!(:theme_palette) { Fabricate(:color_scheme, name: "Theme Palette", theme: theme) }+ fab!(:regular_palette) do+ Fabricate(:color_scheme, name: "Regular Palette", user_selectable: false)+ end++ let(:foundation_scheme_a) do+ Fabricate(:color_scheme, name: "Foundation scheme a", theme: Theme.foundation_theme)+ end+ let(:foundation_scheme_b) do+ Fabricate(:color_scheme, name: "Foundation scheme b", theme: Theme.foundation_theme)+ end+ let(:horizon_scheme_a) do+ Fabricate(:color_scheme, name: "Horizon scheme a", theme: Theme.horizon_theme)+ end+ let(:horizon_scheme_b) do+ Fabricate(:color_scheme, name: "Horizon scheme b", theme: Theme.horizon_theme)+ end+ let(:custom_scheme_a) { Fabricate(:color_scheme, name: "Custom scheme a") }+ let(:custom_scheme_b) { Fabricate(:color_scheme, name: "Custom scheme b") }+ let(:selectable_foundation_scheme_a) do+ Fabricate(+ :color_scheme,+ name: "Selectable foundation scheme a",+ theme: Theme.foundation_theme,+ user_selectable: true,+ )+ end+ let(:selectable_foundation_scheme_b) do+ Fabricate(+ :color_scheme,+ name: "Selectable foundation scheme b",+ theme: Theme.foundation_theme,+ user_selectable: true,+ )+ end+ let(:selectable_horizon_theme_scheme_a) do+ Fabricate(+ :color_scheme,+ name: "Selectable horizon scheme a",+ theme: Theme.horizon_theme,+ user_selectable: true,+ )+ end+ let(:selectable_horizon_theme_scheme_b) do+ Fabricate(+ :color_scheme,+ name: "Selectable horizon scheme b",+ theme: Theme.horizon_theme,+ user_selectable: true,+ )+ end+ let(:selectable_custom_scheme_a) do+ Fabricate(:color_scheme, name: "Selectable custom scheme a", user_selectable: true)+ end+ let(:selectable_custom_scheme_b) do+ Fabricate(:color_scheme, name: "Selectable custom scheme b", user_selectable: true)+ end+ let(:default_light_scheme) { Fabricate(:color_scheme, name: "Default light") }+ let(:default_dark_scheme) { Fabricate(:color_scheme, name: "Default dark") }let(:config_area) { PageObjects::Pages::AdminColorPalettesConfigArea.new }- let(:edit_config_area) { PageObjects::Pages::AdminColorPaletteConfigArea.new }let(:create_color_palette_modal) { PageObjects::Modals::CreateColorPalette.new }+ let(:toasts) { PageObjects::Components::Toasts.new }before { sign_in(admin) }- it "can navigate between different palettes" do- config_area.visit-- config_area.palette(palette_1.id).click- expect(edit_config_area.palette_id).to eq(palette_1.id)- expect(page).to have_current_path("/admin/config/colors/#{palette_1.id}")-- config_area.palette(palette_2.id).click- expect(edit_config_area.palette_id).to eq(palette_2.id)- expect(page).to have_current_path("/admin/config/colors/#{palette_2.id}")- end-it "can create new color palettes" doconfig_area.visit@@ -40,7 +89,7 @@ describe "Admin Color Palettes Config Area Page", type: :system doconfig_area.create_button.clickcreate_color_palette_modal.base_dropdown.expandexpect(page).to have_css(".color-palette-picker-row")- create_color_palette_modal.base_dropdown.select_row_by_name("A Test Palette 2")+ create_color_palette_modal.base_dropdown.select_row_by_name("A Test Palette")create_color_palette_modal.create_button.click@@ -48,32 +97,256 @@ describe "Admin Color Palettes Config Area Page", type: :system doexpect(page).to have_no_css(".revert")end- it "can toggle light and dark palette as default on default theme" do- Theme.find_default.update!(color_scheme: palette_1)+ describe "filtering" do+ it "shows filters when there are more than 8 color schemes" do+ config_area.visit- edit_config_area.visit(palette_1.id)- expect(page).to have_text(- I18n.t(- "admin_js.admin.config_areas.color_palettes.color_options.toggle_default_light_on_theme",- themeName: "Foundation",- ),- )- expect(page).to have_text(- I18n.t(- "admin_js.admin.config_areas.color_palettes.color_options.toggle_default_dark_on_theme",- themeName: "Foundation",- ),- )- edit_config_area.default_light_on_theme_field.have_value?(true)- edit_config_area.default_dark_on_theme_field.have_value?(false)- edit_config_area.default_light_on_theme_field.toggle- edit_config_area.default_dark_on_theme_field.toggle- edit_config_area.form.submit- edit_config_area.default_light_on_theme_field.have_value?(false)- edit_config_area.default_dark_on_theme_field.have_value?(true)-- edit_config_area.visit(palette_2.id)- edit_config_area.default_light_on_theme_field.have_value?(false)- edit_config_area.default_dark_on_theme_field.have_value?(false)+ expect(page).to have_css(".admin-filter-controls__input")+ end++ it "can filter by text search" do+ config_area.visit++ find(".admin-filter-controls__input").fill_in(with: user_selectable_palette.name)++ expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")+ expect(page).to have_no_css("[data-palette-id='#{regular_palette.id}']")+ end++ it "can filter by type" do+ config_area.visit++ select_kit = PageObjects::Components::DSelect.new(".d-select")+ select_kit.select("user_selectable")++ expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")+ expect(page).to have_no_css("[data-palette-id='#{regular_palette.id}']")+ expect(page).to have_no_css(".color-palette:not([data-palette-id])")+ end++ it "shows no results state" do+ config_area.visit++ find(".admin-filter-controls__input").fill_in(with: "bananas")++ expect(page).to have_css(".admin-filter-controls__no-results")+ expect(page).to have_css("button", text: I18n.t("admin_js.admin.plugins.filters.reset"))+ end+ end++ describe "color palette list items" do+ it "shows palette details" do+ config_area.visit++ expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")+ expect(page).to have_css("[data-palette-id='#{theme_palette.id}']")+ expect(page).to have_css("[data-palette-id='#{regular_palette.id}']")+ end++ it "shows user selectable badge" do+ config_area.visit++ within("[data-palette-id='#{user_selectable_palette.id}']") do+ expect(page).to have_css(".theme-card__badge.--selectable")+ end+ end++ it "shows theme link for theme palettes" do+ config_area.visit++ within("[data-palette-id='#{theme_palette.id}']") { expect(page).to have_link(theme.name) }+ end++ it "can toggle user selectable status" do+ config_area.visit++ within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }++ expect(page).to have_css(".dropdown-menu")+ click_button(I18n.t("admin_js.admin.customize.theme.user_selectable_button_label"))++ within("[data-palette-id='#{regular_palette.id}']") do+ expect(page).to have_css(".theme-card__badge.--selectable")+ end+ end++ it "can set as light and dark default for theme" do+ config_area.visit++ within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }++ expect(page).to have_css(".dropdown-menu")++ click_button(+ I18n.t(+ "admin_js.admin.customize.colors.set_default_light",+ { theme: Theme.find_default.name },+ ),+ )++ within("[data-palette-id='#{regular_palette.id}']") do+ expect(page).to have_css(+ ".theme-card__badge.--default",+ text: I18n.t("admin_js.admin.customize.colors.default_light_badge.text"),+ )+ end++ within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }++ expect(page).to have_css(".dropdown-menu")++ click_button(+ I18n.t(+ "admin_js.admin.customize.colors.set_default_dark",+ { theme: Theme.find_default.name },+ ),+ )++ within("[data-palette-id='#{regular_palette.id}']") do+ expect(page).to have_css(+ ".theme-card__badge.--default",+ text: I18n.t("admin_js.admin.customize.colors.default_dark_badge.text"),+ )+ end+ end+ end++ describe "CSS variables" do+ it "generates CSS variables for color schemes" do+ config_area.visit++ palette_item = find("[data-palette-id='#{regular_palette.id}'] .color-palette__preview")++ expect(palette_item[:style]).to include("--primary--preview:")+ expect(palette_item[:style]).to include("--secondary--preview:")+ expect(palette_item[:style]).to include("--tertiary--preview:")+ end+ end++ describe "live preview functionality" do+ it "does not show toast when live preview is available" do+ admin.user_option.update!(+ theme_ids: [Theme.find_default.id],+ color_scheme_id: -1,+ dark_scheme_id: -1,+ )++ config_area.visit++ within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }++ expect(page).to have_css(".dropdown-menu")++ click_button(+ I18n.t(+ "admin_js.admin.customize.colors.set_default_light",+ { theme: Theme.find_default.name },+ ),+ )++ expect(page).to have_no_css(".fk-d-default-toast.-success")+ end++ it "shows toast when admin cannot see live preview" do+ custom_scheme = Fabricate(:color_scheme, name: "Custom Scheme")+ admin.user_option.update!(+ theme_ids: [Theme.find_default.id],+ color_scheme_id: custom_scheme.id,+ )++ config_area.visit++ within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }++ expect(page).to have_css(".dropdown-menu")++ click_button(+ I18n.t(+ "admin_js.admin.customize.colors.set_default_light",+ { theme: Theme.find_default.name },+ ),+ )++ expected_message =+ I18n.t(+ "admin_js.admin.customize.colors.set_default_success",+ schemeName: regular_palette.name,+ themeName: Theme.find_default.name,+ )+ expect(toasts).to have_success(expected_message)+ end+ end++ describe "sort" do+ before do+ ColorScheme.delete_all+ foundation_scheme_a+ foundation_scheme_b+ horizon_scheme_a+ horizon_scheme_b+ custom_scheme_a+ custom_scheme_b+ selectable_foundation_scheme_a+ selectable_foundation_scheme_b+ selectable_horizon_theme_scheme_a+ selectable_horizon_theme_scheme_b+ selectable_custom_scheme_a+ selectable_custom_scheme_b+ default_light_scheme+ default_dark_scheme+ Theme.horizon_theme.update!(+ color_scheme: default_light_scheme,+ dark_color_scheme: default_dark_scheme,+ )+ end+ it "sorts schemes in order: selectable, custom, current default theme, alphabetical for horizon theme" do+ SiteSetting.default_theme_id = Theme.horizon_theme.id+ config_area.visit+ color_schemes = page.all(".color-palette__details h3").map(&:text)+ expect(color_schemes).to eq(+ [+ "Default light",+ "Default dark",+ "Selectable custom scheme a",+ "Selectable custom scheme b",+ "Selectable horizon scheme a",+ "Selectable horizon scheme b",+ "Selectable foundation scheme a",+ "Selectable foundation scheme b",+ "Custom scheme a",+ "Custom scheme b",+ "Horizon scheme a",+ "Horizon scheme b",+ "Foundation scheme a",+ "Foundation scheme b",+ "Light (default)",+ ],+ )+ end++ it "sorts schemes in order: selectable, custom, current default theme, alphabetical for foundation theme" do+ SiteSetting.default_theme_id = Theme.foundation_theme.id+ config_area.visit+ color_schemes = page.all(".color-palette__details h3").map(&:text)+ expect(color_schemes).to eq(+ [+ "Light (default)",+ "Selectable custom scheme a",+ "Selectable custom scheme b",+ "Selectable foundation scheme a",+ "Selectable foundation scheme b",+ "Selectable horizon scheme a",+ "Selectable horizon scheme b",+ "Custom scheme a",+ "Custom scheme b",+ "Default dark",+ "Default light",+ "Foundation scheme a",+ "Foundation scheme b",+ "Horizon scheme a",+ "Horizon scheme b",+ ],+ )+ endendenddiff --git a/spec/system/admin_color_palettes_features_spec.rb b/spec/system/admin_color_palettes_features_spec.rbdeleted file mode 100644index f64ca3e3333..00000000000--- a/spec/system/admin_color_palettes_features_spec.rb+++ /dev/null@@ -1,339 +0,0 @@-# frozen_string_literal: true--describe "Admin Color Palettes Features", type: :system do- fab!(:admin)- fab!(:theme) { Fabricate(:theme, name: "Test Theme") }- fab!(:user_selectable_palette) do- Fabricate(:color_scheme, name: "User Selectable", user_selectable: true)- end- fab!(:theme_palette) { Fabricate(:color_scheme, name: "Theme Palette", theme: theme) }- fab!(:regular_palette) do- Fabricate(:color_scheme, name: "Regular Palette", user_selectable: false)- end-- let(:toasts) { PageObjects::Components::Toasts.new }-- let(:foundation_scheme_a) do- Fabricate(:color_scheme, name: "Foundation scheme a", theme: Theme.foundation_theme)- end- let(:foundation_scheme_b) do- Fabricate(:color_scheme, name: "Foundation scheme b", theme: Theme.foundation_theme)- end- let(:horizon_scheme_a) do- Fabricate(:color_scheme, name: "Horizon scheme a", theme: Theme.horizon_theme)- end- let(:horizon_scheme_b) do- Fabricate(:color_scheme, name: "Horizon scheme b", theme: Theme.horizon_theme)- end- let(:custom_scheme_a) { Fabricate(:color_scheme, name: "Custom scheme a") }- let(:custom_scheme_b) { Fabricate(:color_scheme, name: "Custom scheme b") }- let(:selectable_foundation_scheme_a) do- Fabricate(- :color_scheme,- name: "Selectable foundation scheme a",- theme: Theme.foundation_theme,- user_selectable: true,- )- end- let(:selectable_foundation_scheme_b) do- Fabricate(- :color_scheme,- name: "Selectable foundation scheme b",- theme: Theme.foundation_theme,- user_selectable: true,- )- end- let(:selectable_horizon_theme_scheme_a) do- Fabricate(- :color_scheme,- name: "Selectable horizon scheme a",- theme: Theme.horizon_theme,- user_selectable: true,- )- end- let(:selectable_horizon_theme_scheme_b) do- Fabricate(- :color_scheme,- name: "Selectable horizon scheme b",- theme: Theme.horizon_theme,- user_selectable: true,- )- end- let(:selectable_custom_scheme_a) do- Fabricate(:color_scheme, name: "Selectable custom scheme a", user_selectable: true)- end- let(:selectable_custom_scheme_b) do- Fabricate(:color_scheme, name: "Selectable custom scheme b", user_selectable: true)- end- let(:default_light_scheme) { Fabricate(:color_scheme, name: "Default light") }- let(:default_dark_scheme) { Fabricate(:color_scheme, name: "Default dark") }- let(:create_color_palette_modal) { PageObjects::Modals::CreateColorPalette.new }-- before { sign_in(admin) }-- describe "filtering" do- it "shows filters when there are more than 8 color schemes" do- visit("/admin/customize/colors")-- expect(page).to have_css(".admin-filter-controls__input")- end-- it "can filter by text search" do- visit("/admin/customize/colors")-- find(".admin-filter-controls__input").fill_in(with: user_selectable_palette.name)-- expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")- expect(page).to have_no_css("[data-palette-id='#{regular_palette.id}']")- end-- it "can filter by type" do- visit("/admin/customize/colors")-- select_kit = PageObjects::Components::DSelect.new(".d-select")- select_kit.select("user_selectable")-- expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")- expect(page).to have_no_css("[data-palette-id='#{regular_palette.id}']")- expect(page).to have_no_css(".color-palette:not([data-palette-id])")- end-- it "shows no results state" do- visit("/admin/customize/colors")-- find(".admin-filter-controls__input").fill_in(with: "bananas")-- expect(page).to have_css(".admin-filter-controls__no-results")- expect(page).to have_css("button", text: I18n.t("admin_js.admin.plugins.filters.reset"))- end- end-- describe "color palette list items" do- it "shows palette details" do- visit("/admin/customize/colors")-- expect(page).to have_css("[data-palette-id='#{user_selectable_palette.id}']")- expect(page).to have_css("[data-palette-id='#{theme_palette.id}']")- expect(page).to have_css("[data-palette-id='#{regular_palette.id}']")- end-- it "shows user selectable badge" do- visit("/admin/customize/colors")-- within("[data-palette-id='#{user_selectable_palette.id}']") do- expect(page).to have_css(".theme-card__badge.--selectable")- end- end-- it "shows theme link for theme palettes" do- visit("/admin/customize/colors")-- within("[data-palette-id='#{theme_palette.id}']") { expect(page).to have_link(theme.name) }- end-- it "can toggle user selectable status" do- visit("/admin/customize/colors")-- within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }-- expect(page).to have_css(".dropdown-menu")- click_button(I18n.t("admin_js.admin.customize.theme.user_selectable_button_label"))-- within("[data-palette-id='#{regular_palette.id}']") do- expect(page).to have_css(".theme-card__badge.--selectable")- end- end-- it "can set as light and dark default for theme" do- visit("/admin/customize/colors")-- within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }-- expect(page).to have_css(".dropdown-menu")-- click_button(- I18n.t(- "admin_js.admin.customize.colors.set_default_light",- { theme: Theme.find_default.name },- ),- )-- within("[data-palette-id='#{regular_palette.id}']") do- expect(page).to have_css(- ".theme-card__badge.--default",- text: I18n.t("admin_js.admin.customize.colors.default_light_badge.text"),- )- end-- within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }-- expect(page).to have_css(".dropdown-menu")-- click_button(- I18n.t(- "admin_js.admin.customize.colors.set_default_dark",- { theme: Theme.find_default.name },- ),- )-- within("[data-palette-id='#{regular_palette.id}']") do- expect(page).to have_css(- ".theme-card__badge.--default",- text: I18n.t("admin_js.admin.customize.colors.default_dark_badge.text"),- )- end- end- end-- describe "CSS variables" do- it "generates CSS variables for color schemes" do- visit("/admin/customize/colors")-- palette_item = find("[data-palette-id='#{regular_palette.id}'] .color-palette__preview")-- expect(palette_item[:style]).to include("--primary--preview:")- expect(palette_item[:style]).to include("--secondary--preview:")- expect(palette_item[:style]).to include("--tertiary--preview:")- end- end-- describe "live preview functionality" do- it "does not show toast when live preview is available" do- admin.user_option.update!(- theme_ids: [Theme.find_default.id],- color_scheme_id: -1,- dark_scheme_id: -1,- )-- visit("/admin/customize/colors")-- within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }-- expect(page).to have_css(".dropdown-menu")-- click_button(- I18n.t(- "admin_js.admin.customize.colors.set_default_light",- { theme: Theme.find_default.name },- ),- )-- expect(page).to have_no_css(".fk-d-default-toast.-success")- end-- it "shows toast when admin cannot see live preview" do- custom_scheme = Fabricate(:color_scheme, name: "Custom Scheme")- admin.user_option.update!(- theme_ids: [Theme.find_default.id],- color_scheme_id: custom_scheme.id,- )-- visit("/admin/customize/colors")-- within("[data-palette-id='#{regular_palette.id}']") { find(".btn-flat").click }-- expect(page).to have_css(".dropdown-menu")-- click_button(- I18n.t(- "admin_js.admin.customize.colors.set_default_light",- { theme: Theme.find_default.name },- ),- )-- expected_message =- I18n.t(- "admin_js.admin.customize.colors.set_default_success",- schemeName: regular_palette.name,- themeName: Theme.find_default.name,- )- expect(toasts).to have_success(expected_message)- end- end-- describe "sort" do- before do- ColorScheme.delete_all- foundation_scheme_a- foundation_scheme_b- horizon_scheme_a- horizon_scheme_b- custom_scheme_a- custom_scheme_b- selectable_foundation_scheme_a- selectable_foundation_scheme_b- selectable_horizon_theme_scheme_a- selectable_horizon_theme_scheme_b- selectable_custom_scheme_a- selectable_custom_scheme_b- default_light_scheme- default_dark_scheme- Theme.horizon_theme.update!(- color_scheme: default_light_scheme,- dark_color_scheme: default_dark_scheme,- )- end- it "sorts schemes in order: selectable, custom, current default theme, alphabetical for horizon theme" do- SiteSetting.default_theme_id = Theme.horizon_theme.id- visit("/admin/customize/colors")- color_schemes = page.all(".color-palette__details h3").map(&:text)- expect(color_schemes).to eq(- [- "Default light",- "Default dark",- "Selectable custom scheme a",- "Selectable custom scheme b",- "Selectable horizon scheme a",- "Selectable horizon scheme b",- "Selectable foundation scheme a",- "Selectable foundation scheme b",- "Custom scheme a",- "Custom scheme b",- "Horizon scheme a",- "Horizon scheme b",- "Foundation scheme a",- "Foundation scheme b",- "Light (default)",- ],- )- end-- it "sorts schemes in order: selectable, custom, current default theme, alphabetical for foundation theme" do- SiteSetting.default_theme_id = Theme.foundation_theme.id- visit("/admin/customize/colors")- color_schemes = page.all(".color-palette__details h3").map(&:text)- expect(color_schemes).to eq(- [- "Light (default)",- "Selectable custom scheme a",- "Selectable custom scheme b",- "Selectable foundation scheme a",- "Selectable foundation scheme b",- "Selectable horizon scheme a",- "Selectable horizon scheme b",- "Custom scheme a",- "Custom scheme b",- "Default dark",- "Default light",- "Foundation scheme a",- "Foundation scheme b",- "Horizon scheme a",- "Horizon scheme b",- ],- )- end- end-- it "can create new color palette from custom palette" do- visit("/admin/customize/colors")-- page.find(".d-page-action-button").click-- create_color_palette_modal.base_dropdown.select_row_by_name("Theme Palette")-- create_color_palette_modal.create_button.click-- expect(page).to have_current_path(%r{/admin/customize/colors/\d+})- expect(page).to have_no_css(".revert")- end-enddiff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rbindex fa5e5d4ef27..a92d58a3e18 100644--- a/spec/system/admin_customize_themes_spec.rb+++ b/spec/system/admin_customize_themes_spec.rb@@ -32,7 +32,7 @@ describe "Admin Customize Themes", type: :system doexpect(page).to have_link(I18n.t("admin_js.admin.customize.theme.edit_colors"),- href: "/admin/customize/colors/#{color_scheme.id}",+ href: "/admin/config/colors/#{color_scheme.id}",)end@@ -54,7 +54,7 @@ describe "Admin Customize Themes", type: :system doexpect(page).to have_link(I18n.t("admin_js.admin.customize.theme.edit_colors"),- href: "/admin/customize/colors/#{color_scheme.id}",+ href: "/admin/config/colors/#{color_scheme.id}",)end