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

Re-work pagination and add tests. #38

Closed
wants to merge 42 commits into from

Conversation

benkonrath
Copy link
Collaborator

Here's a first version. This version doesn't include next or previous in the metadata if a number for page can't be found. This is only really expected to happen when next or previous are null for the first and last page. An alternative would be include next and previous in the metadata and set them to -1 for the first and last pages. What do you think?

I also still need to write user facing docs but I'm waiting for that to be setup.

Dustin Farris and others added 30 commits June 30, 2014 12:13
…ults

Set host/namespace defaults to use ember-cli express server
    - The ember-cli-ember-data addon is deprecated
      switched the dependency to ember-data instead
Fix for "Cannot read property 'pkg' of null" error
@@ -23,13 +23,30 @@ export default DS.RESTSerializer.extend({
* @param {Object} payload
*/
extractMeta: function(store, type, payload) {

function extractPageNumber(url) {
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure about the name url for this argument. Maybe queryString fits better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

next and previous are URLs and the regex requires ? so the parameter should be a URL with a query string. How about queryStringURL?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For those following: the last comment from @dustinfarris is gone but he now agree that the parameter url is correctly named.

@benkonrath
Copy link
Collaborator Author

Two issues still need to be addressed which are in hidden / out-dated comments:

  • Should next / previous be null when the page query param doesn't exist in the URLs from DRF or should next / previous be excluded in this case (as is currently implemented)?
  • Should extractPageNumber be change to a private method on the serializer?

@dustinfarris
Copy link
Owner

I think we should set to null. It simplifies the code on our end, and is just as easy to work with for the user—for a next or previous that doesn't exist, they'll get null instead of undefined. Either way this fails as expected:

if (meta.next) {
  ...

I think I'd like to see extractPageNumber moved to a private method on the serializer. If anything, this will allow us to write a unit test or two for that specific piece of code.

@benkonrath
Copy link
Collaborator Author

Yep, I agree with both suggestions. I'll have time tomorrow morning to re-work this and checkout your docs PR.

@dustinfarris dustinfarris added this to the Version 1.0 milestone Dec 15, 2014
@benkonrath benkonrath mentioned this pull request Dec 15, 2014
@benkonrath
Copy link
Collaborator Author

Still needs docs which I'll add later today or tomorrow.

@dustinfarris
Copy link
Owner

I suggest adding a separate document for Pagination. If you add it to the mkdocs.yml file it will show up in the sidebar.

@benkonrath
Copy link
Collaborator Author

I'm a bit delayed on this. I'll have more time at the end of this week / next week. I want to update one of my projects to use this before it goes in so that I have a working example to help write clear documentation. I also want to make sure this can work with https://github.com/mharris717/ember-cli-pagination.

@dustinfarris
Copy link
Owner

@benkonrath I moved version-1.0 branch to master and submitted v0.5.0. Can you edit this PR to point at master?

* extractPageNumber is now a private method on the serializer.
* null is returned from extractPageNumber when the page query param
  isn't in the url.
* Create unit tests specifically for extractPageNumber and remove
  the previous indirect tests.
* next / previous are now always included in the metadata.
@benkonrath
Copy link
Collaborator Author

The work in this PR will continue in #45.

@benkonrath benkonrath closed this Jan 5, 2015
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.

3 participants