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

Commit 1cd251a

Browse files
committed
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.
1 parent a9afa04 commit 1cd251a

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,44 @@
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 href="{{this.filterURL}}activity-after%3A{{this.today}}%20order%3A{{this.model.type}}">
10+
{{number this.model.todayCount}}
11+
</a>
12+
</div>
913

1014
<div
1115
class="cell value yesterday-count {{this.model.yesterdayTrend}}"
1216
title={{this.model.yesterdayCountTitle}}
1317
>
14-
{{number this.model.yesterdayCount}}
18+
<a href="{{this.filterURL}}activity-after%3A{{this.yesterday}}%20order%3A{{this.model.type}}">
19+
{{number this.model.yesterdayCount}}
20+
</a>
1521
{{d-icon this.model.yesterdayTrendIcon}}
1622
</div>
1723

1824
<div
1925
class="cell value sevendays-count {{this.model.sevenDaysTrend}}"
2026
title={{this.model.sevenDaysCountTitle}}
2127
>
22-
{{number this.model.lastSevenDaysCount}}
28+
<a href="{{this.filterURL}}activity-after%3A{{this.lastWeek}}%20order%3A{{this.model.type}}">
29+
{{number this.model.lastSevenDaysCount}}
30+
</a>
2331
{{d-icon this.model.sevenDaysTrendIcon}}
2432
</div>
2533

2634
<div
2735
class="cell value thirty-days-count {{this.model.thirtyDaysTrend}}"
2836
title={{this.model.thirtyDaysCountTitle}}
2937
>
30-
{{number this.model.lastThirtyDaysCount}}
38+
<a href="{{this.filterURL}}activity-after%3A{{this.lastMonth}}%20order%3A{{this.model.type}}">
39+
{{number this.model.lastThirtyDaysCount}}
40+
</a>
3141

3242
{{#if this.model.canDisplayTrendIcon}}
3343
{{d-icon this.model.thirtyDaysTrendIcon}}
3444
{{/if}}
35-
</div>
45+
</div>

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)