diff --git a/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs b/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs index 601dea8472..110790bdbe 100644 --- a/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs +++ b/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs @@ -254,11 +254,9 @@ private ValueTask> GetData(GridIt .ToList(); // Paging visible resources. - var query = orderedResources.Skip(request.StartIndex); - if (request.Count != null) - { - query = query.Take(request.Count.Value); - } + var query = orderedResources + .Skip(request.StartIndex) + .Take(request.Count ?? DashboardUIHelpers.DefaultDataGridResultCount); return ValueTask.FromResult(GridItemsProviderResult.From(query.ToList(), orderedResources.Count)); } diff --git a/src/Aspire.Dashboard/Components/Pages/StructuredLogs.razor.cs b/src/Aspire.Dashboard/Components/Pages/StructuredLogs.razor.cs index 985342be68..9b767b2ea3 100644 --- a/src/Aspire.Dashboard/Components/Pages/StructuredLogs.razor.cs +++ b/src/Aspire.Dashboard/Components/Pages/StructuredLogs.razor.cs @@ -105,7 +105,7 @@ public partial class StructuredLogs : IPageWithSessionAndUrlState> GetData(GridItemsProviderRequest request) { ViewModel.StartIndex = request.StartIndex; - ViewModel.Count = request.Count; + ViewModel.Count = request.Count ?? DashboardUIHelpers.DefaultDataGridResultCount; var logs = ViewModel.GetLogs(); diff --git a/src/Aspire.Dashboard/Components/Pages/TraceDetail.razor.cs b/src/Aspire.Dashboard/Components/Pages/TraceDetail.razor.cs index 0508982bed..cc7a08efc9 100644 --- a/src/Aspire.Dashboard/Components/Pages/TraceDetail.razor.cs +++ b/src/Aspire.Dashboard/Components/Pages/TraceDetail.razor.cs @@ -84,10 +84,7 @@ private ValueTask> GetData(GridI { page = page.Skip(request.StartIndex); } - if (request.Count != null) - { - page = page.Take(request.Count.Value); - } + page = page.Take(request.Count ?? DashboardUIHelpers.DefaultDataGridResultCount); return ValueTask.FromResult(new GridItemsProviderResult { diff --git a/src/Aspire.Dashboard/Components/Pages/Traces.razor.cs b/src/Aspire.Dashboard/Components/Pages/Traces.razor.cs index d81f6a01f2..ce2e5d9882 100644 --- a/src/Aspire.Dashboard/Components/Pages/Traces.razor.cs +++ b/src/Aspire.Dashboard/Components/Pages/Traces.razor.cs @@ -110,7 +110,7 @@ private string GetSpansTooltip(OrderedApplication applicationSpans) private async ValueTask> GetData(GridItemsProviderRequest request) { TracesViewModel.StartIndex = request.StartIndex; - TracesViewModel.Count = request.Count; + TracesViewModel.Count = request.Count ?? DashboardUIHelpers.DefaultDataGridResultCount; var traces = TracesViewModel.GetTraces(); if (DashboardOptions.Value.TelemetryLimits.MaxTraceCount == traces.TotalItemCount && !TelemetryRepository.HasDisplayedMaxTraceLimitMessage) diff --git a/src/Aspire.Dashboard/Model/StructuredLogsViewModel.cs b/src/Aspire.Dashboard/Model/StructuredLogsViewModel.cs index 674f9bc626..7eaf5c8a78 100644 --- a/src/Aspire.Dashboard/Model/StructuredLogsViewModel.cs +++ b/src/Aspire.Dashboard/Model/StructuredLogsViewModel.cs @@ -16,7 +16,7 @@ public class StructuredLogsViewModel private ApplicationKey? _applicationKey; private string _filterText = string.Empty; private int _logsStartIndex; - private int? _logsCount; + private int _logsCount; private LogLevel? _logLevel; public StructuredLogsViewModel(TelemetryRepository telemetryRepository) @@ -60,7 +60,7 @@ public bool RemoveFilter(TelemetryFilter filter) } public int StartIndex { get => _logsStartIndex; set => SetValue(ref _logsStartIndex, value); } - public int? Count { get => _logsCount; set => SetValue(ref _logsCount, value); } + public int Count { get => _logsCount; set => SetValue(ref _logsCount, value); } public LogLevel? LogLevel { get => _logLevel; set => SetValue(ref _logLevel, value); } private void SetValue(ref T field, T value) diff --git a/src/Aspire.Dashboard/Model/TracesViewModel.cs b/src/Aspire.Dashboard/Model/TracesViewModel.cs index 2218797a66..b9b7f7eb8c 100644 --- a/src/Aspire.Dashboard/Model/TracesViewModel.cs +++ b/src/Aspire.Dashboard/Model/TracesViewModel.cs @@ -16,7 +16,7 @@ public class TracesViewModel private ApplicationKey? _applicationKey; private string _filterText = string.Empty; private int _startIndex; - private int? _count; + private int _count; public TracesViewModel(TelemetryRepository telemetryRepository) { @@ -26,7 +26,7 @@ public TracesViewModel(TelemetryRepository telemetryRepository) public ApplicationKey? ApplicationKey { get => _applicationKey; set => SetValue(ref _applicationKey, value); } public string FilterText { get => _filterText; set => SetValue(ref _filterText, value); } public int StartIndex { get => _startIndex; set => SetValue(ref _startIndex, value); } - public int? Count { get => _count; set => SetValue(ref _count, value); } + public int Count { get => _count; set => SetValue(ref _count, value); } public TimeSpan MaxDuration { get; private set; } public IReadOnlyList Filters => _filters; diff --git a/src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs b/src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs index 4d5c6cdb6b..90e465b993 100644 --- a/src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs +++ b/src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs @@ -392,18 +392,14 @@ public static string ConcatProperties(this KeyValuePair[] proper return sb.ToString(); } - public static PagedResult GetItems(IEnumerable results, int startIndex, int? count) + public static PagedResult GetItems(IEnumerable results, int startIndex, int count) { return GetItems(results, startIndex, count, null); } - public static PagedResult GetItems(IEnumerable results, int startIndex, int? count, Func? select) + public static PagedResult GetItems(IEnumerable results, int startIndex, int count, Func? select) { - var query = results.Skip(startIndex); - if (count != null) - { - query = query.Take(count.Value); - } + var query = results.Skip(startIndex).Take(count); List items; if (select != null) { diff --git a/src/Aspire.Dashboard/Otlp/Storage/GetLogsContext.cs b/src/Aspire.Dashboard/Otlp/Storage/GetLogsContext.cs index 4569719ca3..0174903b35 100644 --- a/src/Aspire.Dashboard/Otlp/Storage/GetLogsContext.cs +++ b/src/Aspire.Dashboard/Otlp/Storage/GetLogsContext.cs @@ -9,6 +9,6 @@ public sealed class GetLogsContext { public required ApplicationKey? ApplicationKey { get; init; } public required int StartIndex { get; init; } - public required int? Count { get; init; } + public required int Count { get; init; } public required List Filters { get; init; } } diff --git a/src/Aspire.Dashboard/Otlp/Storage/GetTracesRequest.cs b/src/Aspire.Dashboard/Otlp/Storage/GetTracesRequest.cs index 3151071f07..d08d969167 100644 --- a/src/Aspire.Dashboard/Otlp/Storage/GetTracesRequest.cs +++ b/src/Aspire.Dashboard/Otlp/Storage/GetTracesRequest.cs @@ -9,7 +9,7 @@ public sealed class GetTracesRequest { public required ApplicationKey? ApplicationKey { get; init; } public required int StartIndex { get; init; } - public required int? Count { get; init; } + public required int Count { get; init; } public required string FilterText { get; init; } public required List Filters { get; init; } } diff --git a/src/Aspire.Dashboard/Utils/DashboardUIHelpers.cs b/src/Aspire.Dashboard/Utils/DashboardUIHelpers.cs new file mode 100644 index 0000000000..0c8f1e1c86 --- /dev/null +++ b/src/Aspire.Dashboard/Utils/DashboardUIHelpers.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Aspire.Dashboard.Utils; + +internal static class DashboardUIHelpers +{ + // The initial data fetch for a FluentDataGrid doesn't include a count of items to return. + // The data grid doesn't specify a count because it doesn't know how many items fit in the UI. + // Once it knows the height of items and the height of the grid then it specifies the desired item count + // and then virtualization will fetch more data as needed. The problem with this is the initial fetch + // could fetch all available data when it doesn't need to. + // + // If there is no count then default to a limit to avoid getting all data. + // Given the size of rows on dashboard grids, 100 rows should always fill the grid on the screen. + public const int DefaultDataGridResultCount = 100; +}