Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 2c8d818

Browse files
authored
FIX: Misc fixes for sentiment in the admin dashboard (#928)
* FIX: Misc fixes for sentiment in the admin dashboard - Fixes missing filters for the main graph - Fixes previous 30 days trend in emotion table Also moves links to individual cells in emotion table, so admins can drill down to the specific time period on their reports. * lints
1 parent a9afa04 commit 2c8d818

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

assets/javascripts/discourse/components/admin-report-emotion.hbs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,50 @@
22
{{#if this.model.icon}}
33
{{d-icon this.model.icon}}
44
{{/if}}
5-
<a href="{{this.filterURL}}{{this.model.type}}">{{this.model.title}}</a>
5+
{{this.model.title}}
66
</div>
77

8-
<div class="cell value today-count">{{number this.model.todayCount}}</div>
8+
<div class="cell value today-count">
9+
<a
10+
href="{{this.filterURL}}activity-after%3A{{this.today}}%20order%3A{{this.model.type}}"
11+
>
12+
{{number this.model.todayCount}}
13+
</a>
14+
</div>
915

1016
<div
1117
class="cell value yesterday-count {{this.model.yesterdayTrend}}"
1218
title={{this.model.yesterdayCountTitle}}
1319
>
14-
{{number this.model.yesterdayCount}}
20+
<a
21+
href="{{this.filterURL}}activity-after%3A{{this.yesterday}}%20order%3A{{this.model.type}}"
22+
>
23+
{{number this.model.yesterdayCount}}
24+
</a>
1525
{{d-icon this.model.yesterdayTrendIcon}}
1626
</div>
1727

1828
<div
1929
class="cell value sevendays-count {{this.model.sevenDaysTrend}}"
2030
title={{this.model.sevenDaysCountTitle}}
2131
>
22-
{{number this.model.lastSevenDaysCount}}
32+
<a
33+
href="{{this.filterURL}}activity-after%3A{{this.lastWeek}}%20order%3A{{this.model.type}}"
34+
>
35+
{{number this.model.lastSevenDaysCount}}
36+
</a>
2337
{{d-icon this.model.sevenDaysTrendIcon}}
2438
</div>
2539

2640
<div
2741
class="cell value thirty-days-count {{this.model.thirtyDaysTrend}}"
2842
title={{this.model.thirtyDaysCountTitle}}
2943
>
30-
{{number this.model.lastThirtyDaysCount}}
44+
<a
45+
href="{{this.filterURL}}activity-after%3A{{this.lastMonth}}%20order%3A{{this.model.type}}"
46+
>
47+
{{number this.model.lastThirtyDaysCount}}
48+
</a>
3149

3250
{{#if this.model.canDisplayTrendIcon}}
3351
{{d-icon this.model.thirtyDaysTrendIcon}}

assets/javascripts/discourse/components/admin-report-emotion.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,22 @@ import getURL from "discourse-common/lib/get-url";
66
@attributeBindings("model.description:title")
77
export default class AdminReportEmotion extends Component {
88
get filterURL() {
9-
let aMonthAgo = moment().subtract(1, "month").format("YYYY-MM-DD");
10-
return getURL(`/filter?q=activity-after%3A${aMonthAgo}%20order%3A`);
9+
return getURL(`/filter?q=`);
10+
}
11+
12+
get today() {
13+
return moment().format("YYYY-MM-DD");
14+
}
15+
16+
get yesterday() {
17+
return moment().subtract(1, "day").format("YYYY-MM-DD");
18+
}
19+
20+
get lastWeek() {
21+
return moment().subtract(1, "week").format("YYYY-MM-DD");
22+
}
23+
24+
get lastMonth() {
25+
return moment().subtract(1, "month").format("YYYY-MM-DD");
1126
}
1227
}

assets/javascripts/discourse/controllers/admin-dashboard-sentiment.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import { computed } from "@ember/object";
12
import AdminDashboardTabController from "admin/controllers/admin-dashboard-tab";
23

34
export default class AdminDashboardSentiment extends AdminDashboardTabController {
5+
@computed("startDate", "endDate")
6+
get filters() {
7+
return { startDate: this.startDate, endDate: this.endDate };
8+
}
9+
410
get emotions() {
511
const emotions = [
612
"admiration",

lib/sentiment/emotion_dashboard_report.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def self.register!(plugin)
99
query_results = DiscourseAi::Sentiment::EmotionDashboardReport.fetch_data
1010
report.data = query_results.pop(30).map { |row| { x: row.day, y: row.send(emotion) } }
1111
report.prev30Days =
12-
query_results.take(30).map { |row| { x: row.day, y: row.send(emotion) } }
12+
query_results.take(30).reduce(0) { |sum, row| sum + row.send(emotion) }.to_i
1313
end
1414
end
1515

0 commit comments

Comments
 (0)