From 8cf8c7723a40f1a0cbfdb3bf4d377fdd3983b8de Mon Sep 17 00:00:00 2001 From: maebeale Date: Thu, 5 Mar 2026 15:38:13 -0500 Subject: [PATCH 1/2] Fix event name search filter on admin activities page The view passed params[:name] from the Event Name text field but the controller never used it to filter results. Co-Authored-By: Claude Opus 4.6 --- .../admin/ahoy_activities_controller.rb | 5 +++++ spec/requests/admin/ahoy_activities_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/controllers/admin/ahoy_activities_controller.rb b/app/controllers/admin/ahoy_activities_controller.rb index 593ff8e5e..b7f16b504 100644 --- a/app/controllers/admin/ahoy_activities_controller.rb +++ b/app/controllers/admin/ahoy_activities_controller.rb @@ -23,6 +23,11 @@ def index *prefixes.map { |p| "#{p}.%" }) end + # Filter by event name + if params[:name].present? + scope = scope.where("ahoy_events.name LIKE ?", "%#{Ahoy::Event.sanitize_sql_like(params[:name])}%") + end + # Filter by user (if viewing specific user activity) scope = scope.where(user: @users) if @users.present? diff --git a/spec/requests/admin/ahoy_activities_spec.rb b/spec/requests/admin/ahoy_activities_spec.rb index d8b2ea769..2506ade7b 100644 --- a/spec/requests/admin/ahoy_activities_spec.rb +++ b/spec/requests/admin/ahoy_activities_spec.rb @@ -158,6 +158,22 @@ expect(response.body).to include("create.bookmark") expect(response.body).to include("auth.login") end + + it "filters by event name" do + get index_path, params: { name: "auth.login", time_period: "all_time" } + + expect(response).to have_http_status(:ok) + expect(response.body).to include("auth.login") + expect(response.body).not_to include("create.bookmark") + end + + it "filters by partial event name" do + get index_path, params: { name: "bookmark", time_period: "all_time" } + + expect(response).to have_http_status(:ok) + expect(response.body).to include("create.bookmark") + expect(response.body).not_to include("auth.login") + end end describe "GET /admin/activities/visits" do From 3efc52253c3870e510da58d10d4782453960c7d1 Mon Sep 17 00:00:00 2001 From: maebeale Date: Sun, 8 Mar 2026 15:44:03 -0400 Subject: [PATCH 2/2] Rename search param from name to event_name for clarity Co-Authored-By: Claude Opus 4.6 --- app/controllers/admin/ahoy_activities_controller.rb | 4 ++-- app/views/admin/ahoy_activities/index.html.erb | 6 +++--- spec/requests/admin/ahoy_activities_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/ahoy_activities_controller.rb b/app/controllers/admin/ahoy_activities_controller.rb index b7f16b504..3c2b2a24b 100644 --- a/app/controllers/admin/ahoy_activities_controller.rb +++ b/app/controllers/admin/ahoy_activities_controller.rb @@ -24,8 +24,8 @@ def index end # Filter by event name - if params[:name].present? - scope = scope.where("ahoy_events.name LIKE ?", "%#{Ahoy::Event.sanitize_sql_like(params[:name])}%") + if params[:event_name].present? + scope = scope.where("ahoy_events.name LIKE ?", "%#{Ahoy::Event.sanitize_sql_like(params[:event_name])}%") end # Filter by user (if viewing specific user activity) diff --git a/app/views/admin/ahoy_activities/index.html.erb b/app/views/admin/ahoy_activities/index.html.erb index 46084f98f..06ffdf8c1 100644 --- a/app/views/admin/ahoy_activities/index.html.erb +++ b/app/views/admin/ahoy_activities/index.html.erb @@ -25,8 +25,8 @@ - <%= text_field_tag :name, - params[:name], + <%= text_field_tag :event_name, + params[:event_name], placeholder: "e.g. Viewed Workshop", class: "w-full px-3 py-2 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" %> @@ -112,7 +112,7 @@
Quick: - <% safe_params = params.slice(:name, :visit_id, :props, :user_id, :from, :to).to_unsafe_h %> + <% safe_params = params.slice(:event_name, :visit_id, :props, :user_id, :from, :to).to_unsafe_h %> <%= link_to "24h", url_for(safe_params.merge(from: 1.day.ago.to_date)), class: "text-indigo-600 hover:underline" %> diff --git a/spec/requests/admin/ahoy_activities_spec.rb b/spec/requests/admin/ahoy_activities_spec.rb index 2506ade7b..67db19eee 100644 --- a/spec/requests/admin/ahoy_activities_spec.rb +++ b/spec/requests/admin/ahoy_activities_spec.rb @@ -160,7 +160,7 @@ end it "filters by event name" do - get index_path, params: { name: "auth.login", time_period: "all_time" } + get index_path, params: { event_name: "auth.login", time_period: "all_time" } expect(response).to have_http_status(:ok) expect(response.body).to include("auth.login") @@ -168,7 +168,7 @@ end it "filters by partial event name" do - get index_path, params: { name: "bookmark", time_period: "all_time" } + get index_path, params: { event_name: "bookmark", time_period: "all_time" } expect(response).to have_http_status(:ok) expect(response.body).to include("create.bookmark")