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

Add support for removable filters #44

Merged
merged 21 commits into from
Oct 27, 2021
Merged

Add support for removable filters #44

merged 21 commits into from
Oct 27, 2021

Conversation

yen-tt
Copy link
Contributor

@yen-tt yen-tt commented Oct 22, 2021

  • Update AppliedFilters to have a removable filters Applied static filters and facets will be removable and will trigger a new search when removed.
  • CSS styling for removable filters
  • Setup sample-app component jest test environment, and added appliedFilter component tests
  • update eslint to check for commas in interfaces/types/props

J=SLAP-1641
TEST=manual

spin up sample app, search 'virginia', and click on static filter and facet options. See that the applied filter labels have 'X' button. When click, see that the corresponding label is removed and the result is properly updated
see that new jest tests passed locally

- Update AppliedFilters to have a `removable` field. If true, applied static filters and facets will be removable and will trigger a new search when removed.
- CSS styling for removable filters
- TODO: add jest tests

J=SLAP-1641
TEST=manual

spin up sample app, search 'virginia', and click on static filter and facet options. See that when removable option is true, the applied filter labels have 'X' button. When click, see that the corresponding label is removed and the result is properly updated
@yen-tt yen-tt added the wip Work in progress label Oct 22, 2021
@coveralls
Copy link

coveralls commented Oct 22, 2021

Coverage Status

Coverage remained the same at 75.269% when pulling 887d6db on dev/removable-filters into 0c8a24f on main.

@yen-tt yen-tt removed the wip Work in progress label Oct 25, 2021
__mocks__/svgMock.tsx Outdated Show resolved Hide resolved

const onRemoveStaticFilterOption = () => {
document.getElementById(`${filter.filter.fieldId + "_" + filter.filter.value}`)?.click();
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make a state change that removes the filter, instead of manually clicking the checkbox

Copy link
Contributor Author

@yen-tt yen-tt Oct 26, 2021

Choose a reason for hiding this comment

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

StaticFilter component track its own state, which is different structure from statefulcore FilterState, then update statefulcore's filter state after restructuring it to the Filter|CombinedFilter format, which makes it a bit tricky. We could update answers-headless to have function(s) that traverse down CombinedFilter and remove that filter through a dispatch call, and update StaticFilter component to subscribe to FilterState.static changes. I briefly talked to Tom about this issue and I believe we decided to not make any changes in answers-headless. Is there a specific idea you are thinking of?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for now passing a callback down from the StaticFilters component would be a little cleaner? To put it bluntly I think the current StaticFilters component needs to be written. You currently cannot have multiple static filters on the page, and this is definitely not going to work with FilterSearch

Copy link
Contributor Author

@yen-tt yen-tt Oct 26, 2021

Choose a reason for hiding this comment

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

yeah, this is assuming we only support one StaticFilter since StaticFilter right now directly set statefulcore's FilterState to its own state managed in the component, so the click here would work. I will take a look into passing a callback of some sort

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: the option handling static filter selection uses this which requires some binding. I tried using the parent component VerticalSearchPage to get reference of StaticFilter or its handleOptionSelection function that bind this to the instance, and pass to AppliedFilter. Went through different approaches with createRef/useRef and setting callback function through props, nothing really works. We can try messing with setState in verticalSearchPage to manage changes between the two child components. But I think it might be best to wait till the refactor of the StaticFilter to utilize the filter action from answers-headless

Copy link
Member

Choose a reason for hiding this comment

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

this SGTM, and then we can update to use the new filter actions from answers-headless

sample-app/src/components/AppliedFilters.tsx Outdated Show resolved Hide resolved
@yen-tt yen-tt requested a review from oshi97 October 26, 2021 20:02
react-app.d.ts Show resolved Hide resolved
const { fieldId, matcher, value } = filter.filter;
if (isNearFilterValue(value)) {
throw Error('unrecognized value type for facet option.');
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it might be preferable to use console.error and returning rather than throw Error because throwing an Error can crash the application

Copy link
Member

Choose a reason for hiding this comment

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

Also, would a message such as 'A Filter with a NearFilterValue is not a supported RemovableFilter' be more accurate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that works too, I will update. I was thinking this would be more immediate in letting user know to resolve this problem, yeah that might not be ideal.

@yen-tt yen-tt requested a review from cea2aj October 26, 2021 21:25
react-app.d.ts Outdated Show resolved Hide resolved
Copy link
Member

@cea2aj cea2aj left a comment

Choose a reason for hiding this comment

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

I just have that nit on the comment, but otherwise LGTM

@yen-tt yen-tt merged commit 198a852 into main Oct 27, 2021
@yen-tt yen-tt deleted the dev/removable-filters branch October 27, 2021 12:23
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.

None yet

4 participants