Skip to content

Commit ecdef41

Browse files
Merge pull request #6 from xdev-software/initial-state-reset-button-not-disabled-fix
Bug Fix: Reset button still enabled after restoring the original state manually
2 parents 539c442 + fe4f39b commit ecdef41

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/FilterComponent.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import software.xdev.vaadin.model.FilterField;
8383
import software.xdev.vaadin.model.FilterFieldEnumExtension;
8484
import software.xdev.vaadin.model.SimpleFilterField;
85+
import software.xdev.vaadin.utl.FilterComponentUtl;
8586
import software.xdev.vaadin.utl.QueryParameterUtil;
8687

8788

@@ -519,8 +520,23 @@ private void deactivateDeleteButtonFromChipComponents(
519520
this.addQueryParameter(badge);
520521
}
521522

522-
// Activate the reset button
523-
this.btnResetFilter.setEnabled(true);
523+
// When no initial filter is existing
524+
if(this.initialChipBadges.isEmpty() && this.chipBadges.isEmpty())
525+
{
526+
this.btnResetFilter.setEnabled(false);
527+
}
528+
else
529+
{
530+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> initialChipBadgesCopy
531+
= new ArrayList<>(this.initialChipBadges);
532+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> chipBadgesCopy
533+
= new ArrayList<>(this.chipBadges);
534+
535+
// Check if just the initial filter are currently applied. Then enable/disable the reset button as
536+
// appropriate.
537+
this.btnResetFilter.setEnabled(
538+
!new FilterComponentUtl<T>().equalLists(initialChipBadgesCopy, chipBadgesCopy));
539+
}
524540
});
525541
}
526542
}
@@ -1293,7 +1309,7 @@ private String createMultipleQueryParameterString()
12931309
/**
12941310
* Method for adding a specific filter condition as query parameter.
12951311
*
1296-
* @param filterCondition The condition which should be converted to query parameter.
1312+
* @param chipBadge The condition which should be converted to query parameter.
12971313
*/
12981314
private void addQueryParameter(final ChipBadgeExtension<FilterCondition<T, ?>> chipBadge)
12991315
{
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.vaadin.utl;
17+
18+
import java.util.List;
19+
import java.util.stream.Collectors;
20+
21+
import software.xdev.vaadin.model.ChipBadge;
22+
import software.xdev.vaadin.model.ChipBadgeExtension;
23+
import software.xdev.vaadin.model.FilterCondition;
24+
25+
26+
public final class FilterComponentUtl<T>
27+
{
28+
public FilterComponentUtl()
29+
{
30+
}
31+
32+
/**
33+
* Check if the lists contains the same chip badges objects
34+
*
35+
* @param one List one
36+
* @param two List two
37+
* @return True if the lists contains the same objects
38+
*/
39+
public boolean equalLists(
40+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> one,
41+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> two)
42+
{
43+
return one.stream()
44+
.map(ChipBadge::getBadgeId)
45+
.collect(Collectors.toSet())
46+
.equals(two.stream()
47+
.map(ChipBadge::getBadgeId)
48+
.collect(Collectors.toSet()));
49+
}
50+
}

0 commit comments

Comments
 (0)