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

Commit 8b0cdcb

Browse files
committed
DEV: Improvements
1 parent 57b1c01 commit 8b0cdcb

File tree

6 files changed

+80
-15
lines changed

6 files changed

+80
-15
lines changed

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

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ import dIcon from "discourse/helpers/d-icon";
1414
import replaceEmoji from "discourse/helpers/replace-emoji";
1515
import { ajax } from "discourse/lib/ajax";
1616
import { popupAjaxError } from "discourse/lib/ajax-error";
17+
import { getAbsoluteURL } from "discourse/lib/get-url";
18+
import discourseLater from "discourse/lib/later";
19+
import { clipboardCopy } from "discourse/lib/utilities";
1720
import Post from "discourse/models/post";
1821
import closeOnClickOutside from "discourse/modifiers/close-on-click-outside";
1922
import { i18n } from "discourse-i18n";
2023
import DoughnutChart from "discourse/plugins/discourse-ai/discourse/components/doughnut-chart";
24+
import DTooltip from "float-kit/components/d-tooltip";
2125

2226
export default class AdminReportSentimentAnalysis extends Component {
2327
@service router;
@@ -28,6 +32,7 @@ export default class AdminReportSentimentAnalysis extends Component {
2832
@tracked nextOffset = 0;
2933
@tracked showingSelectedChart = false;
3034
@tracked activeFilter = "all";
35+
@tracked shareIcon = "link";
3136

3237
setActiveFilter = modifier((element) => {
3338
this.clearActiveFilters(element);
@@ -266,6 +271,21 @@ export default class AdminReportSentimentAnalysis extends Component {
266271
});
267272
}
268273

274+
@action
275+
shareChart() {
276+
const url = this.router.currentURL;
277+
if (!url) {
278+
return;
279+
}
280+
281+
clipboardCopy(getAbsoluteURL(url));
282+
this.shareIcon = "check";
283+
284+
discourseLater(() => {
285+
this.shareIcon = "link";
286+
}, 2000);
287+
}
288+
269289
<template>
270290
<span {{didInsert this.openToChart}}></span>
271291

@@ -298,20 +318,39 @@ export default class AdminReportSentimentAnalysis extends Component {
298318

299319
{{#if (and this.selectedChart this.showingSelectedChart)}}
300320
<div class="admin-report-sentiment-analysis__selected-chart">
301-
<DButton
302-
@label="back_button"
303-
@icon="chevron-left"
304-
class="btn-flat"
305-
@action={{this.backToAllCharts}}
306-
/>
321+
<div class="admin-report-sentiment-analysis__selected-chart-actions">
322+
<DButton
323+
@label="back_button"
324+
@icon="chevron-left"
325+
class="btn-flat"
326+
@action={{this.backToAllCharts}}
327+
/>
328+
329+
{{!-- <DButton
330+
@title="discourse_ai.sentiments.sentiment_analysis.share_chart"
331+
@icon={{this.shareIcon}}
332+
@action={{this.shareChart}}
333+
class="share btn-flat"
334+
/> --}}
335+
<DTooltip
336+
class="share btn-flat"
337+
@icon={{this.shareIcon}}
338+
{{on "click" this.shareChart}}
339+
@content={{i18n
340+
"discourse_ai.sentiments.sentiment_analysis.share_chart"
341+
}}
342+
/>
343+
</div>
307344

308345
<DoughnutChart
309346
@labels={{@model.labels}}
310347
@colors={{this.colors}}
311348
@data={{this.selectedChart.scores}}
312349
@totalScore={{this.selectedChart.total_score}}
313350
@doughnutTitle={{this.selectedChart.title}}
351+
@radius={{100}}
314352
/>
353+
315354
</div>
316355
<div class="admin-report-sentiment-analysis-details">
317356
<HorizontalOverflowNav

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Component from "@glimmer/component";
22
import { tracked } from "@glimmer/tracking";
3+
import { concat } from "@ember/helper";
4+
import { htmlSafe } from "@ember/template";
5+
import { isDevelopment } from "discourse/lib/environment";
36
import Chart from "admin/components/chart";
47

58
export default class DoughnutChart extends Component {
@@ -18,11 +21,19 @@ export default class DoughnutChart extends Component {
1821
);
1922
}
2023

24+
getRadius() {
25+
if (this.args.radius) {
26+
return this.args.radius;
27+
} else if (isDevelopment()) {
28+
return this.calculateRadius(Math.floor(Math.random() * (100 + 1)));
29+
} else {
30+
return this.calculateRadius(this.args.totalScore);
31+
}
32+
}
33+
2134
get config() {
2235
const totalScore = this.args.totalScore || "";
23-
// const radius = this.calculateRadius(this.args.totalScore)
24-
// Temporary for tesitng:
25-
const radius = this.calculateRadius(Math.floor(Math.random() * (100 + 1)));
36+
const radius = this.getRadius();
2637

2738
const paddingTop = 30;
2839
const paddingBottom = 0;
@@ -108,7 +119,7 @@ export default class DoughnutChart extends Component {
108119
{{#if this.config}}
109120
<h3
110121
class="doughnut-chart-title"
111-
style="max-width: {{this.canvasSize}}px"
122+
style={{htmlSafe (concat "max-width: " this.canvasSize "px")}}
112123
>{{@doughnutTitle}}</h3>
113124
<Chart @chartConfig={{this.config}} class="admin-report-doughnut" />
114125
{{/if}}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,23 @@
100100
font-size: var(--font-up-2);
101101
margin: 0 auto;
102102
text-align: center;
103-
margin-bottom: 1rem;
104103
margin-top: 0.3rem;
105104
padding-top: 2rem;
106-
padding-bottom: 1rem;
107105
border-top: 1px solid var(--primary-low);
108106
}
109107
}
108+
109+
&__selected-chart-actions {
110+
display: flex;
111+
align-items: center;
112+
.share {
113+
margin-left: auto;
114+
115+
.d-icon-check {
116+
color: var(--success);
117+
}
118+
}
119+
}
110120
}
111121

112122
:root {

config/locales/client.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ en:
656656
overview: "Sentiment overview"
657657
analysis: "Sentiment analysis"
658658
sentiment_analysis:
659+
share_chart: "Copy link to chart"
659660
filter_types:
660661
all: "All"
661662
positive: "Positive"

lib/sentiment/entry_point.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ def inject_into(plugin)
2222
end,
2323
) { ClassificationResult.has_sentiment_classification? }
2424

25-
if ClassificationResult.has_sentiment_classification? && SiteSetting.ai_sentiment_enabled &&
26-
SiteSetting.ai_sentiment_reports_enabled
25+
if Rails.env.test? ||
26+
ClassificationResult.has_sentiment_classification? &&
27+
SiteSetting.ai_sentiment_enabled && SiteSetting.ai_sentiment_reports_enabled
2728
EmotionFilterOrder.register!(plugin)
2829
EmotionDashboardReport.register!(plugin)
2930
SentimentDashboardReport.register!(plugin)

spec/reports/sentiment_analysis_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
fab!(:post_2) { Fabricate(:post, user: admin, topic: topic) }
99
fab!(:classification_result) { Fabricate(:classification_result, target: post) }
1010

11-
before { SiteSetting.ai_sentiment_enabled = true }
11+
before do
12+
SiteSetting.ai_sentiment_reports_enabled = true
13+
SiteSetting.ai_sentiment_enabled = true
14+
end
1215

1316
it "contains the correct filters" do
1417
report = Report.find("sentiment_analysis")

0 commit comments

Comments
 (0)