From 06b80c8bd95be86ff96dc9a84c8db19e6d573879 Mon Sep 17 00:00:00 2001 From: "g.verdier" Date: Sun, 8 Sep 2024 11:15:23 -0400 Subject: [PATCH] Fix filter lost after changing page --- .../Components/QueryBuilder.razor | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/DotnetEventsViewer/Components/QueryBuilder.razor b/DotnetEventsViewer/Components/QueryBuilder.razor index c2207c8..ef44576 100644 --- a/DotnetEventsViewer/Components/QueryBuilder.razor +++ b/DotnetEventsViewer/Components/QueryBuilder.razor @@ -29,7 +29,7 @@ s.Name) .ToArray(); Query = State.Query!; @@ -158,10 +158,17 @@ _messageStore = new ValidationMessageStore(_editContext); } - private IEnumerable EnumerateDynamicFieldSelectors(Trace trace) + private IEnumerable EnumerateDynamicFieldSelectors(Trace trace, Filter[] filters) { return trace.EventMetadata - .SelectMany(m => m.FieldDefinitions.Select(d => Field.FromPayloadFieldDefinition(d, m))) + .SelectMany(m => m.FieldDefinitions.Select(d => + { + // FluentCombobox.SelectedOption is expected to exist in FluentCombobox.Items but if the field is + // created dynamically, the reference comparison will fail and the filter will be set to null when + // changing page. The hack here, is to reuse existing fields before creating a new instance. + var filter = filters.FirstOrDefault(x => x.Field.Name == d.Name); + return filter?.Field ?? Field.FromPayloadFieldDefinition(d, m); + })) .DistinctBy(s => s.Name); } @@ -188,7 +195,7 @@ .Where(m => m.EventName.Contains(e.Text, StringComparison.OrdinalIgnoreCase)); } - private IEnumerable GetFields(Filter forFilter) + private IEnumerable GetFields() { if (Query.EventKeys.Length == 0) {