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

Create facilities tab & display text search results #237

Merged
merged 3 commits into from
Mar 5, 2019

Conversation

kellyi
Copy link
Contributor

@kellyi kellyi commented Feb 28, 2019

Overview

This PR adds a facilities list tab which will display a list of text search results as depicted below when the facilities results return from a search of the API. I also added a free text search which currently searches on the name address and country_name fields to narrow down the list of visible results, as well as a "Download CSV" functionality which downloads a list of CSV items.

Additionally, this PR also:

  • replaces papaparse with a custom utility function to turn a 2d array into a string, which circumvents a bug whereby JSON.parse would sometimes try to parse the OAR ID as a number but fail and instead print NaN to the CSV
  • adds tests for that newly added utility function
  • adjusts the contributor list to list them in alphabetical order by name
  • adjusts the app's DOM structure to make it possible to scroll subcomponents rather than scrolling the entire app
  • changes the app name in package.json from "redpanda" (which was the legacy name?) to "open apparel registry"

Connects #209
Connects #227
Connects #127
Connects #123

Demo

facilities-list

CSV:
facilities.csv.txt

No results for a search:

screen shot 2019-03-04 at 11 47 10 am

Notes

I made #244 for the map interactions because it will need some dedicated thought about how to handle the various possible kinds of interaction.

Testing

  • get this branch then ./scripts/update
  • run ./scripts/test and verify that everything passes
  • ./scripts/resetdb
  • visit the main map page and
    • verify that the contributors are now listed in alphabetical order by name
    • make a search and verify that you are navigated to the facilities tab on success
    • verify that the free text search works as expected
    • verify that you can download a list of facilities, filtered by your free text search
    • verify that you can scroll through the facilities and that clicking on any of the list items takes you to its details route
  • on the Macbook-sized viewport, check that the following pages scroll correctly following the changes I made to the DOM:
    • /auth/register
    • /contribute
    • /profile/:id/
    • /lists
    • /lists/:id
  • download a facility list and verify that that still works, following the changes to replace papaparse

@kellyi kellyi force-pushed the ki/list-facilities branch 6 times, most recently from bf31713 to de75e16 Compare March 1, 2019 22:30
@kellyi kellyi force-pushed the ki/list-facilities branch 2 times, most recently from 6de75f1 to 12ed908 Compare March 4, 2019 16:37
@kellyi kellyi changed the title WIP: Create facilities tab & display text search results Create facilities tab & display text search results Mar 4, 2019
@kellyi kellyi marked this pull request as ready for review March 4, 2019 16:52
@kellyi kellyi requested a review from jwalgran March 4, 2019 16:52
@jwalgran
Copy link
Contributor

jwalgran commented Mar 4, 2019

Looking at this now

@jwalgran
Copy link
Contributor

jwalgran commented Mar 4, 2019

I'm seeing an odd click target bug when switching tabs in Chrome. Only clicks at the very top or bottom edges of the tab are triggering the state change. Clicks in the middle of the tab are triggering the Material UI animation, but not a state change.

2019-03-04 12 48 52

@kellyi
Copy link
Contributor Author

kellyi commented Mar 4, 2019

I'm seeing an odd click target bug when switching tabs in Chrome.

Weird! I wonder if I set up the click handlers incorrectly. I tested staging and it's not happening there.

@kellyi
Copy link
Contributor Author

kellyi commented Mar 4, 2019

Interesting, I must need to add an ID to another element:

screen shot 2019-03-04 at 3 04 11 pm

@kellyi
Copy link
Contributor Author

kellyi commented Mar 4, 2019

Turns out the correct function signature is:

  handleChange = (event, value) => {
    this.setState({ value });
  };

Adjusted it in 1a05bab

@jwalgran
Copy link
Contributor

jwalgran commented Mar 4, 2019

