avo
avo copied to clipboard
Configure `search_count` per resource
Context
As a follow up for https://github.com/avo-hq/avo/issues/2885 lets also enable resource level configuration for the search query limit.
Approach
- Fetch the
results_count
from the search options like we do with the query here - Execute it using
Avo::ExecutionContext
like we do with thesearch_query
here - Make sure that
results_count
can be both, an integer or a Proc - Make sure that resource level
results_count
takes precedence over the global configurationAvo.configuration.search_results_count
- Add docs somewhere around here
Final DSL should look like:
class Avo::Resources::User < Avo::BaseResource
self.search = {
query: -> { query.ransack(name_eq: params[:q]).result(distinct: false) },
results_count: -> { user.admin ? 30 : 10 }
}
end