Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to configure via_per_page on has_many #2661

Open
smathieu opened this issue Apr 4, 2024 · 5 comments
Open

Add option to configure via_per_page on has_many #2661

smathieu opened this issue Apr 4, 2024 · 5 comments
Labels
Configuration Enhancement New feature or request Help wanted We could use some help with this

Comments

@smathieu
Copy link

smathieu commented Apr 4, 2024

Feature

Currently, it seems only possible to set a global via_per_page.

It would be useful to have the ability to override that value in the resource itself.

API could be something like:

module Avo
  module Resources
    class CatalogProduct < Avo::BaseResource
      def fields
         field :certifications, as: :has_many, per_page: 72
      end
  end
end

or alternatively, we could default it per resource.

module Avo
  module Resources
    class CatalogCertification < Avo::BaseResource
      self.via_per_page = 72
      self.per_page = 24
      def fields
        # ...
      end
  end
end

This is useful because in most case, we want a smaller pagination window, but we do have a few workflows where it's useful to see a large amount of items for triggering action on a batch of records.

Current workarounds

Not aware of any

Screenshots or screen recordings

Additional context

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Apr 5, 2024

I think this can be useful, thanks for submitting it @smathieu

API suggestion:

module Avo
  module Resources
    class CatalogCertification < Avo::BaseResource
      self.pagination = -> do
        {
         via_per_page: 72
         per_page: 24
        }
      end
      def fields
        # ...
      end
  end
end

This way inside pagination proc we can do some custom logic looking into params to check if is association or not and set pagination params accordingly.

@Paul-Bob Paul-Bob added Enhancement New feature or request Configuration labels Apr 5, 2024
@adrianthedev
Copy link
Collaborator

You can set the via_per_page globally right now.

Otherwise, IDK is self.via_per_page would do it justice.
I would rather do the first option:

field :certifications, as: :has_many, per_page: 72

@adrianthedev adrianthedev added the Help wanted We could use some help with this label Apr 15, 2024
@adrianthedev
Copy link
Collaborator

If the global configuration is enough for you, @smathieu, then it's ok to close this issue.
If you need something more granular, we'll merge a PR with that.
Unfortunately, we can't prioritize and work on it right now.

@smathieu
Copy link
Author

The global configuration doesn't work very well for us, as we do have a use case where we need ~100 records rendering in a page, but that's way too much for other views.

This isn't super urgent for us, but we'd definitely benefit from the option to configure it.

All proposed API would work, but I think I prefer the per field proposed by @adrianthedev

@adrianthedev
Copy link
Collaborator

Got it!

Yes, the field config should work better from the same reason that you want to configure the per_page only in some scenarios.

I added the Help wanted label. Maybe someone wants to pick it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Configuration Enhancement New feature or request Help wanted We could use some help with this
Projects
Status: To Do
Development

No branches or pull requests

3 participants