Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default count to data grids to avoid getting all data #6664

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,9 @@ private ValueTask<GridItemsProviderResult<ResourceGridViewModel>> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public partial class StructuredLogs : IPageWithSessionAndUrlState<StructuredLogs
private async ValueTask<GridItemsProviderResult<OtlpLogEntry>> GetData(GridItemsProviderRequest<OtlpLogEntry> request)
{
ViewModel.StartIndex = request.StartIndex;
ViewModel.Count = request.Count;
ViewModel.Count = request.Count ?? DashboardUIHelpers.DefaultDataGridResultCount;

var logs = ViewModel.GetLogs();

Expand Down
5 changes: 1 addition & 4 deletions src/Aspire.Dashboard/Components/Pages/TraceDetail.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ private ValueTask<GridItemsProviderResult<SpanWaterfallViewModel>> 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<SpanWaterfallViewModel>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Pages/Traces.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private string GetSpansTooltip(OrderedApplication applicationSpans)
private async ValueTask<GridItemsProviderResult<OtlpTrace>> GetData(GridItemsProviderRequest<OtlpTrace> 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)
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Dashboard/Model/StructuredLogsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<T>(ref T field, T value)
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Dashboard/Model/TracesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<TelemetryFilter> Filters => _filters;

Expand Down
10 changes: 3 additions & 7 deletions src/Aspire.Dashboard/Otlp/Model/OtlpHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,14 @@ public static string ConcatProperties(this KeyValuePair<string, string>[] proper
return sb.ToString();
}

public static PagedResult<T> GetItems<T>(IEnumerable<T> results, int startIndex, int? count)
public static PagedResult<T> GetItems<T>(IEnumerable<T> results, int startIndex, int count)
{
return GetItems<T, T>(results, startIndex, count, null);
}

public static PagedResult<TResult> GetItems<TSource, TResult>(IEnumerable<TSource> results, int startIndex, int? count, Func<TSource, TResult>? select)
public static PagedResult<TResult> GetItems<TSource, TResult>(IEnumerable<TSource> results, int startIndex, int count, Func<TSource, TResult>? select)
{
var query = results.Skip(startIndex);
if (count != null)
{
query = query.Take(count.Value);
}
var query = results.Skip(startIndex).Take(count);
List<TResult> items;
if (select != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Otlp/Storage/GetLogsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TelemetryFilter> Filters { get; init; }
}
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Otlp/Storage/GetTracesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TelemetryFilter> Filters { get; init; }
}
17 changes: 17 additions & 0 deletions src/Aspire.Dashboard/Utils/DashboardUIHelpers.cs
Original file line number Diff line number Diff line change
@@ -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;
}