avo-hq / avo

Build Ruby on Rails apps 10x faster
https://avohq.io
Other
1.43k stars 222 forks source link

Configure `search_count` per resource #2901

Open Paul-Bob opened 4 days ago

Paul-Bob commented 4 days ago

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

  1. Fetch the results_count from the search options like we do with the query here
  2. Execute it using Avo::ExecutionContext like we do with the search_query here
  3. Make sure that results_count can be both, an integer or a Proc
  4. Make sure that resource level results_count takes precedence over the global configuration Avo.configuration.search_results_count
  5. 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
binarygit commented 4 days ago

Could this be assigned to me?