mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-08 08:34:25 +01:00
Search: Display text filters in search input (#5986)
* Search: Display text filters in search input This changes the search text input to also display the filters, which don't have a special UI (e.g. dropdown). Those filters (e.g. orderid) were not displayed before and hence could not be reset. Fixes #5984. * Add and fix test
This commit is contained in:
@@ -9,7 +9,8 @@ namespace BTCPayServer
|
||||
{
|
||||
private const char FilterSeparator = ',';
|
||||
private const char ValueSeparator = ':';
|
||||
|
||||
private static readonly string[] StripFilters = ["status", "exceptionstatus", "unusual", "includearchived", "appid", "startdate", "enddate"];
|
||||
|
||||
private readonly string _originalString;
|
||||
private readonly int _timezoneOffset;
|
||||
|
||||
@@ -27,12 +28,18 @@ namespace BTCPayServer
|
||||
.Where(kv => kv.Length == 2)
|
||||
.Select(kv => new KeyValuePair<string, string>(UnifyKey(kv[0]), kv[1]))
|
||||
.ToMultiValueDictionary(o => o.Key, o => o.Value);
|
||||
|
||||
var val = splitted.FirstOrDefault(a => a.IndexOf(ValueSeparator, StringComparison.OrdinalIgnoreCase) == -1);
|
||||
TextSearch = val != null ? val.Trim() : string.Empty;
|
||||
// combine raw search term and filters which don't have a special UI (e.g. orderid)
|
||||
var textFilters = Filters
|
||||
.Where(f => !StripFilters.Contains(f.Key))
|
||||
.Select(f => string.Join(FilterSeparator, f.Value.Select(v => $"{f.Key}{ValueSeparator}{v}"))).ToList();
|
||||
TextFilters = textFilters.Any() ? string.Join(FilterSeparator, textFilters) : null;
|
||||
TextSearch = splitted.FirstOrDefault(a => a.IndexOf(ValueSeparator, StringComparison.OrdinalIgnoreCase) == -1)?.Trim();
|
||||
}
|
||||
|
||||
public string TextSearch { get; private set; }
|
||||
public string TextFilters { get; private set; }
|
||||
|
||||
public string TextCombined => string.Join(FilterSeparator, new []{ TextFilters, TextSearch }.Where(x => !string.IsNullOrEmpty(x)));
|
||||
|
||||
public MultiValueDictionary<string, string> Filters { get; }
|
||||
|
||||
@@ -82,9 +89,10 @@ namespace BTCPayServer
|
||||
|
||||
public string WithoutSearchText()
|
||||
{
|
||||
return string.IsNullOrEmpty(TextSearch)
|
||||
? Finalize(ToString())
|
||||
: Finalize(ToString()).Replace(TextSearch, string.Empty);
|
||||
var txt = ToString();
|
||||
if (!string.IsNullOrEmpty(TextSearch)) txt = Finalize(txt.Replace(TextSearch, string.Empty));
|
||||
if (!string.IsNullOrEmpty(TextFilters)) txt = Finalize(txt.Replace(TextFilters, string.Empty));
|
||||
return Finalize(txt).Trim();
|
||||
}
|
||||
|
||||
public string[] GetFilterArray(string key)
|
||||
@@ -144,7 +152,7 @@ namespace BTCPayServer
|
||||
|
||||
private static string Finalize(string str)
|
||||
{
|
||||
var value = str.TrimStart(FilterSeparator).TrimEnd(FilterSeparator);
|
||||
var value = str.Trim().TrimStart(FilterSeparator).TrimEnd(FilterSeparator);
|
||||
return string.IsNullOrEmpty(value) ? " " : value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user