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

Countless pagination #108

Merged
merged 10 commits into from
Nov 20, 2018
Merged

Countless pagination #108

merged 10 commits into from
Nov 20, 2018

Conversation

ddnexus
Copy link
Owner

@ddnexus ddnexus commented Nov 18, 2018

Add the Pagy::Countless subclass and the countless extra.

@ddnexus
Copy link
Owner Author

ddnexus commented Nov 18, 2018

@workgena I didn't try the code yet. If you have time, please, take a look at it. The doc should be already OK, but it is missing the tests for the Pagy::Countless and countless extra. Any help will be very appreciated. Thanks.

@workgena
Copy link
Contributor

Today I'll take a look at this solution. And will write tests for it.

One thing I see strait away is:

  • original Pagy returns ActiveRelation, in cast of ActiveRecord(Rails)
  • Contless returns an Array

Since, it is another subclass - it should be OK, no braking change, I think. Worth mention in documentation.

@ddnexus
Copy link
Owner Author

ddnexus commented Nov 19, 2018 via email

@workgena workgena mentioned this pull request Nov 19, 2018
@ddnexus
Copy link
Owner Author

ddnexus commented Nov 19, 2018

Thanks for fixing my typos in the items test :).
Thanks for the extra countless tests.
It looks like we miss only the Pagy::Countless.

@workgena
Copy link
Contributor

Many cases for Pagy::Countless already covered(implicitly).

Some new logic in finalize should be covered explicitly, values at:

attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next

@workgena
Copy link
Contributor

I've integrated this countless-branch into my project at work.

I was a little bit concerned about COUNTLESS = true, but it works absolutely fine. Let me explain the use-case:

Each user can decide what pagination to use: Normal(with count) or Fast(Countless) by changing user-settings. So, PostsController always has require 'pagy/extras/countless' included. Depending on the user settings, the code executes with pagy(collection) or pagy_countless(collection).

Both scenarios work as expected.

@ddnexus
Copy link
Owner Author

ddnexus commented Nov 20, 2018

I didn't understand what was your concern with COUNTLESS.

BTW, your use-case looks interesting. If you have time, you may want to write some article/tutorial explaining what you did.

pagy_get_vars_without_items(collection, vars)
end
alias_method :pagy_get_vars, :pagy_get_vars_with_items

# support for countless extra
if defined?(Pagy::COUNTLESS) # defined in the countless extra
Copy link
Contributor

@workgena workgena Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets imagine PostsController with require 'pagy/extras/countless' always. So Pagy::COUNTLESS = true.

But in fact it uses normal pagination with @pagy, @records = pagy(collection).

I was afraid, that this block of code populates vars with wrong values.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood. The COUNTLESS constant is just to avoid to load the aliases and method for the items extra... but that is done at load time. Then it does not matter because they are designed to work in parallel, with different named classes and methods.

@ddnexus ddnexus merged commit 051f024 into dev Nov 20, 2018
@espen
Copy link
Contributor

espen commented Nov 21, 2018

Just a thought here: this looks great and I assume it would be mostly useful with endless scrolling and other non-nav UI. However this could still be useful when having a normal pagy_nav. And in those situations I think the nav helper should just have next/prev links. Currently it will shows "page 1, 2" on load when the total pages is maybe 90. I understand why, but the result is confusing UX. So a better situation for the user would be to just have next/prev links and skip the page numbers.

@ddnexus
Copy link
Owner Author

ddnexus commented Nov 21, 2018

@espen: just feed size: [] to remove all the page links, leaving you only the previous/next buttons

@workgena
Copy link
Contributor

BTW, me miss this in documentation 📚 ...

@ddnexus
Copy link
Owner Author

ddnexus commented Nov 21, 2018

@workgena this time I didn't forget :)

Skipping the page links

Also reported in the last note of series

@ddnexus
Copy link
Owner Author

ddnexus commented Nov 21, 2018

@espen @workgena Endless scrolling (or incremental scroll) is coming with the more extra (currently in development). It will provide the countless pagination with empty series and a few helpers like pagy_more_url, pagy_more_link and pagy_more_json to implement manual or ajax incremental scroll.

I need someone for trying it and writing tests (hoping to be able to push it soon with at least the doc)

@espen
Copy link
Contributor

espen commented Nov 21, 2018

Thanks. Will try this out a bit more. I think as a user (at least in my app) it's rarely relevant to me how many pages I have. Either I use search or just click next. So skipping one SQL query and not present page links could be a good solution both for performance and UX.

Awesome to hear that endless scrolling will be implemented.

@ddnexus ddnexus added the merged label Nov 21, 2018
@ddnexus ddnexus deleted the countless branch December 3, 2018 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants