Skip to content

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

UX: Replace dropdown with a dedicated index page for email templates (#35284)

Osama Sayegh43013b7b7627
diff --git a/app/assets/javascripts/admin/addon/components/admin-filter-controls.gjs b/app/assets/javascripts/admin/addon/components/admin-filter-controls.gjs
index c80c2561059..2b08bfdf338 100644
--- a/app/assets/javascripts/admin/addon/components/admin-filter-controls.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-filter-controls.gjs
@@ -175,6 +175,7 @@ export default class AdminFilterControls extends Component {
</div>
{{/if}}
+ {{yield to="aboveContent"}}
{{#if this.filteredData.length}}
{{yield this.filteredData to="content"}}
{{else if this.showFilters}}
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-email-templates.js b/app/assets/javascripts/admin/addon/controllers/admin-email-templates.js
deleted file mode 100644
index dbf78e79aba..00000000000
--- a/app/assets/javascripts/admin/addon/controllers/admin-email-templates.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import Controller from "@ember/controller";
-import { action } from "@ember/object";
-import { sort } from "@ember/object/computed";
-import { service } from "@ember/service";
-
-export default class AdminEmailTemplatesController extends Controller {
- @service router;
-
- titleSorting = ["title"];
- @sort("emailTemplates", "titleSorting") sortedTemplates;
-
- @action
- onSelectTemplate(template) {
- this.router.transitionTo("adminEmailTemplates.edit", template);
- }
-}
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-email-templates/index.js b/app/assets/javascripts/admin/addon/controllers/admin-email-templates/index.js
new file mode 100644
index 00000000000..c631a0b813f
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/controllers/admin-email-templates/index.js
@@ -0,0 +1,24 @@
+import { tracked } from "@glimmer/tracking";
+import Controller from "@ember/controller";
+import { action } from "@ember/object";
+import { sort } from "@ember/object/computed";
+
+export default class AdminEmailTemplatesIndexController extends Controller {
+ @tracked showOverridenOnly = false;
+
+ titleSorting = ["title"];
+ @sort("emailTemplates", "titleSorting") sortedTemplates;
+
+ get shownTemplates() {
+ if (this.showOverridenOnly) {
+ return this.sortedTemplates.filter((template) => template.can_revert);
+ } else {
+ return this.sortedTemplates;
+ }
+ }
+
+ @action
+ toggleOverridenOnly() {
+ this.showOverridenOnly = !this.showOverridenOnly;
+ }
+}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-email-templates.js b/app/assets/javascripts/admin/addon/routes/admin-email-templates.js
index 41289ff7a34..1b85a5f6153 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-email-templates.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-email-templates.js
@@ -1,27 +1,7 @@
-import { action } from "@ember/object";
import Route from "@ember/routing/route";
-import { service } from "@ember/service";
export default class AdminEmailTemplatesRoute extends Route {
- @service router;
-
model() {
return this.store.findAll("email-template");
}
-
- setupController(controller, model) {
- controller.set("emailTemplates", model);
- }
-
- @action
- didTransition() {
- const editController = this.controllerFor("adminEmailTemplates.edit");
-
- if (!editController.emailTemplate) {
- this.router.transitionTo(
- "adminEmailTemplates.edit",
- this.controller.get("sortedTemplates.firstObject")
- );
- }
- }
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-email-templates/index.js b/app/assets/javascripts/admin/addon/routes/admin-email-templates/index.js
new file mode 100644
index 00000000000..6a1fe3be842
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/routes/admin-email-templates/index.js
@@ -0,0 +1,8 @@
+import Route from "@ember/routing/route";
+
+export default class AdminEmailTemplatesIndexRoute extends Route {
+ setupController(controller) {
+ const parentController = this.controllerFor("adminEmailTemplates");
+ controller.set("emailTemplates", parentController.get("model"));
+ }
+}
diff --git a/app/assets/javascripts/admin/addon/templates/admin-email-templates.gjs b/app/assets/javascripts/admin/addon/templates/admin-email-templates.gjs
deleted file mode 100644
index 76ab5bd9893..00000000000
--- a/app/assets/javascripts/admin/addon/templates/admin-email-templates.gjs
+++ /dev/null
@@ -1,3 +0,0 @@
-import RouteTemplate from "ember-route-template";
-
-export default RouteTemplate(<template>{{outlet}}</template>);
diff --git a/app/assets/javascripts/admin/addon/templates/admin-email-templates/edit.gjs b/app/assets/javascripts/admin/addon/templates/admin-email-templates/edit.gjs
index df7c91a0b7d..2926d790e62 100644
--- a/app/assets/javascripts/admin/addon/templates/admin-email-templates/edit.gjs
+++ b/app/assets/javascripts/admin/addon/templates/admin-email-templates/edit.gjs
@@ -5,19 +5,18 @@ import RouteTemplate from "ember-route-template";
import DButton from "discourse/components/d-button";
import DEditor from "discourse/components/d-editor";
import SaveControls from "discourse/components/save-controls";
+import icon from "discourse/helpers/d-icon";
import { i18n } from "discourse-i18n";
-import ComboBox from "select-kit/components/combo-box";
export default RouteTemplate(
<template>
- <ComboBox
- @value={{@controller.emailTemplate.id}}
- @content={{@controller.adminEmailTemplates.sortedTemplates}}
- @onChange={{@controller.adminEmailTemplates.onSelectTemplate}}
- @nameProperty="title"
- />
-
<div class="email-template">
+ <div class="back-to-email-templates">
+ <LinkTo @route="adminEmailTemplates">
+ {{icon "angle-left"}}
+ {{i18n "admin.customize.email_templates.back"}}
+ </LinkTo>
+ </div>
<label>{{i18n "admin.customize.email_templates.subject"}}</label>
{{#if @controller.hasMultipleSubjects}}
<h3><LinkTo
diff --git a/app/assets/javascripts/admin/addon/templates/admin-email-templates/index.gjs b/app/assets/javascripts/admin/addon/templates/admin-email-templates/index.gjs
new file mode 100644
index 00000000000..9164d5b2ac4
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/templates/admin-email-templates/index.gjs
@@ -0,0 +1,80 @@
+import { array } from "@ember/helper";
+import { on } from "@ember/modifier";
+import { LinkTo } from "@ember/routing";
+import RouteTemplate from "ember-route-template";
+import DButton from "discourse/components/d-button";
+import concatClass from "discourse/helpers/concat-class";
+import { i18n } from "discourse-i18n";
+import AdminFilterControls from "admin/components/admin-filter-controls";
+
+export default RouteTemplate(
+ <template>
+ <AdminFilterControls
+ @array={{@controller.shownTemplates}}
+ @searchableProps={{array "title" "id"}}
+ @showDropdownFilter={{false}}
+ @inputPlaceholder={{i18n
+ "admin.customize.email_templates.search_templates"
+ }}
+ @noResultsMessage={{i18n
+ "admin.customize.email_templates.no_templates_found"
+ }}
+ >
+ <:aboveContent>
+ <label class="checkbox-label">
+ <input
+ type="checkbox"
+ checked={{@controller.showOverridenOnly}}
+ id="toggle-overridden"
+ {{on "click" @controller.toggleOverridenOnly}}
+ />
+ {{i18n "admin.site_text.show_overriden"}}
+ </label>
+ </:aboveContent>
+ <:content as |filteredTemplates|>
+ <table class="d-table email-templates-list">
+ <thead class="d-table__header">
+ <tr class="d-table__row">
+ <th class="d-table__header-cell">{{i18n
+ "admin.customize.email_templates.title"
+ }}</th>
+ <th class="d-table__header-cell"></th>
+ </tr>
+ </thead>
+ <tbody class="d-table__body">
+ {{#each filteredTemplates as |template|}}
+ <tr
+ class={{concatClass
+ "d-table__row"
+ "email-templates-list__row"
+ (if template.can_revert "overridden")
+ }}
+ data-template-id={{template.id}}
+ >
+ <td class="d-table__cell --overview">
+ <LinkTo
+ @route="adminEmailTemplates.edit"
+ @model={{template.id}}
+ class="d-table__overview-name admin-email-templates__name"
+ >
+ {{template.title}}
+ </LinkTo>
+ </td>
+ <td class="d-table__cell --controls">
+ <div class="d-table__cell-actions">
+ <DButton
+ class="btn-default admin-email-templates__edit-button"
+ @label="admin.customize.email_templates.edit"
+ @route="adminEmailTemplates.edit"
+ @routeModels={{array template.id}}
+ />
+ </div>
+ </td>
+ </tr>
+ {{/each}}
+ </tbody>
+ </table>
+ </:content>
+ </AdminFilterControls>
+ </template>
+);
diff --git a/app/assets/stylesheets/admin/customize.scss b/app/assets/stylesheets/admin/customize.scss
index eb58c6f9e47..b5039f380b8 100644
--- a/app/assets/stylesheets/admin/customize.scss
+++ b/app/assets/stylesheets/admin/customize.scss
@@ -844,6 +844,18 @@
.d-editor {
height: 50vh;
}
+
+ .back-to-email-templates {
+ margin-bottom: var(--space-2);
+ }
+
+ .email-templates-list {
+ &__row {
+ &.overridden {
+ border-left: 3px solid var(--highlight-medium);
+ }
+ }
+ }
}
.admin-customize-email-style {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index f83d1202b40..c211a0593ee 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -6916,6 +6916,10 @@ en:
body: "Body"
revert: "Revert Changes"
revert_confirm: "Are you sure you want to revert your changes?"
+ search_templates: "Filter by template name..."
+ no_templates_found: "No templates match your filters."
+ edit: "Edit"
+ back: "Back to templates"
component:
all_filter: "All"
used_filter: "Used"
diff --git a/spec/system/admin_email_templates_index_spec.rb b/spec/system/admin_email_templates_index_spec.rb
new file mode 100644
index 00000000000..c10763f0ccc
--- /dev/null
+++ b/spec/system/admin_email_templates_index_spec.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+describe "Admin Email Templates Page", type: :system do
+ fab!(:admin)
+
+ let(:email_templates_page) { PageObjects::Pages::AdminEmailTemplatesIndex.new }
+
+ before { sign_in(admin) }
+
+ it "navigates to the email template edit page when clicking the Edit button" do
+ email_templates_page.visit
+
+ email_templates_page.template("user_notifications.account_exists").edit_button.click
+
+ expect(page).to have_current_path("/admin/email/templates/user_notifications.account_exists")
+ end
+
+ it "navigates to the email template edit page when clicking the template name" do
+ email_templates_page.visit
+
+ email_templates_page.template("user_notifications.account_exists").name_cell.click
+
+ expect(page).to have_current_path("/admin/email/templates/user_notifications.account_exists")
+ end
+
+ describe "filter controls" do
+ it "can find templates by name" do
+ email_templates_page.visit
+
+ email_templates_page.filter_controls.type_in_search("Account already")
+
+ expect(email_templates_page).to have_exact_count_templates_shown(1)
+ expect(
+ email_templates_page.template("user_notifications.account_exists").name_cell.text.strip,
+ ).to eq("Account already exists")
+ end
+
+ it "can find templates by id" do
+ email_templates_page.visit
+
+ email_templates_page.filter_controls.type_in_search("user_notifications.account_exists")
+
+ expect(email_templates_page).to have_exact_count_templates_shown(1)
+ expect(
+ email_templates_page.template("user_notifications.account_exists").name_cell.text.strip,
+ ).to eq("Account already exists")
+ end
+
+ it "can filter templates to only show overridden ones" do
+ TranslationOverride.upsert!(
+ I18n.locale,
+ "user_notifications.user_replied_pm.text_body_template",
+ "some new body",
+ )
+ email_templates_page.visit
+
+ expect(email_templates_page.only_overridden_checkbox.checked?).to be_falsey
+
+ email_templates_page.only_overridden_checkbox.click
+
+ expect(email_templates_page).to have_exact_count_templates_shown(1)
+ expect(email_templates_page.template("user_notifications.user_replied_pm")).to be_overridden
+ end
+ end
+end
diff --git a/spec/system/page_objects/pages/admin_email_templates_index.rb b/spec/system/page_objects/pages/admin_email_templates_index.rb
new file mode 100644
index 00000000000..ba4bc1fbbca
--- /dev/null
+++ b/spec/system/page_objects/pages/admin_email_templates_index.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class AdminEmailTemplatesIndex < PageObjects::Pages::Base
+ class TemplateRow < PageObjects::Components::Base
+ def initialize(selector)
+ @selector = selector
+ @element = find(selector)
+ end
+
+ def edit_button
+ @element.find(".admin-email-templates__edit-button")
+ end
+
+ def name_cell
+ @element.find(".admin-email-templates__name")
+ end
+
+ def overridden?
+ @element[:class].include?("overridden")
+ end
+ end
+
+ def visit
+ page.visit("/admin/email/templates")
+ end
+
+ def template(id)
+ TemplateRow.new("tr[data-template-id=\"#{id}\"]")
+ end
+
+ def filter_controls
+ PageObjects::Components::AdminFilterControls.new(".admin-filter-controls")
+ end
+
+ def only_overridden_checkbox
+ find("#toggle-overridden")
+ end
+
+ def has_exact_count_templates_shown?(count)
+ has_css?("tr[data-template-id]", count:)
+ end
+ end
+ end
+end