A platform for community discussion. Free, open, simple.
DEV: Prettify negative numbers in reviewable score explanation (#23642)
Ted Johanssonc42257b47d51
diff --git a/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.hbs b/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.hbsindex eb6a180232b..d4d751e5d3c 100644--- a/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.hbs+++ b/app/assets/javascripts/discourse/app/components/modal/explain-reviewable.hbs@@ -14,26 +14,19 @@{{#each this.reviewableExplanation.scores as |s|}}<tr><td>- <ScoreValue @value="1.0" @tagName="" />- <ScoreValue- @value={{s.type_bonus}}- @label="type_bonus"- @tagName=""- />+ <ScoreValue @value="1.0" />+ <ScoreValue @value={{s.type_bonus}} @label="type_bonus" /><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>diff --git a/app/assets/javascripts/discourse/app/components/score-value.gjs b/app/assets/javascripts/discourse/app/components/score-value.gjsnew file mode 100644index 00000000000..3b679b187dc--- /dev/null+++ b/app/assets/javascripts/discourse/app/components/score-value.gjs@@ -0,0 +1,34 @@+import Component from "@glimmer/component";+import I18n from "I18n";++export default class ScoreValue extends Component {+ <template>+ {{#if @value}}+ <span class="op">{{if this.isNegative "-" "+"}}</span>+ <span class="score-value">+ <span class="score-number">{{this.numericValue}}</span>+ {{#if @label}}+ <span title={{this.explanationTitle}} class="score-value-type">+ {{this.explanationContent}}+ </span>+ {{/if}}+ </span>+ {{/if}}+ </template>++ get numericValue() {+ return parseFloat(Math.abs(this.args.value)).toFixed(1);+ }++ get isNegative() {+ return this.args.value < 0;+ }++ get explanationTitle() {+ return I18n.t(`review.explain.${this.args.label}.title`);+ }++ get explanationContent() {+ return I18n.t(`review.explain.${this.args.label}.name`);+ }+}diff --git a/app/assets/javascripts/discourse/app/components/score-value.hbs b/app/assets/javascripts/discourse/app/components/score-value.hbsdeleted file mode 100644index d8562118c72..00000000000--- a/app/assets/javascripts/discourse/app/components/score-value.hbs+++ /dev/null@@ -1,14 +0,0 @@-{{#if this.value}}- <span class="score-value">- <span class="score-number">{{float this.value}}</span>- {{#if this.label}}- <span- title={{i18n (concat "review.explain." this.label ".title")}}- class="score-value-type"- >- {{i18n (concat "review.explain." this.label ".name")}}- </span>- {{/if}}- </span>- <span class="op">+</span>-{{/if}}\ No newline at end of filediff --git a/app/assets/javascripts/discourse/app/components/score-value.js b/app/assets/javascripts/discourse/app/components/score-value.jsdeleted file mode 100644index 87d5ddb040f..00000000000--- a/app/assets/javascripts/discourse/app/components/score-value.js+++ /dev/null@@ -1,3 +0,0 @@-import Component from "@ember/component";--export default Component.extend({});diff --git a/app/assets/stylesheets/common/base/explain-reviewable.scss b/app/assets/stylesheets/common/base/explain-reviewable.scssindex 9f82f808d2a..0a4bd1421a4 100644--- a/app/assets/stylesheets/common/base/explain-reviewable.scss+++ b/app/assets/stylesheets/common/base/explain-reviewable.scss@@ -31,7 +31,7 @@color: var(--primary-medium);}- .op:last-of-type {+ .op:first-of-type {display: none;}}