From 50e1bc774a24a5a4257c6b158470a98d1cd1b217 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 24 Mar 2025 10:10:22 -0700 Subject: [PATCH] FIX: unable to click doughnut when no filters (#1213) This PR fixes an issue where you are unable to click to see the sentiment drill-down when there are no current filters applied. This is due to trying to `JSON.parse()` the filters when there are no filters. This fix ensures there are filters first before trying to parse the JSON. --- .../components/admin-report-sentiment-analysis.gjs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs b/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs index fb97c5cc..62a18dfd 100644 --- a/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs +++ b/assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs @@ -216,10 +216,15 @@ export default class AdminReportSentimentAnalysis extends Component { } const currentQueryParams = this.router.currentRoute.queryParams; + + const currentFilters = currentQueryParams?.filters + ? JSON.parse(currentQueryParams.filters) + : {}; + this.router.transitionTo(this.router.currentRoute.name, { queryParams: { ...currentQueryParams, - filters: JSON.parse(currentQueryParams.filters), // avoids a double escaping + filters: currentFilters, // avoids a double escaping selectedChart: data.title, }, }); @@ -265,10 +270,13 @@ export default class AdminReportSentimentAnalysis extends Component { this.posts = []; const currentQueryParams = this.router.currentRoute.queryParams; + const currentFilters = currentQueryParams?.filters + ? JSON.parse(currentQueryParams.filters) + : {}; this.router.transitionTo(this.router.currentRoute.name, { queryParams: { ...currentQueryParams, - filters: JSON.parse(currentQueryParams.filters), // avoids a double escaping + filters: currentFilters, // avoids a double escaping selectedChart: null, }, });