Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Fetch next page of facilities via infinite scroll component #750

Merged
merged 2 commits into from Aug 29, 2019

Conversation

kellyi
Copy link
Contributor

@kellyi kellyi commented Aug 26, 2019

Overview

Adjust facilities tab so that it will fetch the next page of facilities
on reaching the bottom of the infinite scroll list.

Also:

  • remove some now unused utility code & tests
  • update facilities list endpoint to return results in alphabetical
    order
  • update url to retrieve facilities to request pages of 25 results at a
    time
  • add a loading indicator to display contextually at the temporary bottom of the list when there's another page of items to fetch

Connects #742

Notes

I'm going to make a new issue for scroll restoration. I had worked out part of a solution using a custom hook, but it's most likely an enhancement that we can address later if desired.

Testing Instructions

  • serve this branch, then search for some facilities
  • verify that the results return in alphabetical order in the sidebar and that a new page is fetched each time you reach the bottom of the list (until no pages remain)
  • verify that any filters you've applied remain applied when fetching a new page of results

Checklist

  • fixup! commits have been squashed
  • CI passes after rebase
  • CHANGELOG.md updated with summary of features or fixes, following Keep a Changelog guidelines

@kellyi kellyi force-pushed the ki/load-facilities-on-sidebar-scroll branch 4 times, most recently from 0fb908c to 72e7a41 Compare August 27, 2019 21:26
@kellyi
Copy link
Contributor Author

kellyi commented Aug 27, 2019

Targeted this at the marker click branch, btw, since I initially branched off that one.

@kellyi kellyi marked this pull request as ready for review August 27, 2019 21:28
@kellyi kellyi requested a review from jwalgran August 27, 2019 21:29
@jwalgran
Copy link
Contributor

Looking at this now.

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

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

Nice implementation. I'm glad this was as simple as I expected, and I love a PR that adds functionality and decreases line count at the same time. I have some small questions and suggestions.

} = getState();

if (!nextPageURL) {
return noop();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a benefit to return noop(); instead of the equivalent return;?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe they're basically equivalent insofar as each will make the return value undefined, but I think the explicit return noop() is a little more readable when scanning through the code.

const headerDisplayString = facilitiesCount && (facilitiesCount !== filteredFacilities.length)
? `Displaying ${filteredFacilities.length} facilities of ${facilitiesCount} results`
: `Displaying ${filteredFacilities.length} facilities`;
const headerDisplayString = facilitiesCount && `${facilitiesCount} results`;
Copy link
Contributor

Choose a reason for hiding this comment

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

0 is falsy, so headerDisplayString would be "0" instead of "0 results." We currently don't show the results list if there are zero results, so this isn't really an issue.

Consider adding a pluralization util function to avoid showing "1 results"

Screen Shot 2019-08-27 at 3 34 36 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a utility function and test in 915004a

@@ -93,7 +91,7 @@ export const makeGetCountriesURL = () => '/api/countries/';

export const makeGetFacilitiesURL = () => '/api/facilities/';
export const makeGetFacilityByOARIdURL = oarId => `/api/facilities/${oarId}/`;
export const makeGetFacilitiesURLWithQueryString = qs => `/api/facilities/?${qs}`;
export const makeGetFacilitiesURLWithQueryString = qs => `/api/facilities/?${qs}&pageSize=25`;
Copy link
Contributor

Choose a reason for hiding this comment

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

We check this literal 25 in a test so we should consider extracting it into constants.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! Done in 1de1e06

error: { $set: null },
data: {
features: {
$set: state.facilities.data.features.concat(get(payload, 'features', [])),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider

$push: get(payload, 'features', [])

Which appears to work identically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. This is
3be94f6

@kellyi kellyi force-pushed the ki/load-facilities-on-sidebar-scroll branch from aae6a11 to 915004a Compare August 28, 2019 15:51
@kellyi
Copy link
Contributor Author

kellyi commented Aug 28, 2019

@jwalgran I believe this is ready for another look!

@kellyi kellyi changed the base branch from ki/handle-marker-clicks to develop August 28, 2019 17:38
Adjust facilities tab so that it will fetch the next page of facilities
on reaching the bottom of the infinite scroll list.

Also:

- remove some now unused utility code & tests
- update facilities list endpoint to return results in alphabetical
order
- update url to retrieve facilities to request pages of 25 results at a
time
- add a loading indicator contextually if there's a next page of facilities to fetch
@kellyi kellyi force-pushed the ki/load-facilities-on-sidebar-scroll branch from 76c4b2c to bee55de Compare August 28, 2019 17:40
@kellyi
Copy link
Contributor Author

kellyi commented Aug 28, 2019

Squashed and rebased on develop.

Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

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

This is working perfectly, but it occurred to me that this is probably not the behavior we want when the vector tile feature flag is off

2019-08-29 08 18 20

I had imagined that the entire "show arbitrary number of facilities" feature would be enabled as a whole. Do you think we could gate this new behavior with the feature flag without a burdensome amount of rewriting?

@kellyi
Copy link
Contributor Author

kellyi commented Aug 29, 2019

Yep, feature flagging this should be easy. In this case what I will do is just add a temporary component that is named NonVectorTileFilterSidebarFacilitiesTab and just includes the old code, then set things up to display conditionally based on whether the feature flag is set.

@kellyi
Copy link
Contributor Author

kellyi commented Aug 29, 2019

@jwalgran 73ad944 adds back the old facilities sidebar functionality so that we can toggle the behavior with the vector_tile switch. I opted to rename the old component rather than the new one, since the download CSV PR has some changes targeting the new component.

@kellyi kellyi changed the title Fetch next page of facilities via infinite scroll Fetch next page of facilities via infinite scroll component Aug 29, 2019
Copy link
Contributor

@jwalgran jwalgran 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 quickly implementing the feature flag. Works perfectly.

@jwalgran jwalgran removed their assignment Aug 29, 2019
Restore the old sidebar facilities tab as a
`NonVectorTileFilterSidebarFacilitiesTab` component so that it can be
displayed when the vector_tile flag is off.

Restore some utility functions (moved into the NonVectorTile...
component) which were required to make the component work, along with
some Redux actions it expected to exist.

Adjust the fetchFacilities function to accept an options object so that
callers can set the page request size. We don't need to make a similar
adjustment to the fetchNextPage function since it uses the URL returned
from the API for its next page of results.
@kellyi kellyi force-pushed the ki/load-facilities-on-sidebar-scroll branch from 7f44a17 to 3058053 Compare August 29, 2019 18:39
@kellyi
Copy link
Contributor Author

kellyi commented Aug 29, 2019

Thanks for your help with this!

@kellyi kellyi merged commit e019541 into develop Aug 29, 2019
@kellyi kellyi deleted the ki/load-facilities-on-sidebar-scroll branch August 29, 2019 18:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants