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

Bug Fix: Reset button still enabled after restoring the original state manually #6

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import software.xdev.vaadin.model.FilterField;
import software.xdev.vaadin.model.FilterFieldEnumExtension;
import software.xdev.vaadin.model.SimpleFilterField;
import software.xdev.vaadin.utl.FilterComponentUtl;
import software.xdev.vaadin.utl.QueryParameterUtil;


Expand Down Expand Up @@ -515,8 +516,23 @@ private void deactivateDeleteButtonFromChipComponents(
this.addQueryParameter(badge);
}

// Activate the reset button
this.btnResetFilter.setEnabled(true);
// When no initial filter is existing
if(this.initialChipBadges.isEmpty() && this.chipBadges.isEmpty())
{
this.btnResetFilter.setEnabled(false);
}
else
{
final List<ChipBadgeExtension<FilterCondition<T, ?>>> initialChipBadgesCopy
= new ArrayList<>(this.initialChipBadges);
final List<ChipBadgeExtension<FilterCondition<T, ?>>> chipBadgesCopy
= new ArrayList<>(this.chipBadges);

// Check if just the initial filter are currently applied. Then enable/disable the reset button as
// appropriate.
this.btnResetFilter.setEnabled(
!new FilterComponentUtl<T>().equalLists(initialChipBadgesCopy, chipBadgesCopy));
JohannesRabauer marked this conversation as resolved.
Show resolved Hide resolved
}
});
}
}
Expand Down Expand Up @@ -1289,7 +1305,7 @@ private String createMultipleQueryParameterString()
/**
* Method for adding a specific filter condition as query parameter.
*
* @param filterCondition The condition which should be converted to query parameter.
* @param chipBadge The condition which should be converted to query parameter.
*/
private void addQueryParameter(final ChipBadgeExtension<FilterCondition<T, ?>> chipBadge)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright © 2024 XDEV Software (https://xdev.software)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package software.xdev.vaadin.utl;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import software.xdev.vaadin.model.ChipBadge;
import software.xdev.vaadin.model.ChipBadgeExtension;
import software.xdev.vaadin.model.FilterCondition;


public final class FilterComponentUtl<T>
{
public FilterComponentUtl()
{
}

/**
* Check if the lists contains the same chip badges objects
*
* @param one List one
* @param two List two
* @return True if the lists contains the same objects
*/
public boolean equalLists(
final List<ChipBadgeExtension<FilterCondition<T, ?>>> one,
final List<ChipBadgeExtension<FilterCondition<T, ?>>> two)
{
if(one == null && two == null)
{
return true;
}

if(one == null || two == null || one.size() != two.size())
{
return false;
}

// to avoid messing the order of the lists we will use a copy
final List<ChipBadgeExtension<FilterCondition<T, ?>>> oneCopy = new ArrayList<>(one);
final List<ChipBadgeExtension<FilterCondition<T, ?>>> twoCopy = new ArrayList<>(two);

oneCopy.sort(Comparator.comparing(ChipBadge::getBadgeId));
twoCopy.sort(Comparator.comparing(ChipBadge::getBadgeId));
return one.equals(two);
}
}