Add filter for recent receiver suggestions
Introduced a filter input box in `CreateEnvelopeWizardPopup.razor` to allow users to search recent receiver suggestions dynamically. Added `_receiverSuggestionFilterText` property and `OnReceiverSuggestionFilterChanged` method to handle filtering logic. Refactored `ReceiverSuggestionFilterHandler` to simplify its API. Updated the `Filter` method to accept a single query string and removed redundant overloads. Improved filtering logic to match `FullName` or `EmailAddress` using case-sensitive comparison. These changes enhance usability by enabling quick filtering of receiver suggestions.
This commit is contained in:
@@ -252,8 +252,14 @@
|
|||||||
}
|
}
|
||||||
else if (_currentStep == 1)
|
else if (_currentStep == 1)
|
||||||
{
|
{
|
||||||
<div class="sender-create-wizard__suggestions">
|
<div class="sender-create-wizard__suggestions">
|
||||||
<div class="sender-create-wizard__suggestions-title">@L("SenderWizard_RecentReceivers", "Zuletzt verwendete Empfänger")</div>
|
<div class="sender-create-wizard__suggestions-title">@L("SenderWizard_RecentReceivers", "Zuletzt verwendete Empfänger")</div>
|
||||||
|
|
||||||
|
<DxTextBox Text="@_receiverSuggestionFilterText"
|
||||||
|
TextChanged="OnReceiverSuggestionFilterChanged"
|
||||||
|
BindValueMode="BindValueMode.OnInput"
|
||||||
|
NullText='@L("SenderWizard_FilterRecentReceivers_Placeholder", "Empfänger in Vorschlägen filtern...")'
|
||||||
|
CssClass="w-100" />
|
||||||
|
|
||||||
@if (_isLoadingRecentSuggestions)
|
@if (_isLoadingRecentSuggestions)
|
||||||
{
|
{
|
||||||
@@ -512,6 +518,7 @@
|
|||||||
|
|
||||||
private string _receiverName = string.Empty;
|
private string _receiverName = string.Empty;
|
||||||
private string _receiverEmail = string.Empty;
|
private string _receiverEmail = string.Empty;
|
||||||
|
private string _receiverSuggestionFilterText = string.Empty;
|
||||||
private readonly List<CreateEnvelopeWizardReceiver> _receivers = [];
|
private readonly List<CreateEnvelopeWizardReceiver> _receivers = [];
|
||||||
private IEnumerable<string> _receiverTags = [];
|
private IEnumerable<string> _receiverTags = [];
|
||||||
private readonly List<RecentReceiverSuggestionDto> _recentReceiverSuggestions = [];
|
private readonly List<RecentReceiverSuggestionDto> _recentReceiverSuggestions = [];
|
||||||
@@ -611,6 +618,13 @@
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task OnReceiverSuggestionFilterChanged(string? value)
|
||||||
|
{
|
||||||
|
_receiverSuggestionFilterText = value ?? string.Empty;
|
||||||
|
_validationMessage = null;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
private Task OnEnvelopeTypeChanged(ChangeEventArgs args)
|
private Task OnEnvelopeTypeChanged(ChangeEventArgs args)
|
||||||
{
|
{
|
||||||
_validationMessage = null;
|
_validationMessage = null;
|
||||||
@@ -696,7 +710,10 @@
|
|||||||
return [];
|
return [];
|
||||||
|
|
||||||
var handler = new ReceiverSuggestionFilterHandler(_recentReceiverSuggestions);
|
var handler = new ReceiverSuggestionFilterHandler(_recentReceiverSuggestions);
|
||||||
var filtered = handler.Filter(_receiverName, _receiverEmail);
|
var filterText = _receiverSuggestionFilterText.Trim();
|
||||||
|
var filtered = string.IsNullOrWhiteSpace(filterText)
|
||||||
|
? _recentReceiverSuggestions
|
||||||
|
: handler.Filter(filterText);
|
||||||
|
|
||||||
return filtered
|
return filtered
|
||||||
.GroupBy(x => x.EmailAddress, StringComparer.OrdinalIgnoreCase)
|
.GroupBy(x => x.EmailAddress, StringComparer.OrdinalIgnoreCase)
|
||||||
@@ -1213,6 +1230,7 @@
|
|||||||
|
|
||||||
_receiverName = string.Empty;
|
_receiverName = string.Empty;
|
||||||
_receiverEmail = string.Empty;
|
_receiverEmail = string.Empty;
|
||||||
|
_receiverSuggestionFilterText = string.Empty;
|
||||||
_receivers.Clear();
|
_receivers.Clear();
|
||||||
_receiverTags = [];
|
_receiverTags = [];
|
||||||
_recentReceiverSuggestions.Clear();
|
_recentReceiverSuggestions.Clear();
|
||||||
|
|||||||
@@ -4,23 +4,19 @@ namespace EnvelopeGenerator.Server.Client.Components.Sender.ReceiverSuggestionFi
|
|||||||
|
|
||||||
public class ReceiverSuggestionFilterHandler(IEnumerable<RecentReceiverSuggestionDto> suggestions)
|
public class ReceiverSuggestionFilterHandler(IEnumerable<RecentReceiverSuggestionDto> suggestions)
|
||||||
{
|
{
|
||||||
private readonly IReadOnlyList<Entry> _entries = suggestions
|
private readonly IReadOnlyList<Entry> _entries = [.. suggestions
|
||||||
.Where(x => !string.IsNullOrWhiteSpace(x.FullName) && !string.IsNullOrWhiteSpace(x.EmailAddress))
|
.Where(x => !string.IsNullOrWhiteSpace(x.FullName) && !string.IsNullOrWhiteSpace(x.EmailAddress))
|
||||||
.Select(x => new Entry(new ReceiverFilterCriteria(x.FullName, x.EmailAddress), x))
|
.Select(x => new Entry(new ReceiverFilterCriteria(x.FullName, x.EmailAddress), x))];
|
||||||
.ToList();
|
|
||||||
|
|
||||||
private readonly record struct Entry(ReceiverFilterCriteria Criteria, RecentReceiverSuggestionDto Suggestion);
|
private readonly record struct Entry(ReceiverFilterCriteria Criteria, RecentReceiverSuggestionDto Suggestion);
|
||||||
|
|
||||||
public IEnumerable<RecentReceiverSuggestionDto> Filter(ReceiverFilterCriteria criteria)
|
public IEnumerable<RecentReceiverSuggestionDto> Filter(string query)
|
||||||
{
|
{
|
||||||
|
var normalizedQuery = new ReceiverFilterCriteria(query, query);
|
||||||
return _entries
|
return _entries
|
||||||
.Where(x => x.Criteria.Matches(criteria))
|
.Where(x =>
|
||||||
|
x.Criteria.FullName.Contains(normalizedQuery.FullName, StringComparison.Ordinal)
|
||||||
|
|| x.Criteria.EmailAddress.Contains(normalizedQuery.EmailAddress, StringComparison.Ordinal))
|
||||||
.Select(x => x.Suggestion);
|
.Select(x => x.Suggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<RecentReceiverSuggestionDto> Filter(string fullName, string emailAddress)
|
|
||||||
{
|
|
||||||
var criteria = new ReceiverFilterCriteria(fullName, emailAddress);
|
|
||||||
return Filter(criteria);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user