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

@ -398,7 +398,7 @@ QUnit.test("computed labels", assert => {
username: "joffrey",
user_id: 1,
user_avatar: "/",
flag_count: 1876,
flag_count: "1876",
time_read: 287362,
note: "This is a long note",
topic_id: 2,
@ -470,7 +470,7 @@ QUnit.test("computed labels", assert => {
assert.equal(flagCountLabel.type, "number");
let computedFlagCountLabel = flagCountLabel.compute(row);
assert.equal(computedFlagCountLabel.formatedValue, "1.9k");
assert.equal(computedFlagCountLabel.value, 1876);
assert.strictEqual(computedFlagCountLabel.value, 1876);
computedFlagCountLabel = flagCountLabel.compute(row, {
formatNumbers: false
});