Wrap facility search results with react-infinite via react-infininte-any-height #711
Conversation
There was a single dependency in the `package.json` file that was not in correct alphabetical order.
We will use this to load additional facility search results on demand. Added by running this command on the development Vagrant VM. ``` docker-compose \ run --rm --no-deps app \ yarn add react-infinite@0.13.0 ```
src/app/package.json
Outdated
@@ -25,6 +25,8 @@ | |||
"react-copy-to-clipboard": "5.0.1", | |||
"react-dom": "16.8.6", | |||
"react-hot-loader": "4.9.0", | |||
"react-infinite": "0.13.0", | |||
"react-infinite-any-height": "^2.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing ^
here just to stay in tune with the other imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pinned the react-infinite-any-height
version in fixup a9c5d89
138, // Sidebar controls | ||
51, // Footer | ||
8, // Additional padding | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if we should set these values as constants somewhere if they're hard-coded in multiple places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Since we are styling with JS objects, we should have the luxury of just moving the values out to a shared constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out it is not that easy. There are min-height
and padding
directives coming in from our top level stylesheet as well as Material UI that are complicating things. I am going to instead add class tags to the elements that we need to measure and do the height calculation on the fly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented a class-based height calculation in fixup abdafcf
src/app/src/reducers/UIReducer.js
Outdated
@@ -20,6 +21,10 @@ const initialState = Object.freeze({ | |||
filterText: '', | |||
resetButtonClickCount: 0, | |||
}), | |||
window: Object.freeze({ | |||
innerHeight: typeof window === 'object' ? window.innerHeight : null, | |||
innerWidth: typeof window === 'object' ? window.innerWidth : null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also https://lodash.com/docs/4.17.15#isObject but it probably does the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly there is a subtle difference. _.isObject
considers a function to be an "object"
Good to know, but it doesn't matter in this case. Switching to isObject
will make things a bit more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to using isObject
in fixup 2952bdf
We may not need to worry about them but it appears that react-infinite & react-infinite-any-height cause some peer dependency warnings on yarn install. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking the window size will allow components with fixes sizes to respond accordingly. For example, `react-infinite` requires us to specify a fixed container height.
We plan to allow for the display of all matching search results rather than capping the result count at 500. Using `react-infinite` will allow us to trigger a request for additional items when the person searching for facilities scrolls to the bottom of the partial list. `react-infinite` forces us to explicitly set the size of the container and the size of each item. We are temporarily using a hardcoded 120px height for list items which looks ok for most results. In a future commit we can develop a "height calculator" that would allow us to resume using variable height list items.
`react-infinite-any-height` is a wrapper around `react-infinite` that wraps each list item with a span and uses that span to calculate the height, preventing the need to force all list items to be the same height. There is a lot of variability in the length of facility names and addresses. On narrow screens some list items can be twice as tall as others.
Thanks for the excellent suggestions. |
Overview
Wraps search facility results with
react-infinite
viareact-infininte-any-height
in preparation for loading more than 500 results.Connects #705
Demo
Notes
React infinite requires that we specify the height of the list item container. We accomplish this by listening for window resize events, tracking the window size in the Redux state, then calculating the proper container size.
react-infinite-any-height
is a wrapper aroundreact-infinite
that wraps each list item with a span and uses that span to calculate the height, preventing the need to force all list items to be the same height. There is a lot of variability in the length of facility names and addresses. On narrow screens some list items can be twice as tall as others.Testing Instructions
./scripts/update
to install the new packagesChecklist
fixup!
commits have been squashed