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 Lucky::Paginator #1020

Merged
merged 1 commit into from
Mar 13, 2020
Merged

Add Lucky::Paginator #1020

merged 1 commit into from
Mar 13, 2020

Conversation

paulcsmith
Copy link
Member

@paulcsmith paulcsmith commented Mar 3, 2020

This will make it easy to paginate with Lucky. We (and others) can extend this with new goodies since the paginator is decoupled from Avram. This works very very similarly to the Ruby Pagy gem: https://github.com/ddnexus/pagy but with some modifications to link generation and the provided methods.

Still to do:

  • Add specs (this was all tested in an app, but need some real unit tests)
  • Add specs for backend helpers
  • Add specs for components
  • Add in SimpleNav component to get up and running super fast with a built-in component
  • Create templates for Bulma and Bootstrap pagination links to get up and running quickly
  • Add series to help generate gaps and page windows

Probably later on:

  • Paginate array helpers
  • Add pagination to resource generator by default! Helpful to have and shows people how to do it
  • Paginate without count helpers

@paulcsmith paulcsmith changed the title Add Lucky::Paginator [WIP] Add Lucky::Paginator Mar 3, 2020
@jwoertink
Copy link
Member

This will be awesome!

@jkthorne
Copy link
Contributor

Cursor based pagination is becoming more popular. What do you think about adding cursor based pagination support or an interface to implement it yourself?

@paulcsmith
Copy link
Member Author

@wontruefree Definitely in the pipeline! I prefer cursor based for a lot of stuff. Doesn't work for everything, but when it does it is awesome!

@jkthorne
Copy link
Contributor

Agreed it does not work for everything. Also can add tons of complexity in edge cases. that is the reason I mentioned just an interface for it.

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

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

It's a lot going on, but it all looks good from what I can tell. This is pretty huge! I love that you included the Bootstrap and Bulma as built-in components. That will help people to extend as needed.

I left some comments on the specs, but otherwise I think we can get this in! Good job 🎉

pages, records = Paginatable.new(page: "2").call

pages.page.should eq(2)
pages.per_page.should eq(25)
Copy link
Member

Choose a reason for hiding this comment

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

Just as a safety, should we still have pages.total.should eq(2)?

pages, records = PaginatableWithOverriddenMethods.new.call

pages.page.should eq(2)
pages.per_page.should eq(10)
Copy link
Member

Choose a reason for hiding this comment

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

Same. Maybe having pages.total.should eq(5)?

page: paginator_page,
per_page: per_page,
item_count: query.clone.reset_order.reset_limit.reset_offset.select_count,
full_path: context.request.resource
Copy link
Member

Choose a reason for hiding this comment

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

So with this, if you need to override what your page link paths are, you'd just pass in the string? full_path: "/whatever"

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case you can't since the method is hardcoded to using the current path. We could add a setter for full_path or an option on the paginate method, but I think this is a good start for MVP since I think 99% of the time you want to paginate the same url

begin beginning : Int32 = 0,
left_of_current : Int32 = 0,
right_of_current : Int32 = 0,
end ending : Int32 = 0
Copy link
Member

Choose a reason for hiding this comment

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

I'm shocked that works.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hah yeah me too. Glad it did though!

Copy link
Member Author

@paulcsmith paulcsmith left a comment

Choose a reason for hiding this comment

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

Thanks for the review!

begin beginning : Int32 = 0,
left_of_current : Int32 = 0,
right_of_current : Int32 = 0,
end ending : Int32 = 0
Copy link
Member Author

Choose a reason for hiding this comment

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

Hah yeah me too. Glad it did though!

page: paginator_page,
per_page: per_page,
item_count: query.clone.reset_order.reset_limit.reset_offset.select_count,
full_path: context.request.resource
Copy link
Member Author

Choose a reason for hiding this comment

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

In this case you can't since the method is hardcoded to using the current path. We could add a setter for full_path or an option on the paginate method, but I think this is a good start for MVP since I think 99% of the time you want to paginate the same url

@paulcsmith paulcsmith merged commit d0336ef into master Mar 13, 2020
@paulcsmith paulcsmith deleted the pcs/paginator branch March 13, 2020 17:32
@paulcsmith
Copy link
Member Author

Added the extra checks in f4df5a1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants