Skip to content

Add onSelect prop to FilterSearch - #323

Merged
nmanu1 merged 5 commits into
developfrom
dev/filtersearch-onSelect
Nov 11, 2022
Merged

nmanu1 merged 5 commits into
developfrom
dev/filtersearch-onSelect

Conversation

@nmanu1

@nmanu1 nmanu1 commented Nov 2, 2022 •

Copy link
Copy Markdown
Contributor

Add an onSelect prop to FilterSearch and deprecate searchOnSelect. If an onSelect function is passed in, the default selecting (and searching) logic is bypassed and we call the onSelect. If searchOnSelect=true is passed with an onSelect, we log a console warning that the former will be ignored. To allow for the UCSD use case mentioned in the spec, currentFilter was updated to allow any StaticFilter, not just a field value filter.

J=SLAP-2431
TEST=auto, manual

See that the added Jest tests pass. In the test-site, pass in an onSelect function that matches the current functionality with searchOnSelect as either true or false. Also, mimic a UCSD-like use case with compound filters and see that the component behaves correctly when selecting and un-selecting a filter. If both an onSelect and searchOnSelect=true are passed, see that a console warning is logged.

@coveralls

coveralls commented Nov 2, 2022 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.6%) to 84.853% when pulling a23dd1a on dev/filtersearch-onSelect into 1166991 on develop.

@github-actions

github-actions Bot commented Nov 2, 2022 •

Copy link
Copy Markdown
Contributor

Current unit coverage is 88.08250572956456%
Current visual coverage is 77.46781115879828%
Current combined coverage is 88.61726508785333%

@nmanu1
nmanu1 marked this pull request as ready for review November 2, 2022 14:39
@nmanu1
nmanu1 requested a review from a team as a code owner November 2, 2022 14:39
Comment thread src/components/FilterSearch.tsx Resolved
Comment thread src/components/FilterSearch.tsx Outdated
searchActions.setOffset(0);
searchActions.resetFacets();
executeSearch(searchActions);
if (onSelect && !searchOnSelect) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is getting a little messy, can we move to it's own function handleSelect and use gates like

if (!newFilter && !newDisplayName) {
  return;
}

if (!select) {
  return;
}

if (onSelect && !searchOnSelect) {
  onSelect(...)
} else {
  ...
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also think some refactoring here would be good since we're adding additional complexity in this PR!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did some refactoring to simplify things. Turns out, the handleToggleDropdown code was no longer needed because we're not doing special behavior when a user clicks out of filter search

Comment thread src/utils/filterutils.tsx Resolved
Comment thread src/components/FilterSearch.tsx Outdated
/** A function which is called when a filter is selected. To use this, searchOnSelect must be false. */
onSelect?: (
currentFilter: StaticFilter | undefined,
setCurrentFilter: (filter: StaticFilter) => void,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

are all of these params necessary?

@nmanu1 nmanu1 Nov 2, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, in order to be able to exactly replicate the current filter search behavior, a user would need access to all of these params.

they need to be able to unselect the currentFilter in State if they want, setCurrentFilter to some new filter, get the newFilter and newDisplayName that the user clicked, and use our special executeFilterSearch function that keeps the requests and responses synchronized and updates the filterSearchResponse accordingly

Comment thread src/components/FilterSearch.tsx Resolved
Comment thread src/components/FilterSearch.tsx Outdated
searchOnSelect?: boolean,
/** A function which is called when a filter is selected. To use this, searchOnSelect must be false. */
onSelect?: (
currentFilter: StaticFilter | undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So currentFilter was updated to allow any StaticFilter because the selected field value filter could transformed into a compound, conjunction filter for the UCSD case, is that correct?
I think it's confusing that the currently filter is of type StaticFilter and the newFilter is FieldValueStaticFilter. I would expect the current and new filter type to match.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's correct. I agree that it is a little odd that the types are different, but I thought it would be easier for the user to get a guarantee that newFilter will only ever be a field value filter (since that's what the filter search response returns). Otherwise, they would have to perform that checking themselves each time before they could access the fields

Comment thread src/components/FilterSearch.tsx Resolved
Comment thread src/components/FilterSearch.tsx Resolved
Comment thread src/components/FilterSearch.tsx Resolved
@nmanu1
nmanu1 requested a review from oshi97 November 11, 2022 18:50
@nmanu1
nmanu1 requested a review from a team November 11, 2022 20:35

@oshi97 oshi97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice!

@nmanu1
nmanu1 merged commit 893368d into develop Nov 11, 2022
@nmanu1
nmanu1 deleted the dev/filtersearch-onSelect branch November 11, 2022 21:14
@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.

6 participants