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

Commit eba49a8

Browse files
committed
getting started on filters
1 parent da7e8a5 commit eba49a8

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import DoughnutChart from "./doughnut-chart";
1212
export default class AdminReportSentimentAnalysis extends Component {
1313
@tracked selectedChart = null;
1414

15-
get labels() {
16-
return ["Positive", "Neutral", "Negative"];
17-
}
18-
1915
get colors() {
2016
return ["#2ecc71", "#95a5a6", "#e74c3c"];
2117
}
@@ -71,6 +67,14 @@ export default class AdminReportSentimentAnalysis extends Component {
7167
}
7268
}
7369

70+
doughnutTitle(data) {
71+
if (data.posts?.length > 0) {
72+
return `${data.category_name} (${data.posts.length})`;
73+
} else {
74+
return data.category_name;
75+
}
76+
}
77+
7478
<template>
7579
{{! TODO add more details about posts on click + tag data }}
7680
<div class="admin-report-sentiment-analysis">
@@ -87,10 +91,10 @@ export default class AdminReportSentimentAnalysis extends Component {
8791
}}
8892
>
8993
<DoughnutChart
90-
@labels={{this.labels}}
94+
@labels={{@model.labels}}
9195
@colors={{this.colors}}
9296
@data={{data.scores}}
93-
@doughnutTitle={{data.category_name}}
97+
@doughnutTitle={{this.doughnutTitle data}}
9498
/>
9599
</div>
96100
{{/each}}

config/locales/client.en.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ en:
1515
emotion:
1616
title: "Emotion"
1717
description: "The table lists a count of posts classified with a determined emotion. Classified with the model 'SamLowe/roberta-base-go_emotions'."
18+
reports:
19+
filters:
20+
filter_by:
21+
label: "Filter by"
22+
1823
js:
1924
discourse_automation:
2025
scriptables:

config/locales/server.en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ en:
413413
anger: "Anger 😡"
414414
joy: "Joy 😀"
415415
disgust: "Disgust 🤢"
416+
sentiment_analysis:
417+
positive: "Positive"
418+
negative: "Negative"
419+
neutral: "Neutral"
416420

417421
llm:
418422
configuration:

lib/sentiment/sentiment_analysis_report.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ def self.register!(plugin)
4646
end,
4747
}
4848
end
49+
50+
# TODO: connect filter to make the report data change.
51+
filter_type = report.filters.dig(:filter_type) || "Category"
52+
report.add_filter(
53+
"filter_by",
54+
type: "list",
55+
default: filter_type,
56+
choices: [{ id: "category", name: "Category" }, { id: "tag", name: "Tag" }],
57+
allow_any: false,
58+
auto_insert_none_item: false,
59+
)
60+
61+
report.labels = [
62+
I18n.t("discourse_ai.sentiment.reports.sentiment_analysis.positive"),
63+
I18n.t("discourse_ai.sentiment.reports.sentiment_analysis.neutral"),
64+
I18n.t("discourse_ai.sentiment.reports.sentiment_analysis.negative"),
65+
]
4966
end
5067
end
5168

0 commit comments

Comments
 (0)