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

Commit 4325813

Browse files
committed
FIX: Filtering and client-side
1 parent feaa02f commit 4325813

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ export default class AdminReportSentimentAnalysis extends Component {
1616
return ["#2ecc71", "#95a5a6", "#e74c3c"];
1717
}
1818

19+
calculateNeutralScore(data) {
20+
return data.total_count - (data.positive_count + data.negative_count);
21+
}
22+
1923
get transformedData() {
24+
console.log(this.args.model);
2025
return this.args.model.data.map((data) => {
26+
console.log("called", data);
2127
return {
22-
category_name: data.category_name,
28+
title: data.category_name || data.tag_name,
2329
scores: [
24-
data.overall_scores.positive,
25-
data.overall_scores.neutral,
26-
data.overall_scores.negative,
30+
data.positive_count,
31+
this.calculateNeutralScore(data),
32+
data.negative_count,
2733
],
2834
posts: data.posts,
2935
};
@@ -32,7 +38,6 @@ export default class AdminReportSentimentAnalysis extends Component {
3238

3339
@action
3440
showDetails(data) {
35-
console.log(data);
3641
this.selectedChart = data;
3742
}
3843

@@ -69,9 +74,9 @@ export default class AdminReportSentimentAnalysis extends Component {
6974

7075
doughnutTitle(data) {
7176
if (data.posts?.length > 0) {
72-
return `${data.category_name} (${data.posts.length})`;
77+
return `${data.title} (${data.posts.length})`;
7378
} else {
74-
return data.category_name;
79+
return data.title;
7580
}
7681
}
7782

@@ -103,7 +108,7 @@ export default class AdminReportSentimentAnalysis extends Component {
103108
{{#if this.selectedChart}}
104109
<div class="admin-report-sentiment-analysis-details">
105110
<h3 class="admin-report-sentiment-analysis-details__title">
106-
{{this.selectedChart.category_name}}
111+
{{this.selectedChart.title}}
107112
</h3>
108113

109114
<ul class="admin-report-sentiment-analysis-details__scores">

lib/sentiment/sentiment_analysis_report.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ class SentimentAnalysisReport
88
def self.register!(plugin)
99
plugin.add_report("sentiment_analysis") do |report|
1010
report.modes = [:sentiment_analysis]
11-
sentiment_data = DiscourseAi::Sentiment::SentimentAnalysisReport.fetch_data(report)
12-
13-
report.data = sentiment_data
14-
15-
# TODO: connect filter to make the report data change.
16-
filter_type = report.filters.dig(:filter_type) || "Category"
11+
category_filter = report.filters.dig(:filter_by)
1712
report.add_filter(
1813
"filter_by",
1914
type: "list",
20-
default: filter_type,
15+
default: category_filter,
2116
choices: [{ id: "category", name: "Category" }, { id: "tag", name: "Tag" }],
2217
allow_any: false,
2318
auto_insert_none_item: false,
2419
)
2520

21+
sentiment_data = DiscourseAi::Sentiment::SentimentAnalysisReport.fetch_data(report)
22+
23+
report.data = sentiment_data
24+
25+
# TODO: connect filter to make the report data change.
26+
2627
report.labels = [
2728
I18n.t("discourse_ai.sentiment.reports.sentiment_analysis.positive"),
2829
I18n.t("discourse_ai.sentiment.reports.sentiment_analysis.neutral"),
@@ -95,6 +96,8 @@ def self.fetch_data(report)
9596
report_end: report.end_date,
9697
threshold: threshold,
9798
)
99+
100+
grouped_sentiments
98101
end
99102
end
100103
end

0 commit comments

Comments
 (0)