From 1f30bacb65eb4102acb4d9f5fb9472a7bc9348c1 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 9 Feb 2022 22:09:33 +0530 Subject: [PATCH] FIX: use `prev_period` data if `prev30Days` value is not available. (#15867) Previously, reports of likes and flags doesn't include the 30 days trend icon and title. --- .../javascripts/admin/addon/models/report.js | 31 +++++++++++++++---- .../components/admin-report-counters.hbs | 2 +- .../tests/unit/models/report-test.js | 11 +++++-- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/admin/addon/models/report.js b/app/assets/javascripts/admin/addon/models/report.js index fb1eef051fa..55c1012eb19 100644 --- a/app/assets/javascripts/admin/addon/models/report.js +++ b/app/assets/javascripts/admin/addon/models/report.js @@ -163,9 +163,23 @@ const Report = EmberObject.extend({ return this._computeTrend(prev, total, higherIsBetter); }, - @discourseComputed("prev30Days", "lastThirtyDaysCount", "higher_is_better") - thirtyDaysTrend(prev30Days, lastThirtyDaysCount, higherIsBetter) { - return this._computeTrend(prev30Days, lastThirtyDaysCount, higherIsBetter); + @discourseComputed( + "prev30Days", + "prev_period", + "lastThirtyDaysCount", + "higher_is_better" + ) + thirtyDaysTrend( + prev30Days, + prev_period, + lastThirtyDaysCount, + higherIsBetter + ) { + return this._computeTrend( + prev30Days ?? prev_period, + lastThirtyDaysCount, + higherIsBetter + ); }, @discourseComputed("type") @@ -236,10 +250,15 @@ const Report = EmberObject.extend({ ); }, - @discourseComputed("prev30Days", "lastThirtyDaysCount") - thirtyDaysCountTitle(prev30Days, lastThirtyDaysCount) { + @discourseComputed("prev30Days", "prev_period") + canDisplayTrendIcon(prev30Days, prev_period) { + return prev30Days ?? prev_period; + }, + + @discourseComputed("prev30Days", "prev_period", "lastThirtyDaysCount") + thirtyDaysCountTitle(prev30Days, prev_period, lastThirtyDaysCount) { return this.changeTitle( - prev30Days, + prev30Days ?? prev_period, lastThirtyDaysCount, "in the previous 30 day period" ); diff --git a/app/assets/javascripts/admin/addon/templates/components/admin-report-counters.hbs b/app/assets/javascripts/admin/addon/templates/components/admin-report-counters.hbs index 05d456fdebb..b411a2571b2 100644 --- a/app/assets/javascripts/admin/addon/templates/components/admin-report-counters.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/admin-report-counters.hbs @@ -18,7 +18,7 @@
{{number model.lastThirtyDaysCount}} - {{#if model.prev30Days}} + {{#if model.canDisplayTrendIcon}} {{d-icon model.thirtyDaysTrendIcon}} {{/if}}
diff --git a/app/assets/javascripts/discourse/tests/unit/models/report-test.js b/app/assets/javascripts/discourse/tests/unit/models/report-test.js index 3cb76c9a0d8..c07323f1421 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/report-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/report-test.js @@ -109,12 +109,19 @@ module("Unit | Model | report", function () { }); test("thirtyDaysCountTitle", function (assert) { - const report = reportWithData([5, 5, 5, 5]); + let report = reportWithData([5, 5, 5, 5]); report.set("prev30Days", 10); - const title = report.get("thirtyDaysCountTitle"); + let title = report.get("thirtyDaysCountTitle"); assert.ok(title.indexOf("+50%") !== -1); assert.ok(title.match(/Was 10/)); + + report = reportWithData([5, 5, 5, 5]); + report.set("prev_period", 20); + title = report.get("thirtyDaysCountTitle"); + + assert.ok(title.indexOf("-25%") !== -1); + assert.ok(title.match(/Was 20/)); }); test("sevenDaysTrend", function (assert) {