It is a bit frustrating to loose scroll state on the search results. When navigating back from the details view. Have we done any scroll restoration on other projects that could possibly apply here? This react-router document talks about the issue but does not include a general solution for our issue. https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/guides/scroll-restoration.md

2019-03-04 12 59 58

@kellyi
Copy link
Contributor Author

kellyi commented Mar 4, 2019

It is a bit frustrating to loose scroll state on the search results. When navigating back from the details view. Have we done any scroll restoration on other projects that could possibly apply here?

Make sense. I haven't ever worked on it; the nearest thing to this is the parcel cards sidebar in GARP for which we declined to try to set up scroll restoration.

I'm happy to look into it, but I wonder if it'd make sense as a new card?

@jwalgran
Copy link
Contributor

jwalgran commented Mar 4, 2019

I'm happy to look into it, but I wonder if it'd make sense as a new card?
Yes. We can break scroll state restoration into a separate issue.

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.

I like the design of this solution and it is working well. I made a few small suggestions inline.

There is one usability/inconsistency issue that we may need to consider. There are currently two ways to get to the search results:

  • Clicking the "Search" button on the Search tab.
  • Clicking the "Facilities" tab.
    If you run a search, click back to the search tab, change one of the filters, then click back to the "Facilities" tab you are now in a kind of inconsistent state. We may want to consider one of the following changes to make sure the state of the two tabs are always consistent.
  • Disable the facilities tab (make it inaccessible) until a search has been run
  • Make clicking on the facilities tab trigger a search if the search options have changed
  • Remove the search button and always have the results on facilities tab match the search fields

I think making a click on the facilities tab trigger the search if the options have changed is the most natural given the current behavior. Do you have opinions or other ideas?

@@ -40,8 +38,7 @@
"build": "react-scripts build",
"test": "CI=1 react-scripts test",
"lint": "eslint src/ --ext .js --ext .jsx",
"eject": "react-scripts eject",
"deploy": "npm run build && firebase deploy"
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good that we are removing this legacy deploy command, but we should consider documenting in the commit message why we making this change that is unrelated to CSV processing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a note: I have not changed this yet but I will update the commit message when squashing and rebasing before I merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated commit is
6fd1a9b


