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

Improve page titles by adding (resource) or (trace name) where appropriate. #6970

Merged
merged 5 commits into from
Jan 28, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@namespace Aspire.Dashboard.Components

@_applicationName
@_pageTitle
22 changes: 17 additions & 5 deletions src/Aspire.Dashboard/Components/Controls/ApplicationName.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ public sealed partial class ApplicationName : ComponentBase, IDisposable
private CancellationTokenSource? _disposalCts;

[Parameter]
public string? ResourceName { get; init; }
public string? AdditionalText { get; set; }

[Parameter]
public IStringLocalizer? Loc { get; init; }
public string? ResourceName { get; set; }

[Parameter]
public IStringLocalizer? Loc { get; set; }

[Inject]
public required IDashboardClient DashboardClient { get; init; }

private string? _applicationName;
private string? _pageTitle;

protected override async Task OnInitializedAsync()
{
Expand All @@ -31,15 +34,24 @@ protected override async Task OnInitializedAsync()
_disposalCts = new CancellationTokenSource();
await DashboardClient.WhenConnected.WaitAsync(_disposalCts.Token);
}
}

protected override void OnParametersSet()
{
string applicationName;

if (ResourceName is not null && Loc is not null)
{
_applicationName = string.Format(CultureInfo.InvariantCulture, Loc[ResourceName], DashboardClient.ApplicationName);
applicationName = string.Format(CultureInfo.InvariantCulture, Loc[ResourceName], DashboardClient.ApplicationName);
}
else
{
_applicationName = DashboardClient.ApplicationName;
applicationName = DashboardClient.ApplicationName;
}

_pageTitle = string.IsNullOrEmpty(AdditionalText)
? applicationName
: $"{applicationName} ({AdditionalText})";
}

public void Dispose()
Expand Down
7 changes: 6 additions & 1 deletion src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
@using Aspire.Dashboard.Resources
@namespace Aspire.Dashboard.Components.Pages

<PageTitle><ApplicationName ResourceName="@nameof(Dashboard.Resources.ConsoleLogs.ConsoleLogsPageTitle)" Loc="@Loc" /></PageTitle>
<PageTitle>
<ApplicationName
AdditionalText="@PageViewModel.SelectedOption.Id?.ReplicaSetName"
ResourceName="@nameof(Dashboard.Resources.ConsoleLogs.ConsoleLogsPageTitle)"
Loc="@Loc"/>
</PageTitle>

<div class="page-content-container">
<AspirePageContentLayout AddNewlineOnToolbar="true"
Expand Down
21 changes: 20 additions & 1 deletion src/Aspire.Dashboard/Components/Pages/Metrics.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@
@inject IStringLocalizer<Dashboard.Resources.Metrics> Loc
@inject IStringLocalizer<ControlsStrings> ControlsStringsLoc

<PageTitle><ApplicationName ResourceName="@nameof(Dashboard.Resources.Metrics.MetricsPageTitle)" Loc="@Loc" /></PageTitle>
<PageTitle>
@{
string? additionalText;
if (PageViewModel.SelectedApplication.Id is { ReplicaSetName: { } replicaSetName })
{
additionalText = PageViewModel.SelectedInstrument is { } selectedInstrument
? $"{replicaSetName} - {selectedInstrument.Name}"
: replicaSetName;
}
else
{
additionalText = null;
}
}

<ApplicationName
AdditionalText="@additionalText"
ResourceName="@nameof(Dashboard.Resources.Metrics.MetricsPageTitle)"
Loc="@Loc"/>
</PageTitle>

<div class="page-content-container">
<AspirePageContentLayout
Expand Down
7 changes: 6 additions & 1 deletion src/Aspire.Dashboard/Components/Pages/StructuredLogs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
@inject IStringLocalizer<ControlsStrings> ControlsStringsLoc
@inject IStringLocalizer<StructuredFiltering> FilterLoc

<PageTitle><ApplicationName ResourceName="@nameof(Dashboard.Resources.StructuredLogs.StructuredLogsPageTitle)" Loc="@Loc" /></PageTitle>
<PageTitle>
<ApplicationName
AdditionalText="@PageViewModel.SelectedApplication.Id?.ReplicaSetName"
ResourceName="@nameof(Dashboard.Resources.StructuredLogs.StructuredLogsPageTitle)"
Loc="@Loc"/>
</PageTitle>

<div class="page-content-container">
<AspirePageContentLayout @ref="@_contentLayout"
Expand Down
14 changes: 8 additions & 6 deletions src/Aspire.Dashboard/Components/Pages/TraceDetail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
@inject IStringLocalizer<Dashboard.Resources.TraceDetail> Loc
@inject IStringLocalizer<ControlsStrings> ControlStringsLoc

