From 19a522fa8fe29cbc3ca888f2c8445047887e2166 Mon Sep 17 00:00:00 2001 From: Rainer Dema Date: Thu, 28 Sep 2023 18:50:48 +0200 Subject: [PATCH] Refactor event dispatching in Stimulus controllers Switched from using `stimulus-use` dispatch to explicit bubbling. While using `stimulus-use`, targeting an upstream controller without specifying the controller's name wasn't feasible in this context. I've reverted to explicitly setting the event's bubbling property. --- admin/app/components/solidus_admin/ui/table/component.js | 8 ++++---- .../solidus_admin/ui/table/ransack_filter/component.js | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/admin/app/components/solidus_admin/ui/table/component.js b/admin/app/components/solidus_admin/ui/table/component.js index 0e08ce4f22f..03bb282adbf 100644 --- a/admin/app/components/solidus_admin/ui/table/component.js +++ b/admin/app/components/solidus_admin/ui/table/component.js @@ -30,8 +30,8 @@ export default class extends Controller { } connect() { - this.element.addEventListener("ui--table--ransack-filter:showSearch", () => this.showSearch()) - this.element.addEventListener("ui--table--ransack-filter:search", () => this.search()) + this.element.addEventListener("showSearch", () => this.showSearch()) + this.element.addEventListener("search", () => this.search()) if (this.searchFieldTarget.value !== "") this.modeValue = "search" @@ -120,7 +120,7 @@ export default class extends Controller { } disconnect() { - this.element.removeEventListener("ui--table--ransack-filter:showSearch", () => this.showSearch()) - this.element.removeEventListener("ui--table--ransack-filter:search", () => this.search()) + this.element.removeEventListener("showSearch", () => this.showSearch()) + this.element.removeEventListener("search", () => this.search()) } } diff --git a/admin/app/components/solidus_admin/ui/table/ransack_filter/component.js b/admin/app/components/solidus_admin/ui/table/ransack_filter/component.js index e75c8425731..4450de5004f 100644 --- a/admin/app/components/solidus_admin/ui/table/ransack_filter/component.js +++ b/admin/app/components/solidus_admin/ui/table/ransack_filter/component.js @@ -28,7 +28,9 @@ export default class extends Controller { } showSearch() { - if (this.isAnyCheckboxChecked()) this.dispatch('showSearch') + if (this.isAnyCheckboxChecked()) { + this.element.dispatchEvent(new CustomEvent("showSearch", { bubbles: true })) + } } filterOptions(event) { @@ -39,7 +41,8 @@ export default class extends Controller { } search() { - this.dispatch('search') + this.element.dispatchEvent(new CustomEvent("search", { bubbles: true })) + this.highlightFilter() }