Skip to content

[Feature] Add cursor pagination to Livewire #3215

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

Merged
merged 31 commits into from
Dec 8, 2021
Merged

[Feature] Add cursor pagination to Livewire #3215

merged 31 commits into from
Dec 8, 2021

Conversation

ariaieboy
Copy link
Contributor

1️⃣ Is this something that is wanted/needed? Did you create an issue / discussion about it first?
#3182
2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.
No
3️⃣ Does it include tests, if possible? (Not a deal-breaker, just a nice-to-have)
No, I looked at the default pagination tests they only test that page property is set currectly or Not
since the cursor pagination dont use numbers as refrrence for pagination and use a encoded string based from the data i couldnt add test for it if you guys give me a hint i may can add some test for it.

4️⃣ Please include a thorough description of the improvement and reasons why it's useful.
laravel introduced cursor pagination in laravel v8.41.0 this PR aim to add this feature to livewire pagination system.

with this PR users can replace withPagination trait with withCursorPagination trait and change paginate() method with cursorPaginate() and use cursor pagination instead of regular pagination in livewire

5️⃣ Thanks for contributing! 🙌

@nuernbergerA
Copy link
Contributor

Nice PR, the only concern is the version constraint with laravel.

@calebporzio maybe its time to only support the current laravel version (it's not a big deal nowadays to keep your app up to date).
and if you wanna use modern tech (like livewire) update your app, if you cant update you can still use the current (old) livewire version (without updates).

@ariaieboy
Copy link
Contributor Author

Nice PR, the only concern is the version constraint with laravel.

@calebporzio maybe its time to only support the current laravel version (it's not a big deal nowadays to keep your app up to date).
and if you wanna use modern tech (like livewire) update your app, if you cant update you can still use the current (old) livewire version (without updates).

about this PR i don't think the laravel version will be a big concern cause its just a trait that user can add it manually. and we can notice them in docs that this feature only works with laravel 8.41+

But in general I agree with you. And I think not only the Laravel version should be limited to the latest version, but also the php version should be limited to the versions that are actively supported.

@danharrin
Copy link
Contributor

Before another pagination trait gets added, is it possible to ensure this one supports multiple pagination instances on a single component from the start? That's LW's biggest failing at the moment in my opinion.

@ariaieboy
Copy link
Contributor Author

Before another pagination trait gets added, is it possible to ensure this one supports multiple pagination instances on a single component from the start? That's LW's biggest failing at the moment in my opinion.

I can add this feature for both pagination traits but I need to change the livewire paginator api and since users maybe publishes the views and uses custom themes it might not be backward compatible so we can't merge it with current version branch.

but still i am looking at this problem and may come with a solution without breaking things

@danharrin
Copy link
Contributor

Before another pagination trait gets added, is it possible to ensure this one supports multiple pagination instances on a single component from the start? That's LW's biggest failing at the moment in my opinion.

I can add this feature for both pagination traits but I need to change the livewire paginator api and since users maybe publishes the views and uses custom themes it might not be backward compatible so we can't merge it with current version branch.

but still i am looking at this problem and may come with a solution without breaking things

Yeah, even just adding support on this new trait would be good, since there would be no breaking changes.

@ariaieboy
Copy link
Contributor Author

Before another pagination trait gets added, is it possible to ensure this one supports multiple pagination instances on a single component from the start? That's LW's biggest failing at the moment in my opinion.

I can add this feature for both pagination traits but I need to change the livewire paginator api and since users maybe publishes the views and uses custom themes it might not be backward compatible so we can't merge it with current version branch.
but still i am looking at this problem and may come with a solution without breaking things

Yeah, even just adding support on this new trait would be good, since there would be no breaking changes.

i am working on a new pr that add multiple pagination on single component but @calebporzio need to review and accept it

@calebporzio
Copy link
Collaborator

@ariaieboy - I haven't really dug into this problem, but is it possible to support his in the existing WithPagination trait?

@ariaieboy
Copy link
Contributor Author

@ariaieboy - I haven't really dug into this problem, but is it possible to support his in the existing WithPagination trait?

it can be implemented in the same WithPagination trait but i think keep them seperated is better option.
because cursor pagination is only supported in laravel 8 and by changing the currunt trait we need alot of checks for laravel < 8 and for using cursor pagination developers need to do some tweaks before using it and it have some limitations vs the regular pagination its better to keep them seperate and let the users decide wich kind of pagination they need to add to their components.

Cursor vs. Offset Pagination

@ariaieboy
Copy link
Contributor Author

in this PR #3264 i've added multiple cursor pagination on single component.

i've used an array to define the paginations queryStrings.
if we want use 1 trait for both pagination we can use a key=>value on that array that the key is the queryString and the value is the pagination type and then we can have multiple pagination in one component with both regular and cursor pagination without any breaking changes .

we add page query string as default and every thing will work without any breaking change.

just watch that PR and if that was ok let me know so i work on it to add regular pagination to it and update my PR according to that.

@joshhanley
Copy link
Member

@ariaieboy I've been working on adding multiple pagination support to the existing with pagination trait that doesn't have breaking changes, but I'm just waiting for my two other pagination PRs to be merged and I will submit it.

@calebporzio
Copy link
Collaborator

@joshhanley - I think we're good now? I don't see any open PRs for you - yeah? Let me know if you need more from me

@calebporzio
Copy link
Collaborator

Ok, Josh's other PRs are all merged now. I'm open to supporting cursor pagination - ideally it would be contained within the same trait with minimal forking

@ariaieboy
Copy link
Contributor Author

@calebporzio
i update my PR and now its works with the same withPagination trait.
i've added 2 tests and in my local i passed all of it please check and confirm the PR.

Copy link
Member

@joshhanley joshhanley left a comment

Choose a reason for hiding this comment

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

@ariaieboy just a few comments and changes 🙂 also not sure why the dist/livewire.js is showing up and licence.md. Can you make sure it's up to date with master so they're not showing in this PR?

Thanks!

@joshhanley joshhanley changed the title add cursor pagination to livewire [Feature] Add cursor pagination to Livewire Sep 10, 2021
@@ -75,8 +86,10 @@ public function resetPage($pageName = 'page')

public function setPage($page, $pageName = 'page')
{
$page = intval($page);
$page = $page <= 0 ? 1 : $page ;
if (is_numeric($page)){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since cursor pagination use string as the identifier we should not cast the $page to intger all the time

@@ -48,20 +48,12 @@ public function double_page_value_should_be_casted_to_int()
->call('gotoPage', 2.5)
->assertSet('page', 2);
}

/** @test */
public function string_page_value_should_be_reset()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

as i said since cursor pagination use string as identifier we should not reeset strings

@ariaieboy
Copy link
Contributor Author

@joshhanley @calebporzio
ok so i rebase my code to master and fixed all tests
i think we can now merge this to master

@calebporzio
Copy link
Collaborator

Thanks so much for this @ariaieboy!

@calebporzio calebporzio merged commit 316783d into livewire:master Dec 8, 2021
@ariaieboy ariaieboy deleted the add_cursor_pagination branch December 8, 2021 21:58
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.

5 participants