<PageTitle><ApplicationName ResourceName="@nameof(Dashboard.Resources.TraceDetail.TraceDetailPageTitle)" Loc="@Loc" /></PageTitle>
<PageTitle>
<ApplicationName
AdditionalText="@GetPageTitle()"
ResourceName="@nameof(Dashboard.Resources.TraceDetail.TraceDetailPageTitle)"
Loc="@Loc"/>
</PageTitle>

<div class="page-content-container">
@if (_trace is { } trace)
Expand All @@ -19,14 +24,11 @@
MobileToolbarButtonText="@Loc[nameof(Dashboard.Resources.TraceDetail.TraceDetailMobileToolbarButtonText)]"
IsSummaryDetailsViewOpen="@(SelectedSpan is not null)">
<PageTitleSection>
@{
var headerSpan = trace.RootOrFirstSpan;
}
<div class="page-header">
<h1>
<span>@GetResourceName(headerSpan.Source): @headerSpan.Name</span>
<span>@GetPageTitle()</span>
<span class="trace-id">@OtlpHelpers.ToShortenedId(trace.TraceId)</span>
</h1>
</h1>
</div>
</PageTitleSection>
<ToolbarSection>
Expand Down
11 changes: 11 additions & 0 deletions src/Aspire.Dashboard/Components/Pages/TraceDetail.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ private ValueTask<GridItemsProviderResult<SpanWaterfallViewModel>> GetData(GridI
});
}

private string? GetPageTitle()
{
if (_trace is null)
{
return null;
}

var headerSpan = _trace.RootOrFirstSpan;
return $"{GetResourceName(headerSpan.Source)}: {headerSpan.Name}";
}

private static Icon GetSpanIcon(OtlpSpan span)
{
switch (span.Kind)
Expand Down
7 changes: 6 additions & 1 deletion src/Aspire.Dashboard/Components/Pages/Traces.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
@inject IStringLocalizer<ControlsStrings> ControlsStringsLoc
@implements IDisposable

<PageTitle><ApplicationName ResourceName="@nameof(Dashboard.Resources.Traces.TracesPageTitle)" Loc="@Loc" /></PageTitle>
<PageTitle>
<ApplicationName
AdditionalText="@PageViewModel.SelectedApplication.Id?.ReplicaSetName"
ResourceName="@nameof(Dashboard.Resources.Traces.TracesPageTitle)"
Loc="@Loc"/>
</PageTitle>

<div class="page-content-container">
<AspirePageContentLayout AddNewlineOnToolbar="true" @ref="@_contentLayout">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Bunit;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
Expand Down Expand Up @@ -32,6 +33,29 @@ public void Render_DashboardClientDisabled_Success()
cut.MarkupMatches("Aspire");
}

[Fact]
public void Render_With_Args()
{
// Arrange
Services.AddSingleton<IConfiguration>(new ConfigurationManager());
Services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
Services.AddSingleton<IDashboardClient, DashboardClient>();
Services.AddSingleton<IDashboardClientStatus, DashboardClientStatus>();
Services.AddSingleton<BrowserTimeProvider>();
Services.AddSingleton<IKnownPropertyLookup>(new MockKnownPropertyLookup());

// Act
var cut = RenderComponent<ApplicationName>(builder =>
{
builder.Add(p => p.ResourceName, "{0} traces");
builder.Add(p => p.Loc, new TestStringLocalizer<string>());
builder.Add(p => p.AdditionalText, "Hello World");
});

// Assert
cut.MarkupMatches("Localized:Aspire traces (Hello World)");
}

[Fact]
public void Render_DashboardClientEnabled_HtmlInName_Success()
{
Expand All @@ -57,4 +81,12 @@ private sealed class MockDashboardClient : IDashboardClient
public IAsyncEnumerable<IReadOnlyList<ResourceLogLine>> SubscribeConsoleLogs(string resourceName, CancellationToken cancellationToken) => throw new NotImplementedException();
public Task<ResourceViewModelSubscription> SubscribeResourcesAsync(CancellationToken cancellationToken) => throw new NotImplementedException();
}

private sealed class TestStringLocalizer<T> : IStringLocalizer<T>
{
public LocalizedString this[string name] => new LocalizedString(name, $"Localized:{name}");
public LocalizedString this[string name, params object[] arguments] => new LocalizedString(name, $"Localized:{name}:" + string.Join("+", arguments));

public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) => [];
}
}
Loading