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) {