ETT-787: fix bug -- collection search unreachable from www search bar unless at homepage #129
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

The problem
This took an embarrassing amount of time to untangle. The logic of this component is very circular, and I got stuck in a loop for a while. But! I think I got this right in the end.
The desired behavior for the search bar, regardless of location, is that the user can select to search either the "collection" or the "website" using the dropdown in the search bar. If "website" is selected, the dropdown to filter the "collection" search disappears. If "collection" is selected, then the filter dropdown should return.
On prod right now, if you're on the www site on any page other than the homepage, you can try to select "collection" from the dropdown, but you can't actually switch to "collection." See: https://www.hathitrust.org/accessibility Click the SEARCH button in the navbar, then try to select "collection" from the search bar dropdown. Can't do it!
The issue is that there was a long string of conditionals that resulted in the search bar never displaying "collection" or the collection filter dropdown menu on any page other than the homepage. This is because, on page load, we want to default to the search bar pre-selecting "website" as the search option. There is a click handler that is supposed to update the search bar when the dropdown has been clicked, but there is some circular logic that ultimately overrides that click handler logic.
The solution
I added a boolean to the click handler to signify whether the dropdown was clicked, then used that logic to tell the template what to update in the search bar. This allows the default/on-load search bar option to remain "website" but gives the conditional some new options in case someone has clicked the dropdown, essentially bailing out to a new template option if the "dropdownSelected" boolean is true.
I also did a little bit of cleanup. There were some red herring-type log messages in the console about "_searchtype" having a null value:
This ultimately had nothing to do with the actual bug, but it was easy enough to clean up with some conditionals.
Testing
Staged on dev-3: https://dev-3.www.hathitrust.org/about
There are probably a variety of states you could/should test:
/about), switch from "website" search to "collection" search, do a search, and make sure it takes you tolssearch results/about, do a website search ('collection' or 'member' usually has some results), then on the results page (/search/[search-terms]), switch to collection search and back to website search