- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Bug Fix: Mutliple filter components overwrite each others conditions when filtering the same grid #7
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
Conversation
… event is now fired, telling other filter components that they should add their filter back to the grid.
          
 | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some general problems from my side:
- I'm having some serious doubts if this change is needed in the first place. I think the use-case of needing multiple "filter components" for one Grid is extremely unlikely.
 - The current solution is not bound to the Grid that should be filter but instead to the UI, meaning that all "filter components" on the same UI are updated, which can result in unexpected behavior.
 - Self-registering an listener for communication between different components is not a good practice and breaks encapsulation. This will result in "works with magic"-behavior observed by users of the component.
 
| this.registration.remove(); | ||
| } | ||
| 
               | 
          ||
| private static class FilterComponentResetGridFilterEvent extends ComponentEvent<FilterComponent> | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type is missing, see sonar for more details
| this.removeQueryParameter(chip); | ||
| } | ||
| 
               | 
          ||
| private void updateGridFilter() | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method is called updateGridFilter but it just removes filters and throws a FilterComponentResetGridFilterEvent.
Should likely be called resetGridFilters or?
| final List<Predicate<T>> predicates = new ArrayList<>(); | ||
| 
               | 
          ||
| for(final ChipBadge<FilterCondition<T, ?>> chipBadge : chipBadges) | ||
| { | ||
| final FilterCondition<T, ?> item1 = chipBadge.getItem(); | ||
| final String inputValue = item1.getInputValue(); | ||
| 
               | 
          ||
| predicates.add( | ||
| item1.getSelectedCondition().compare( | ||
| item1.getItem().getValueProvider(), | ||
| inputValue) | ||
| ); | ||
| } | ||
| 
               | 
          ||
| return predicates.stream().map(p -> p.test(item)).reduce(Boolean::logicalAnd).orElseThrow(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can likely be written with Streaming API
| } | ||
| 
               | 
          ||
| // Needed for interacting with other filter components on the same ui | ||
| private Registration registration; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be protected so that it can be overriden
| 
           I think @AB-xdev has good points as to why we should not merge this change: #7 (review)  | 
    
…action-digest Update lycheeverse/lychee-action digest to 885c65f



Steps to reproduce:
Expected behavior: At step 4 the second condition should not overwrite the first one. The second condition should be combined with the first condition.