Skip to content

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

DEV: Convert explain-reviewable modal to component-based API (#23274)

Isaac Janzen058c8496f0d4
diff --git a/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.hbs b/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.hbs
new file mode 100644
index 00000000000..eb6a180232b
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.hbs
@@ -0,0 +1,72 @@
+<DModal
+ class="explain-reviewable"
+ @closeModal={{@closeModal}}
+ @title={{i18n "review.explain.title"}}
+>
+ <:body>
+ <ConditionalLoadingSpinner @condition={{this.loading}}>
+ <table>
+ <tbody>
+ <tr>
+ <th>{{i18n "review.explain.formula"}}</th>
+ <th>{{i18n "review.explain.subtotal"}}</th>
+ </tr>
+ {{#each this.reviewableExplanation.scores as |s|}}
+ <tr>
+ <td>
+ <ScoreValue @value="1.0" @tagName="" />
+ <ScoreValue
+ @value={{s.type_bonus}}
+ @label="type_bonus"
+ @tagName=""
+ />
+ <ScoreValue
+ @value={{s.take_action_bonus}}
+ @label="take_action_bonus"
+ @tagName=""
+ />
+ <ScoreValue
+ @value={{s.trust_level_bonus}}
+ @label="trust_level_bonus"
+ @tagName=""
+ />
+ <ScoreValue
+ @value={{s.user_accuracy_bonus}}
+ @label="user_accuracy_bonus"
+ @tagName=""
+ />
+ </td>
+ <td class="sum">{{float s.score}}</td>
+ </tr>
+ {{/each}}
+ <tr class="total">
+ <td>{{i18n "review.explain.total"}}</td>
+ <td class="sum">
+ {{float this.reviewableExplanation.total_score}}
+ </td>
+ </tr>
+ </tbody>
+ </table>
+
+ <table class="thresholds">
+ <tbody>
+ <tr>
+ <td>{{i18n "review.explain.min_score_visibility"}}</td>
+ <td class="sum">
+ {{float this.reviewableExplanation.min_score_visibility}}
+ </td>
+ </tr>
+ <tr>
+ <td>{{i18n "review.explain.score_to_hide"}}</td>
+ <td class="sum">
+ {{float this.reviewableExplanation.hide_post_score}}
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </ConditionalLoadingSpinner>
+ </:body>
+ <:footer>
+ <DButton @action={{@closeModal}} @label="close" />
+ </:footer>
+</DModal>
\ No newline at end of file
diff --git a/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.js b/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.js
new file mode 100644
index 00000000000..a8571b4e3c1
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.js
@@ -0,0 +1,29 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import { inject as service } from "@ember/service";
+
+export default class ExplainReviewable extends Component {
+ @service store;
+
+ @tracked loading = true;
+ @tracked reviewableExplanation = null;
+
+ constructor() {
+ super(...arguments);
+ this.loadExplanation();
+ }
+
+ @action
+ async loadExplanation() {
+ try {
+ const result = await this.store.find(
+ "reviewable-explanation",
+ this.args.model.reviewable.id
+ );
+ this.reviewableExplanation = result;
+ } finally {
+ this.loading = false;
+ }
+ }
+}
diff --git a/app/assets/javascripts/discourse/app/components/reviewable-item.js b/app/assets/javascripts/discourse/app/components/reviewable-item.js
index 4a3ab6b9d7f..1e373f2ea87 100644
--- a/app/assets/javascripts/discourse/app/components/reviewable-item.js
+++ b/app/assets/javascripts/discourse/app/components/reviewable-item.js
@@ -10,6 +10,7 @@ import { action, set } from "@ember/object";
import showModal from "discourse/lib/show-modal";
import { inject as service } from "@ember/service";
import { getOwner } from "discourse-common/lib/get-owner";
+import ExplainReviewableModal from "discourse/components/modal/explain-reviewable";
let _components = {};
@@ -24,6 +25,9 @@ export function addPluginReviewableParam(reviewableType, param) {
export default Component.extend({
adminTools: optionalService(),
dialog: service(),
+ modal: service(),
+ siteSettings: service(),
+ currentUser: service(),
tagName: "",
updating: null,
editing: false,
@@ -214,10 +218,9 @@ export default Component.extend({
@action
explainReviewable(reviewable, event) {
- event?.preventDefault();
- showModal("explain-reviewable", {
- title: "review.explain.title",
- model: reviewable,
+ event.preventDefault();
+ this.modal.show(ExplainReviewableModal, {
+ model: { reviewable },
});
},
diff --git a/app/assets/javascripts/discourse/app/controllers/explain-reviewable.js b/app/assets/javascripts/discourse/app/controllers/explain-reviewable.js
deleted file mode 100644
index 0827d1b45b0..00000000000
--- a/app/assets/javascripts/discourse/app/controllers/explain-reviewable.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import Controller from "@ember/controller";
-import ModalFunctionality from "discourse/mixins/modal-functionality";
-
-export default Controller.extend(ModalFunctionality, {
- loading: null,
- reviewableExplanation: null,
-
- onShow() {
- this.setProperties({ loading: true, reviewableExplanation: null });
-
- this.store
- .find("reviewable-explanation", this.model.id)
- .then((result) => this.set("reviewableExplanation", result))
- .finally(() => this.set("loading", false));
- },
-});
diff --git a/app/assets/javascripts/discourse/app/services/modal.js b/app/assets/javascripts/discourse/app/services/modal.js
index 6be85240692..9e0faf9824b 100644
--- a/app/assets/javascripts/discourse/app/services/modal.js
+++ b/app/assets/javascripts/discourse/app/services/modal.js
@@ -18,7 +18,6 @@ const KNOWN_LEGACY_MODALS = [
"create-account",
"create-invite-bulk",
"create-invite",
- "explain-reviewable",
"feature-topic-on-profile",
"feature-topic",
"flag",
diff --git a/app/assets/javascripts/discourse/app/templates/modal/explain-reviewable.hbs b/app/assets/javascripts/discourse/app/templates/modal/explain-reviewable.hbs
deleted file mode 100644
index e751837bb00..00000000000
--- a/app/assets/javascripts/discourse/app/templates/modal/explain-reviewable.hbs
+++ /dev/null
@@ -1,67 +0,0 @@
-<DModalBody @class="explain-reviewable">
- <ConditionalLoadingSpinner @condition={{this.loading}}>
- <table>
- <tbody>
- <tr>
- <th>{{i18n "review.explain.formula"}}</th>
- <th>{{i18n "review.explain.subtotal"}}</th>
- </tr>
- {{#each this.reviewableExplanation.scores as |s|}}
- <tr>
- <td>
- <ScoreValue @value="1.0" @tagName="" />
- <ScoreValue
- @value={{s.type_bonus}}
- @label="type_bonus"
- @tagName=""
- />
- <ScoreValue
- @value={{s.take_action_bonus}}
- @label="take_action_bonus"
- @tagName=""
- />
- <ScoreValue
- @value={{s.trust_level_bonus}}
- @label="trust_level_bonus"
- @tagName=""
- />
- <ScoreValue
- @value={{s.user_accuracy_bonus}}
- @label="user_accuracy_bonus"
- @tagName=""
- />
- </td>
- <td class="sum">{{float s.score}}</td>
- </tr>
- {{/each}}
- <tr class="total">
- <td>{{i18n "review.explain.total"}}</td>
- <td class="sum">{{float this.reviewableExplanation.total_score}}</td>
- </tr>
- </tbody>
- </table>
-
- <table class="thresholds">
- <tbody>
- <tr>
- <td>{{i18n "review.explain.min_score_visibility"}}</td>
- <td class="sum">
- {{float this.reviewableExplanation.min_score_visibility}}
- </td>
- </tr>
- <tr>
- <td>{{i18n "review.explain.score_to_hide"}}</td>
- <td class="sum">
- {{float this.reviewableExplanation.hide_post_score}}
- </td>
- </tr>
- </tbody>
- </table>
-
- </ConditionalLoadingSpinner>
-
-</DModalBody>
-
-<div class="modal-footer">
- <DButton @action={{route-action "closeModal"}} @label="close" />
-</div>
\ No newline at end of file