Skip to content

Commit

Permalink
Updated FilterValue validation to support dynamic values
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Schick committed Apr 27, 2023
1 parent b435093 commit 1ca8b58
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/EventLogExpert/Shared/Components/FilterRow.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ public partial class FilterRow
{
[Parameter] public FilterModel Value { get; set; } = null!;

private static string? GetSubFilterComparisonString(SubFilterModel subFilter)
private void AddSubFilter() => Dispatcher.Dispatch(new FilterPaneAction.AddSubFilter(Value.Id));

private void EditFilter() => Value.IsEditing = true;

private string? GetSubFilterComparisonString(SubFilterModel subFilter)
{
if (subFilter.FilterValue is null || subFilter.FilterValue < 0)
if (!IsValidFilterValue(subFilter.FilterValue))
{
return null;
}
Expand All @@ -41,9 +45,21 @@ public partial class FilterRow
return stringBuilder.ToString();
}

private void AddSubFilter() => Dispatcher.Dispatch(new FilterPaneAction.AddSubFilter(Value.Id));
private bool IsValidFilterValue(dynamic value)
{
switch (Value.FilterType)
{
case FilterType.EventId :
case FilterType.Severity :
return value < 0 is false;
case FilterType.Provider :
case FilterType.Task :
case FilterType.Description :
return string.IsNullOrWhiteSpace(value) is false;
}

private void EditFilter() => Value.IsEditing = true;
return false;
}

private void RemoveFilter()
{
Expand Down Expand Up @@ -116,7 +132,7 @@ private void SetComparison(FilterModel? filterModel = null, SubFilterModel? subF

private bool SetComparisonString()
{
if (Value.FilterValue is null || Value.FilterValue < 0)
if (!IsValidFilterValue(Value.FilterValue))
{
Value.ComparisonString = null;
return false;
Expand Down

0 comments on commit 1ca8b58

Please sign in to comment.