Skip to content

Commit

Permalink
feat: set search param to index params also try to use
Browse files Browse the repository at this point in the history
ExecutionContext
  • Loading branch information
SahSantoshh committed Jan 29, 2025
1 parent 3fb4517 commit a18e3d3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def index
add_breadcrumb @resource.plural_name.humanize

# Apply the search query if configured on the resource
apply_search_query if params[:q].present? && @resource.search.present?
set_index_params
apply_search
set_filters
set_actions
set_query
Expand Down Expand Up @@ -307,6 +307,9 @@ def set_index_params

set_pagination_params

# Search
@index_params[:q] = params[:q] if params[:q].present?

# Sorting
@index_params[:sort_by] = params[:sort_by] || @resource.sort_by_param

Expand Down Expand Up @@ -646,11 +649,18 @@ def set_query
@query ||= @resource.class.query_scope
end

def apply_search_query
def apply_search
return if @resource.class.search_query.nil?
return if @index_params[:q].nil?

search_query = @resource.search[:query]
return unless search_query.present?

@query = instance_exec(@query, &search_query)
@query = Avo::ExecutionContext.new(
target: @resource.class.search_query,
params: params,
query: @query
).handle
end
end
end

0 comments on commit a18e3d3

Please sign in to comment.