diff --git a/app/javascript/controllers/donut_chart_controller.js b/app/javascript/controllers/donut_chart_controller.js index 0e9219141..9392d9459 100644 --- a/app/javascript/controllers/donut_chart_controller.js +++ b/app/javascript/controllers/donut_chart_controller.js @@ -1,5 +1,6 @@ import { Controller } from "@hotwired/stimulus"; import * as d3 from "d3"; +import { buildCategoryTransactionsUrl } from "utils/transactions_filter_url"; // Connects to data-controller="donut-chart" export default class extends Controller { @@ -250,14 +251,15 @@ export default class extends Controller { // Handles click on segment (optional, controlled by enableClick value) #handleClick(segment) { - if (!segment.name || !this.startDateValue || !this.endDateValue) return; + if (!segment.name) return; - const segmentName = encodeURIComponent(segment.name); - const startDate = this.startDateValue; - const endDate = this.endDateValue; - - const url = `/transactions?q[categories][]=${segmentName}&q[start_date]=${startDate}&q[end_date]=${endDate}`; - window.location.href = url; + Turbo.visit( + buildCategoryTransactionsUrl({ + name: segment.name, + startDate: this.startDateValue, + endDate: this.endDateValue, + }), + ); } // Public methods for external highlighting (e.g., from category list hover)