Skip to content

Commit

Permalink
DEV: Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
keegangeorge committed Mar 5, 2025
1 parent 57b1c01 commit 8b0cdcb
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ import dIcon from "discourse/helpers/d-icon";
import replaceEmoji from "discourse/helpers/replace-emoji";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { getAbsoluteURL } from "discourse/lib/get-url";
import discourseLater from "discourse/lib/later";
import { clipboardCopy } from "discourse/lib/utilities";
import Post from "discourse/models/post";
import closeOnClickOutside from "discourse/modifiers/close-on-click-outside";
import { i18n } from "discourse-i18n";
import DoughnutChart from "discourse/plugins/discourse-ai/discourse/components/doughnut-chart";
import DTooltip from "float-kit/components/d-tooltip";

export default class AdminReportSentimentAnalysis extends Component {
@service router;
Expand All @@ -28,6 +32,7 @@ export default class AdminReportSentimentAnalysis extends Component {
@tracked nextOffset = 0;
@tracked showingSelectedChart = false;
@tracked activeFilter = "all";
@tracked shareIcon = "link";

setActiveFilter = modifier((element) => {
this.clearActiveFilters(element);
Expand Down Expand Up @@ -266,6 +271,21 @@ export default class AdminReportSentimentAnalysis extends Component {
});
}

@action
shareChart() {
const url = this.router.currentURL;
if (!url) {
return;
}

clipboardCopy(getAbsoluteURL(url));
this.shareIcon = "check";

discourseLater(() => {
this.shareIcon = "link";
}, 2000);
}

<template>
<span {{didInsert this.openToChart}}></span>

Expand Down Expand Up @@ -298,20 +318,39 @@ export default class AdminReportSentimentAnalysis extends Component {

{{#if (and this.selectedChart this.showingSelectedChart)}}
<div class="admin-report-sentiment-analysis__selected-chart">
<DButton
@label="back_button"
@icon="chevron-left"
class="btn-flat"
@action={{this.backToAllCharts}}
/>
<div class="admin-report-sentiment-analysis__selected-chart-actions">
<DButton
@label="back_button"
@icon="chevron-left"
class="btn-flat"
@action={{this.backToAllCharts}}
/>

{{!-- <DButton
@title="discourse_ai.sentiments.sentiment_analysis.share_chart"
@icon={{this.shareIcon}}
@action={{this.shareChart}}
class="share btn-flat"
/> --}}
<DTooltip
class="share btn-flat"
@icon={{this.shareIcon}}
{{on "click" this.shareChart}}
@content={{i18n
"discourse_ai.sentiments.sentiment_analysis.share_chart"
}}
/>
</div>

<DoughnutChart
@labels={{@model.labels}}
@colors={{this.colors}}
@data={{this.selectedChart.scores}}
@totalScore={{this.selectedChart.total_score}}
@doughnutTitle={{this.selectedChart.title}}
@radius={{100}}
/>

</div>
<div class="admin-report-sentiment-analysis-details">
<HorizontalOverflowNav
Expand Down
19 changes: 15 additions & 4 deletions assets/javascripts/discourse/components/doughnut-chart.gjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { concat } from "@ember/helper";
import { htmlSafe } from "@ember/template";
import { isDevelopment } from "discourse/lib/environment";
import Chart from "admin/components/chart";

export default class DoughnutChart extends Component {
Expand All @@ -18,11 +21,19 @@ export default class DoughnutChart extends Component {
);
}

getRadius() {
if (this.args.radius) {
return this.args.radius;
} else if (isDevelopment()) {
return this.calculateRadius(Math.floor(Math.random() * (100 + 1)));
} else {
return this.calculateRadius(this.args.totalScore);
}
}

get config() {
const totalScore = this.args.totalScore || "";
// const radius = this.calculateRadius(this.args.totalScore)
// Temporary for tesitng:
const radius = this.calculateRadius(Math.floor(Math.random() * (100 + 1)));
const radius = this.getRadius();

const paddingTop = 30;
const paddingBottom = 0;
Expand Down Expand Up @@ -108,7 +119,7 @@ export default class DoughnutChart extends Component {
{{#if this.config}}
<h3
class="doughnut-chart-title"
style="max-width: {{this.canvasSize}}px"
style={{htmlSafe (concat "max-width: " this.canvasSize "px")}}
>{{@doughnutTitle}}</h3>
<Chart @chartConfig={{this.config}} class="admin-report-doughnut" />
{{/if}}
Expand Down
14 changes: 12 additions & 2 deletions assets/stylesheets/modules/sentiment/common/dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,23 @@
font-size: var(--font-up-2);
margin: 0 auto;
text-align: center;
margin-bottom: 1rem;
margin-top: 0.3rem;
padding-top: 2rem;
padding-bottom: 1rem;
border-top: 1px solid var(--primary-low);
}
}

&__selected-chart-actions {
display: flex;
align-items: center;
.share {
margin-left: auto;

.d-icon-check {
color: var(--success);
}
}
}
}

:root {
Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ en:
overview: "Sentiment overview"
analysis: "Sentiment analysis"
sentiment_analysis:
share_chart: "Copy link to chart"
filter_types:
all: "All"
positive: "Positive"
Expand Down
5 changes: 3 additions & 2 deletions lib/sentiment/entry_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def inject_into(plugin)
end,
) { ClassificationResult.has_sentiment_classification? }

if ClassificationResult.has_sentiment_classification? && SiteSetting.ai_sentiment_enabled &&
SiteSetting.ai_sentiment_reports_enabled
if Rails.env.test? ||
ClassificationResult.has_sentiment_classification? &&
SiteSetting.ai_sentiment_enabled && SiteSetting.ai_sentiment_reports_enabled
EmotionFilterOrder.register!(plugin)
EmotionDashboardReport.register!(plugin)
SentimentDashboardReport.register!(plugin)
Expand Down
5 changes: 4 additions & 1 deletion spec/reports/sentiment_analysis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
fab!(:post_2) { Fabricate(:post, user: admin, topic: topic) }
fab!(:classification_result) { Fabricate(:classification_result, target: post) }

before { SiteSetting.ai_sentiment_enabled = true }
before do
SiteSetting.ai_sentiment_reports_enabled = true
SiteSetting.ai_sentiment_enabled = true
end

it "contains the correct filters" do
report = Report.find("sentiment_analysis")
Expand Down

0 comments on commit 8b0cdcb

Please sign in to comment.