FIX: Cast all numerical values in reports (#8087)

* FIX: Cast all numerical values in reports

The backend can return some numerical values in report as strings. That results in unexpected order of values when sorting report tables.

* Create `toNumber()` helper

The `typeof` and `parseFloat` seem to be the fastest path: https://jsperf.com/number-vs-typeof-vs-parsefloat#results
This commit is contained in:
Jarek Radosz
2019-09-12 15:17:34 +02:00
committed by GitHub
parent 73172f00d3
commit 1dcdcb5c31
4 changed files with 18 additions and 10 deletions

View File

@ -1,7 +1,11 @@
import { escapeExpression } from "discourse/lib/utilities";
import { ajax } from "discourse/lib/ajax";
import round from "discourse/lib/round";
import { fillMissingDates, formatUsername } from "discourse/lib/utilities";
import {
fillMissingDates,
formatUsername,
toNumber
} from "discourse/lib/utilities";
import computed from "ember-addons/ember-computed-decorators";
import { number, durationTiny } from "discourse/lib/formatter";
import { renderAvatar } from "discourse/helpers/user-avatar";
@ -374,14 +378,14 @@ const Report = Discourse.Model.extend({
_secondsLabel(value) {
return {
value,
value: toNumber(value),
formatedValue: durationTiny(value)
};
},
_percentLabel(value) {
return {
value,
value: toNumber(value),
formatedValue: value ? `${value}%` : "—"
};
},
@ -394,14 +398,14 @@ const Report = Discourse.Model.extend({
const formatedValue = () => (formatNumbers ? number(value) : value);
return {
value,
value: toNumber(value),
formatedValue: value ? formatedValue() : "—"
};
},
_bytesLabel(value) {
return {
value,
value: toNumber(value),
formatedValue: I18n.toHumanSize(value)
};
},