From 37942cb8bb74e561613b38dfef042b3a5b2da9f7 Mon Sep 17 00:00:00 2001
From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com>
Date: Thu, 20 Jul 2023 16:31:20 -0500
Subject: [PATCH] DEV: Convert `admin-incoming-email` modal to component-based
API (#22701)
- Convert `admin-incoming-email` modal to component-based API
- Testing that the modal was working in local development was extremely challenging due to the need for `rejected` and `bounced` emails. Something that is not easy to stub in a local dev environment. To make this process more smooth for future developers I have added a new rake task:
```
desc "Creates sample email logs"
task "email_logs:populate" => ["db:load_config"] do |_, args|
DiscourseDev::EmailLog.populate!
end
```
That will generate fully functional email logs in development to be toyed with.
---
.../addon/components/modal/incoming-email.hbs | 54 +++++++++++++
.../modals/admin-incoming-email.js | 28 -------
.../admin/addon/routes/admin-email-bounced.js | 21 ++++-
.../addon/routes/admin-email-rejected.js | 11 ++-
.../templates/modal/admin-incoming-email.hbs | 50 ------------
.../discourse/app/services/modal.js | 1 -
config/dev_defaults.yml | 2 +
lib/discourse_dev/email_log.rb | 77 +++++++++++++++++++
lib/tasks/populate.rake | 5 ++
9 files changed, 162 insertions(+), 87 deletions(-)
create mode 100644 app/assets/javascripts/admin/addon/components/modal/incoming-email.hbs
delete mode 100644 app/assets/javascripts/admin/addon/controllers/modals/admin-incoming-email.js
delete mode 100644 app/assets/javascripts/admin/addon/templates/modal/admin-incoming-email.hbs
create mode 100644 lib/discourse_dev/email_log.rb
diff --git a/app/assets/javascripts/admin/addon/components/modal/incoming-email.hbs b/app/assets/javascripts/admin/addon/components/modal/incoming-email.hbs
new file mode 100644
index 00000000000..e1beb0f6664
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/components/modal/incoming-email.hbs
@@ -0,0 +1,54 @@
+
+ <:body>
+
+
+
+
{{@model.error}}
+ {{#if @model.error_description}}
+
{{@model.error_description}}
+ {{/if}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{@model.subject}}
+
+
+
+
+
+
+
+
+
+
+ {{#if @model.rejection_message}}
+
+
+
+
+
+
+
+
+ {{/if}}
+
+
\ No newline at end of file
diff --git a/app/assets/javascripts/admin/addon/controllers/modals/admin-incoming-email.js b/app/assets/javascripts/admin/addon/controllers/modals/admin-incoming-email.js
deleted file mode 100644
index 3724332cee7..00000000000
--- a/app/assets/javascripts/admin/addon/controllers/modals/admin-incoming-email.js
+++ /dev/null
@@ -1,28 +0,0 @@
-import Controller from "@ember/controller";
-import IncomingEmail from "admin/models/incoming-email";
-import ModalFunctionality from "discourse/mixins/modal-functionality";
-import discourseComputed from "discourse-common/utils/decorators";
-import { longDate } from "discourse/lib/formatter";
-import { popupAjaxError } from "discourse/lib/ajax-error";
-
-export default class AdminIncomingEmailController extends Controller.extend(
- ModalFunctionality
-) {
- @discourseComputed("model.date")
- date(d) {
- return longDate(d);
- }
-
- load(id) {
- return IncomingEmail.find(id).then((result) => this.set("model", result));
- }
-
- loadFromBounced(id) {
- return IncomingEmail.findByBounced(id)
- .then((result) => this.set("model", result))
- .catch((error) => {
- this.send("closeModal");
- popupAjaxError(error);
- });
- }
-}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-email-bounced.js b/app/assets/javascripts/admin/addon/routes/admin-email-bounced.js
index 74cb0975b9b..5a5d410c176 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-email-bounced.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-email-bounced.js
@@ -1,13 +1,26 @@
import { action } from "@ember/object";
import AdminEmailLogs from "admin/routes/admin-email-logs";
-import showModal from "discourse/lib/show-modal";
+import IncomingEmail from "admin/models/incoming-email";
+import IncomingEmailModal from "../components/modal/incoming-email";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { inject as service } from "@ember/service";
export default class AdminEmailBouncedRoute extends AdminEmailLogs {
+ @service modal;
status = "bounced";
@action
- showIncomingEmail(id) {
- showModal("admin-incoming-email", { admin: true });
- this.controllerFor("modals/admin-incoming-email").loadFromBounced(id);
+ async showIncomingEmail(id) {
+ const model = await this.loadFromBounced(id);
+ this.modal.show(IncomingEmailModal, { model });
+ }
+
+ @action
+ async loadFromBounced(id) {
+ try {
+ return await IncomingEmail.findByBounced(id);
+ } catch (error) {
+ popupAjaxError(error);
+ }
}
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-email-rejected.js b/app/assets/javascripts/admin/addon/routes/admin-email-rejected.js
index d09c81ef4fb..bb8b73f77a5 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-email-rejected.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-email-rejected.js
@@ -1,13 +1,16 @@
import { action } from "@ember/object";
import AdminEmailIncomings from "admin/routes/admin-email-incomings";
-import showModal from "discourse/lib/show-modal";
+import IncomingEmailModal from "../components/modal/incoming-email";
+import IncomingEmail from "admin/models/incoming-email";
+import { inject as service } from "@ember/service";
export default class AdminEmailRejectedRoute extends AdminEmailIncomings {
+ @service modal;
status = "rejected";
@action
- showIncomingEmail(id) {
- showModal("admin-incoming-email", { admin: true });
- this.controllerFor("modals/admin-incoming-email").load(id);
+ async showIncomingEmail(id) {
+ const model = await IncomingEmail.find(id);
+ this.modal.show(IncomingEmailModal, { model });
}
}
diff --git a/app/assets/javascripts/admin/addon/templates/modal/admin-incoming-email.hbs b/app/assets/javascripts/admin/addon/templates/modal/admin-incoming-email.hbs
deleted file mode 100644
index 28a4294b9d2..00000000000
--- a/app/assets/javascripts/admin/addon/templates/modal/admin-incoming-email.hbs
+++ /dev/null
@@ -1,50 +0,0 @@
-
-