Skip to content

Refactor pagination#58

Closed
rserur wants to merge 9 commits into
masterfrom
refactor-pagination
Closed

Refactor pagination#58
rserur wants to merge 9 commits into
masterfrom
refactor-pagination

Conversation

@rserur
Copy link
Copy Markdown
Contributor

@rserur rserur commented Jun 14, 2018

The pagination class is refactored here to:

  • keep track of the current bundle to navigate,
  • go to a specific page number if there is server support,
  • and use custom parameter names if a particular server that doesn't use what is listed as default here (_getpages, _getpagesoffset, and _count).

Built to support pagination in FHIRKit Create React App.

Copy link
Copy Markdown
Contributor

@Jammjammjamm Jammjammjamm left a comment

Choose a reason for hiding this comment

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

This looks like a promising refactor. A few general comments:

  • It's not totally clear which methods are intended to be public/private, so @private should be added to the private ones.
  • The public methods should have examples and tests. I see tests were added for gotoPage, but initialize at least seems like another public method that should be tested.
  • I brought up several naming issues. We should probably just discuss these in person and see what we can come up with.

Comment thread lib/pagination.js Outdated
*
* @returns {void}
*/
initialize(results) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If results is always a Bundle, I think it should be called bundle.

Comment thread lib/pagination.js Outdated
*
* @returns {void}
*/
parseUrl(link) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this could have a more descriptive name. Something like extractSearchParams or detectSearchParams?

Comment thread lib/pagination.js Outdated
parseUrl(link) {
const linkUrl = new URL(link.url);

Object.keys(this.paramNames).forEach((paramName) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like it should use Object.entries

Object.entries(this.paramNames).foreach(([paramName, param]) => ...)

Comment thread lib/pagination.js Outdated
*
* @return {Promise<Object>} FHIR resources in a FHIR Bundle structure.
*/
nextPage() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If nextPage and prevPage take an optional bundle as an argument, they can call initialize with it. That way this PR won't break the existing interface.

Comment thread lib/pagination.js
* @param {Object} [paramNames.countParam] server-based result count per page, optional.
*/
constructor(httpClient) {
constructor(httpClient, paramNames = {}) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The client constructor doesn't provide a way to pass paramNames to this constructor.

Comment thread lib/pagination.js
this.currentResults = null;

const defaultParamNames = {
searchIdParam: '_getpages',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you explain what this param actually is?
I see:

offsetParam: '_getpageoffset',
countParam: '_count'

and those make obvious sense, but when I look at searchIdParam: '_getpages' I don't really know what's going on.

Comment thread lib/pagination.js
* here if needed for variations in server parameter names.
*
* @param {HttpClient} httpClient a configured instance of http client.
* @param {Object} paramNames pagination-related search parameter names, optional.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we discuss some alternative names for paramNames? Probably easier to do face to face.

Comment thread lib/pagination.js
goToPage(page) {
const selectedPage = this.goToPageLink(page);

this.currentResults = selectedPage ? this.httpClient.get(selectedPage) : undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is really just getAndSetCurrent(selectedPage), right?

Comment thread lib/pagination.js Outdated
prevPage(results) {
const prevLink = results.link.find(link => link.relation.match(/^prev(ious)?$/));
return prevLink ? this.httpClient.get(prevLink.url) : undefined;
getAndSetCurrent(link) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rename this setCurrent. I think it's pretty normal for a setter to return the value that was set, and the fact that it does so doesn't need to be called out in its name. Maybe we could look into using getters and setters or something and come up with a solution that doesn't need set in the name either.

Comment thread lib/pagination.js Outdated
*
* @return {String} link to specified page based on regex.
*/
getLink(regex) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe findLink?

@bkaney bkaney closed this Feb 8, 2019
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