From 5d5dbe32455c08044797fc56d1027e992c84f7f0 Mon Sep 17 00:00:00 2001 From: maebeale Date: Fri, 6 Mar 2026 06:01:41 -0500 Subject: [PATCH 1/3] Add resource name, visit ID, and props filters to activity events Adds three new search fields to the admin activities events page: - Resource Name: text search on resource_title in event properties JSON - Visit ID: integer filter on visit_id (backend existed, adds UI) - Props: full-text search across the entire properties JSON blob Also adds filter badges to the active filters subheader and preserves new params in quick range links. Co-Authored-By: Claude Opus 4.6 --- .../admin/ahoy_activities_controller.rb | 18 ++++++++++ .../admin/ahoy_activities/index.html.erb | 35 ++++++++++++++++++- .../shared/_active_filters_subheader.html.erb | 15 ++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/ahoy_activities_controller.rb b/app/controllers/admin/ahoy_activities_controller.rb index bbde0a21f..0a912acfd 100644 --- a/app/controllers/admin/ahoy_activities_controller.rb +++ b/app/controllers/admin/ahoy_activities_controller.rb @@ -44,6 +44,24 @@ def index scope = scope.where(visit_id: params[:visit_id]) end + # Filter by resource name (resource_title in properties JSON) + if params[:resource_name].present? + term = Ahoy::Event.sanitize_sql_like(params[:resource_name]) + scope = scope.where( + "JSON_UNQUOTE(JSON_EXTRACT(ahoy_events.properties, '$.resource_title')) LIKE ?", + "%#{term}%" + ) + end + + # Filter by props (full-text search across properties JSON) + if params[:props].present? + term = Ahoy::Event.sanitize_sql_like(params[:props]) + scope = scope.where( + "CAST(ahoy_events.properties AS CHAR) LIKE ?", + "%#{term}%" + ) + end + # Audience filter scope = apply_audience_filter(scope) diff --git a/app/views/admin/ahoy_activities/index.html.erb b/app/views/admin/ahoy_activities/index.html.erb index 40f817eb7..82879855f 100644 --- a/app/views/admin/ahoy_activities/index.html.erb +++ b/app/views/admin/ahoy_activities/index.html.erb @@ -31,6 +31,39 @@ class: "w-full px-3 py-2 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" %> + +
+ + <%= text_field_tag :resource_name, + params[:resource_name], + placeholder: "e.g. My Workshop", + class: "w-full px-3 py-2 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" %> +
+ + +
+ + <%= number_field_tag :visit_id, + params[:visit_id], + placeholder: "e.g. 42", + class: "w-full px-3 py-2 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" %> +
+ + +
+ + <%= text_field_tag :props, + params[:props], + placeholder: "Search properties...", + class: "w-full px-3 py-2 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" %> +
+
- -
- - <%= text_field_tag :resource_name, - params[:resource_name], - placeholder: "e.g. My Workshop", - class: "w-full px-3 py-2 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" %> -
-