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

Commit 9aafca0

Browse files
authored
UX: Improvements to sentiment analysis report (#1150)
This update improves some of the UI around sentiment analysis reports: 1. Improve titles so it is above and truncated when long 2. Change doughnut to only show total count 3. Ensures sentiment posts have dates 4. Ensure expand post doesn't appear on short posts
1 parent 0018475 commit 9aafca0

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

app/controllers/discourse_ai/sentiment/sentiment_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def posts
4141
p.cooked as post_cooked,
4242
p.user_id,
4343
p.post_number,
44+
p.created_at AS created_at,
4445
u.username,
4546
u.name,
4647
u.uploaded_avatar_id,

app/serializers/ai_sentiment_post_serializer.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class AiSentimentPostSerializer < ApplicationSerializer
1111
:excerpt,
1212
:sentiment,
1313
:truncated,
14-
:category
14+
:category,
15+
:created_at
1516

1617
def avatar_template
1718
User.avatar_template(object.username, object.uploaded_avatar_id)
@@ -22,7 +23,7 @@ def excerpt
2223
end
2324

2425
def truncated
25-
true
26+
object.post_cooked.length > SiteSetting.post_excerpt_maxlength
2627
end
2728

2829
def category

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ export default class AdminReportSentimentAnalysis extends Component {
250250
@labels={{@model.labels}}
251251
@colors={{this.colors}}
252252
@data={{data.scores}}
253-
@doughnutTitle={{this.doughnutTitle data}}
253+
@totalScore={{data.total_score}}
254+
@doughnutTitle={{data.title}}
254255
/>
255256
</div>
256257
{{/each}}
@@ -265,15 +266,13 @@ export default class AdminReportSentimentAnalysis extends Component {
265266
class="btn-flat"
266267
@action={{this.backToAllCharts}}
267268
/>
268-
<h3 class="admin-report-sentiment-analysis-details__title">
269-
{{this.selectedChart.title}}
270-
</h3>
271269

272270
<DoughnutChart
273271
@labels={{@model.labels}}
274272
@colors={{this.colors}}
275273
@data={{this.selectedChart.scores}}
276-
@doughnutTitle={{this.doughnutTitle this.selectedChart}}
274+
@totalScore={{this.selectedChart.total_score}}
275+
@doughnutTitle={{this.selectedChart.title}}
277276
/>
278277
</div>
279278
<div class="admin-report-sentiment-analysis-details">

assets/javascripts/discourse/components/doughnut-chart.gjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Chart from "admin/components/chart";
33

44
export default class DoughnutChart extends Component {
55
get config() {
6-
const doughnutTitle = this.args.doughnutTitle || "";
6+
const totalScore = this.args.totalScore || "";
77

88
return {
99
type: "doughnut",
@@ -30,11 +30,11 @@ export default class DoughnutChart extends Component {
3030
afterDraw: function (chart) {
3131
const cssVarColor =
3232
getComputedStyle(document.documentElement).getPropertyValue(
33-
"--primary"
33+
"--primary-high"
3434
) || "#000";
3535
const cssFontSize =
3636
getComputedStyle(document.documentElement).getPropertyValue(
37-
"--font-down-2"
37+
"--font-up-4"
3838
) || "1.3em";
3939
const cssFontFamily =
4040
getComputedStyle(document.documentElement).getPropertyValue(
@@ -49,9 +49,9 @@ export default class DoughnutChart extends Component {
4949
ctx.textAlign = "center";
5050
ctx.textBaseline = "middle";
5151
ctx.fillStyle = cssVarColor.trim();
52-
ctx.font = `${cssFontSize.trim()} ${cssFontFamily.trim()}`;
52+
ctx.font = `bold ${cssFontSize.trim()} ${cssFontFamily.trim()}`;
5353

54-
ctx.fillText(doughnutTitle, centerX, centerY);
54+
ctx.fillText(totalScore, centerX, centerY);
5555
ctx.save();
5656
},
5757
},
@@ -61,6 +61,7 @@ export default class DoughnutChart extends Component {
6161

6262
<template>
6363
{{#if this.config}}
64+
<h3 class="doughnut-chart-title">{{@doughnutTitle}}</h3>
6465
<Chart @chartConfig={{this.config}} class="admin-report-doughnut" />
6566
{{/if}}
6667
</template>

assets/stylesheets/modules/sentiment/common/dashboard.scss

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@
7575
}
7676

7777
&__chart-wrapper {
78+
width: auto;
79+
.doughnut-chart-title {
80+
@include ellipsis;
81+
margin: 0 auto;
82+
text-align: center;
83+
margin-bottom: 1rem;
84+
max-width: 300px;
85+
}
7886
transition: transform 0.25s ease, box-shadow 0.25s ease;
7987
border-radius: var(--d-border-radius);
8088

@@ -89,6 +97,17 @@
8997
border: 1px solid var(--primary-low);
9098
border-radius: var(--d-border-radius);
9199
padding: 1rem;
100+
101+
.doughnut-chart-title {
102+
font-size: var(--font-up-2);
103+
margin: 0 auto;
104+
text-align: center;
105+
margin-bottom: 1rem;
106+
margin-top: 0.3rem;
107+
padding-top: 2rem;
108+
padding-bottom: 1rem;
109+
border-top: 1px solid var(--primary-low);
110+
}
92111
}
93112
}
94113

@@ -119,17 +138,6 @@
119138
}
120139
}
121140

122-
&__title {
123-
font-size: var(--font-up-2);
124-
margin: 0 auto;
125-
text-align: center;
126-
margin-bottom: 1rem;
127-
margin-top: 0.3rem;
128-
padding-top: 2rem;
129-
padding-bottom: 1rem;
130-
border-top: 1px solid var(--primary-low);
131-
}
132-
133141
&__scores {
134142
display: flex;
135143
flex-flow: column wrap;

0 commit comments

Comments
 (0)