From b1a617e52ae40ae01e0ea17bc600da84f0553f75 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Thu, 6 Mar 2025 12:16:25 -0800 Subject: [PATCH 1/2] DEV: Follow-ups --- .../admin-report-sentiment-analysis.gjs | 2 ++ .../discourse/components/doughnut-chart.gjs | 34 +++++++++++++++++++ .../modules/sentiment/common/dashboard.scss | 31 ++++++++++++++--- lib/sentiment/sentiment_analysis_report.rb | 10 ++++++ 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs b/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs index f49745eb8..2354ec140 100644 --- a/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs +++ b/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs @@ -10,6 +10,7 @@ import { and } from "truth-helpers"; import DButton from "discourse/components/d-button"; import HorizontalOverflowNav from "discourse/components/horizontal-overflow-nav"; import PostList from "discourse/components/post-list"; +import bodyClass from "discourse/helpers/body-class"; import dIcon from "discourse/helpers/d-icon"; import replaceEmoji from "discourse/helpers/replace-emoji"; import { ajax } from "discourse/lib/ajax"; @@ -318,6 +319,7 @@ export default class AdminReportSentimentAnalysis extends Component { {{/unless}} {{#if (and this.selectedChart this.showingSelectedChart)}} + {{bodyClass "showing-sentiment-analysis-chart"}}
{ + const { x, y } = element.tooltipPosition(); + const value = dataset.data[index]; + const nonZeroCount = dataset.data.filter((v) => v > 0).length; + + if (value === 0 || nonZeroCount === 1) { + return; + } + + ctx.fillText(value, x, y); + }); + }, + }, ], }; } diff --git a/assets/stylesheets/modules/sentiment/common/dashboard.scss b/assets/stylesheets/modules/sentiment/common/dashboard.scss index a38f2f84e..08416d5ed 100644 --- a/assets/stylesheets/modules/sentiment/common/dashboard.scss +++ b/assets/stylesheets/modules/sentiment/common/dashboard.scss @@ -44,6 +44,13 @@ display: none; } + .control:last-child { + align-self: flex-end; + + input { + } + } + .control:has(.export-csv-btn) { display: none; } @@ -63,10 +70,12 @@ @include report-container-box(); flex: 2; display: flex; - gap: 1rem; - justify-content: space-around; + gap: 2rem 1rem; + justify-content: space-evenly; align-items: center; flex-flow: row wrap; + padding-inline: 0; + padding-block: 1.5rem; .admin-report-doughnut { padding: 0.25rem; @@ -87,7 +96,7 @@ &:hover { box-shadow: var(--shadow-card); - transform: translateY(-1rem); + transform: translateY(-0.5rem); cursor: pointer; } } @@ -219,6 +228,20 @@ position: sticky; top: 0; padding-top: 1rem; - z-index: z("header"); + z-index: z("timeline"); + } +} + +.showing-sentiment-analysis-chart + .admin-report.sentiment-analysis + .body + .filters { + // Hide elements 2 - 6 when showing selected chart + // as they're not supported being changed in this view + .control:first-of-type { + flex: unset; + } + .control:nth-of-type(n + 2):nth-of-type(-n + 6) { + display: none; } } diff --git a/lib/sentiment/sentiment_analysis_report.rb b/lib/sentiment/sentiment_analysis_report.rb index 5584582ea..2ebe351c5 100644 --- a/lib/sentiment/sentiment_analysis_report.rb +++ b/lib/sentiment/sentiment_analysis_report.rb @@ -10,6 +10,16 @@ class SentimentAnalysisReport def self.register!(plugin) plugin.add_report("sentiment_analysis") do |report| report.modes = [:sentiment_analysis] + pp "============== #{report.filters} ========= #{report.filters.class} ========== #{report.filters.inspect}" + + if report.filters.is_a?(String) + begin + report.filters = JSON.parse(report.filters) + rescue JSON::ParserError => e + Rails.logger.error("#{self.class.name}: #{e.message}") + report.filters = {} + end + end group_by_filter = report.filters.dig(:group_by) || GROUP_BY_FILTER_DEFAULT report.add_filter( From 417c0663a7df9c692d64693e5ddfa1981be1bbc6 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 10 Mar 2025 09:02:43 -0700 Subject: [PATCH 2/2] DEV: Remove code to be handled in separate PR --- lib/sentiment/sentiment_analysis_report.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/sentiment/sentiment_analysis_report.rb b/lib/sentiment/sentiment_analysis_report.rb index 2ebe351c5..5584582ea 100644 --- a/lib/sentiment/sentiment_analysis_report.rb +++ b/lib/sentiment/sentiment_analysis_report.rb @@ -10,16 +10,6 @@ class SentimentAnalysisReport def self.register!(plugin) plugin.add_report("sentiment_analysis") do |report| report.modes = [:sentiment_analysis] - pp "============== #{report.filters} ========= #{report.filters.class} ========== #{report.filters.inspect}" - - if report.filters.is_a?(String) - begin - report.filters = JSON.parse(report.filters) - rescue JSON::ParserError => e - Rails.logger.error("#{self.class.name}: #{e.message}") - report.filters = {} - end - end group_by_filter = report.filters.dig(:group_by) || GROUP_BY_FILTER_DEFAULT report.add_filter(