const stringArray = [
[
'hello',
Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider including one of our pathological hex strings in the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I added the problematic one in 5c02862

<label
htmlFor={SEARCH_TERM_INPUT}
>
Search results
Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider changing this label to "Filter results" to distinguish search, which takes place on the "Search" tab, from narrowing the list with a text filter. We may want to carry this renaming through to code constants too, i.e. SEARCH_TERM_INPUT -> FILTER_TERM_INPUT

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. 42bbd93 renames these from using searchTerm to using filterText.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am still seeing "Search" on the "Facilities" tab. Consider changing the label to "Filter results" and the placeholder text to "Filter by name, address, or country"

screen shot 2019-03-05 at 2 04 46 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.

I replaced the "Search" text with "Filter" in the adjusted last commit here.


const SEARCH_TERM_INPUT = 'SEARCH_TERM_INPUT';

const makeFacilityListHeightPercentageString = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

On my 1680x1050 screen there is some whitespace between the scrolling results list and the footer. If I shrink the browser window height the whitespace goes away. I looks like the conditional styling set up by this function may be the reason. Is there a way we can make sure that the scrolling area always fills the container?

screen shot 2019-03-04 at 1 29 44 pm

@kellyi
Copy link
Contributor Author

kellyi commented Mar 4, 2019

If you run a search, click back to the search tab, change one of the filters, then click back to the "Facilities" tab you are now in a kind of inconsistent state. We may want to consider one of the following changes to make sure the state of the two tabs are always consistent.

How would you feel about dumping any existing facilities data altogether when the state of the filters on the search tab changes? That'd also solve an inconsistency between prior data and the new filters before "search" has been clicked.

@jwalgran
Copy link
Contributor

jwalgran commented Mar 4, 2019

How would you feel about dumping any existing facilities data altogether when the state of the filters changes?

I think that is a good idea in general, but what would the facilities tab say at that point? If it reverts to the "No facilities were found for that search" message we are in the same situation.

@kellyi
Copy link
Contributor Author

kellyi commented Mar 4, 2019

I think that is a good idea in general, but what would the facilities tab say at that point? If it reverts to the "No facilities were found for that search" message we are in the same situation.

Interesting. Maybe we just don't show the tab at all if there are no facilities in the state to display? I'll try it out locally to see how that works.

@kellyi
Copy link
Contributor Author

kellyi commented Mar 5, 2019

9a189ee creates a new "no facilities to display" state for the sidebar tab so that it will look like this when there's nothing to show:

screen shot 2019-03-05 at 11 00 04 am

In addition, I updated the application state to clear facilities data when any of the search filters change and to drop the markers from the map when the facilities data is cleared. For the latter, I kept the layer around, but just replace the data with an empty geojson feature collection so that no markers will show.

@kellyi
Copy link
Contributor Author

kellyi commented Mar 5, 2019

cd088df updates the facilities list to have its height set dynamically based on the viewport size

@jwalgran this is ready for another look!

@kellyi
Copy link
Contributor Author

kellyi commented Mar 5, 2019

#250 is for scroll restoration

It occurred to me that we may be able to find an infinite scroll library that supports scroll restoration innately. That would also solve potential performance problems if the list of search results was in the thousands.

Kelly Innes added 2 commits March 5, 2019 14:17
- add an order_by('name') clause to the queryset in all_contributors to
sort the results so they'll display alphabetically by name in the client

Connects #227
- remove papaparse library
- create utility function for generating CSV row strings in order to
circumvent a bug whereby JSON.parse would occasionally cast OAR ID shas
into numbers
- add tests for CSV parsing function
- rename app from "redpanda" to "open apparel registry" in package.json
- drop legacy "npm deploy" script from package.json
@kellyi kellyi force-pushed the ki/list-facilities branch from cd088df to 38881b9 Compare March 5, 2019 19:19
@kellyi
Copy link
Contributor Author

kellyi commented Mar 5, 2019

Rebased this on develop & squashed.

@jwalgran
Copy link
Contributor

jwalgran commented Mar 5, 2019

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.

This looks and works well. Thanks for working through the issues. I made just one small text suggestion.

<label
htmlFor={SEARCH_TERM_INPUT}
>
Search results
Copy link
Contributor

Choose a reason for hiding this comment

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

I am still seeing "Search" on the "Facilities" tab. Consider changing the label to "Filter results" and the placeholder text to "Filter by name, address, or country"

screen shot 2019-03-05 at 2 04 46 pm

@jwalgran jwalgran removed their assignment Mar 5, 2019
@kellyi
Copy link
Contributor Author

kellyi commented Mar 5, 2019

I am still seeing "Search" on the "Facilities" tab. Consider changing the label to "Filter results" and the placeholder text to "Filter by name, address, or country"

Oof, must have forgot to update this. Will make this change before merging.

- create facilities tab for displaying a text list of facilities
- add free text search field to search on name, and country name fields
- add functionality to download a CSV of facilities filtered by free
text search
- update Redux actions to handle toggling & displaying the facilities
tab and storing the free text search value
- adjust application HTML element hierarchy & style sheet in order to
   - prevent the enter app from scrolling vertically
   - enable select components to scroll vertically when necessary
@kellyi kellyi force-pushed the ki/list-facilities branch from 38881b9 to b9d88e6 Compare March 5, 2019 21:15
@kellyi
Copy link
Contributor Author

kellyi commented Mar 5, 2019

Thanks for your help with this!

@kellyi kellyi merged commit 57a1cbe into develop Mar 5, 2019
@kellyi kellyi deleted the ki/list-facilities branch March 5, 2019 21:22
@kellyi kellyi mentioned this pull request Mar 5, 2019
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.

3 participants