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

feat: only allow one filter open at a time, easy closing #3084

Open
wants to merge 46 commits into
base: main
Choose a base branch
from

Conversation

mcmcgrath13
Copy link
Collaborator

@mcmcgrath13 mcmcgrath13 commented Dec 23, 2024

PULL REQUEST

Summary

Move control of filter open state from local component to overall component. This allows us to make sure only one component is open at a time and for escape and click handlers to be added to close out filters more easily.

Related Issue

Fixes #2995

Acceptance Criteria

  • Given an open filter box, it should close if a user clicks anywhere outside of the box
  • Given an open filter box, it should close if the user hits the esc key
  • Only one filter box should open at a time.
    - For example, if the user clicks on condition, the condition box will open. Then, if they clicked on the date filter button, the condition box would automatically close and the filter by date box would open.
    - If a filter box is open and the reset button is clicked, then the filter box should close automatically.
  • Unit tests have been added

angelathe and others added 30 commits December 13, 2024 14:39
* refactor: moar abstraction

* tiny nits, update tests

* fix test

---------

Co-authored-by: angelathe <[email protected]>
Co-authored-by: Mary McGrath <[email protected]>
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.41%. Comparing base (a9d82ef) to head (f535b28).

Files with missing lines Patch % Lines
...ntainers/ecr-viewer/src/app/components/Filters.tsx 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3084      +/-   ##
==========================================
+ Coverage   86.75%   88.41%   +1.66%     
==========================================
  Files         217       80     -137     
  Lines       13527     4126    -9401     
  Branches      690      696       +6     
==========================================
- Hits        11735     3648    -8087     
+ Misses       1770      456    -1314     
  Partials       22       22              
Flag Coverage Δ
ecr-viewer 89.85% <97.14%> (+0.07%) ⬆️
fhir-converter ?
ingestion ?
message-parser ?
message-refiner ?
orchestration 85.67% <ø> (ø)
record-linkage ?
trigger-code-reference ?
validation ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...iners/ecr-viewer/src/app/components/BaseFilter.tsx 90.32% <100.00%> (+2.08%) ⬆️
...ntainers/ecr-viewer/src/app/components/Filters.tsx 93.61% <94.73%> (+0.28%) ⬆️

... and 137 files with indirect coverage changes

Base automatically changed from angela/2752-filter-by-date-p1 to main December 23, 2024 19:05
@angelathe
Copy link
Collaborator

angelathe commented Dec 23, 2024

Quick thing I noticed when testing locally: filters should reset to their previous state if we change it but then don't apply & open a different filter. Ex. If I change something in filter A and then switch over to filter B before applying A, filter A doesn't visually reset until opening/closing A again Ignore this, didn't pull the latest from the branch


// When a filter is open, close it if the escape key is hit or a click happens
// outside the <Filter /> component (implemented by stopping click propogation on <Filter />)
React.useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tiny nit, but can we remove the React. here for consistency? We already import and use useEffect for other consts in this file

if (filterBoxOpen) {
window.addEventListener("keydown", handleEscapeFilters);
window.addEventListener("click", resetFilters);
return () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this cleanup only happen if filterBoxOpen === null?

Also, totally cool, I'd never seen useEffect cleanup functions be used before 🙌

@@ -133,7 +153,7 @@ export const Filter = ({
onSubmit={(e) => {
e.preventDefault();
submitHandler();
setIsFilterBoxOpen(false);
setFilterBoxOpen("__submitted__");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we want it to set filterBoxOpen to "__submitted__"? It's slightly unclear how filterBoxOpen gets used when it can equal either filter type or "__submitted__"

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.

Update UI for closing filter boxes in eCR Library
2 participants