Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default FilterSearch behavior #333

Merged
merged 4 commits into from
Nov 15, 2022
Merged

Conversation

nmanu1
Copy link
Contributor

@nmanu1 nmanu1 commented Nov 14, 2022

Update the default behavior of FilterSearch:

  • On select, clobber other static filters in State that have a fieldId that matches with one of the search fields for FilterSearch. If there are multiple filters that were clobbered, log a console warning.
  • If the static filters state is updated from outside of the component, log a console warning if there are multiple "matching" filters in State and there is no custom onSelect prop passed in.
    • And if there is no filter currently associated with the component, update the input text to the display name of the first "matching" filter that is selected in State.
      • If there are no matching filters in State, clear out the input and filter search response.

Note: We only look for field value filters in State for the "matching" filters. We don't prescribe how compound filters should be handled when comparing one to a search field. In the UCSD use case, a developer would pass in a custom onSelect function that would set compound static filters in State. In this case, the currentFilter may not be part of the matchingFilters array, which is why the concept of a currentFilter is still needed.

J=SLAP-2432
TEST=auto, manual

See that the added Jest tests pass. Spin up the test-site and test that the above situations match the expected behavior with different combinations of filters in State and passing an onSelect prop or not.

@coveralls
Copy link

coveralls commented Nov 14, 2022

Coverage Status

Coverage decreased (-0.5%) to 84.395% when pulling 7dc30ee on dev/update-default-filtersearch into 893368d on develop.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 14, 2022

Current unit coverage is 88.20861678004535%
Current visual coverage is 77.06131078224101%
Current combined coverage is 88.73771730914588%

@nmanu1 nmanu1 marked this pull request as ready for review November 14, 2022 22:29
@nmanu1 nmanu1 requested a review from a team as a code owner November 14, 2022 22:29
src/components/FilterSearch.tsx Outdated Show resolved Hide resolved
src/components/FilterSearch.tsx Outdated Show resolved Hide resolved
@@ -123,14 +128,33 @@ export function FilterSearch({
);

useEffect(() => {
if (matchingFilters.length > 1 && !onSelect) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like it may be beneficial to warn user regardless if onSelect is provided here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a deliberate decision because the thinking is that if you provide your own onSelect prop, you might be fine with having multiple filters selected in state at once and you wouldn't want this warning to to be logged. it's only assumed to be a problem for the default component behavior. people shouldn't have to fork the component just to remove this warning if they don't want clobbering behavior

@@ -123,14 +128,33 @@ export function FilterSearch({
);

useEffect(() => {
if (matchingFilters.length > 1 && !onSelect) {
console.warn('More than one selected static filter found that matches the filter search fields.'
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we add to the message that we will use the first selected static filter found?

Copy link
Contributor Author

@nmanu1 nmanu1 Nov 15, 2022

Choose a reason for hiding this comment

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

what do you think about adding "Picking one filter to display in the input." instead? because technically, it will only pick the first filter it finds if the currentFilter is not selected in state anymore. or does that seem too vague?

Edit: updated to "Picking one filter to display in the input." and I also added the specific search fields to make it more clear in case there are multiple filter search components on the page

@nmanu1
Copy link
Contributor Author

nmanu1 commented Nov 15, 2022

The failing WCAG and coverage checks are from PR #332. As mentioned there, an item has been made to address it.

@nmanu1 nmanu1 merged commit a2e8319 into develop Nov 15, 2022
@nmanu1 nmanu1 deleted the dev/update-default-filtersearch branch November 15, 2022 17:55
@tmeyer2115 tmeyer2115 mentioned this pull request Dec 15, 2022
tmeyer2115 added a commit that referenced this pull request Dec 15, 2022
### Features
- Default behavior of `FilterSearch` was changed to better support Locators and Doctor Finders. Additionally, a new `onSelect` prop was added to the Component. The `searchOnSelect` prop is now deprecated.  (#323, #343, #333)
- A new CSS bundle without the Tailwind resets is exported. (#322)
- We've added a `MapboxMap` Component, powered by v2 of their JavaScript API. (#332)

### Changes
- Assorted updates to improve our GH Actions. 
- Styling of Facet Headers is now exposed in `FilterGroupCssClasses`. (#321)

### Bug Fixes
- Vulnerabilities were addressed for the repo and its test-site. 
- Fixed the Dropdown Component to invoke `preventDefault` only when it is active. (#307)
- Corrected a small error in the generation of SSR Hydration IDs. (#315)
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.

4 participants