Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 6 additions & 1 deletion playground/TestShop/TestShop.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@
.WithExternalHttpEndpoints()
.WithReference(basketService)
.WithReference(catalogService)
.WithUrls(c => c.Urls.ForEach(u => u.DisplayText = $"Online store ({u.Endpoint?.EndpointName})"));
// Modify the display text of the URLs
.WithUrls(c => c.Urls.ForEach(u => u.DisplayText = $"Online store ({u.Endpoint?.EndpointName})"))
// Don't show the non-HTTPS link on the resources page (details only)
.WithUrlForEndpoint("http", url => url.ShowOnResourcesPage = false)
// Add health relative URL (show in details only)
.WithUrlForEndpoint("https", ep => new() { Url = "/health", DisplayText = "Health", ShowOnResourcesPage = false });

var _ = frontend.GetEndpoint("https").Exists ? frontend.WithHttpsHealthCheck("/health") : frontend.WithHttpHealthCheck("/health");

Expand Down
31 changes: 25 additions & 6 deletions src/Aspire.Dashboard/Components/Controls/ResourceDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,25 @@
ResizeType="DataGridResizeType.Discrete"
Style="width:100%"
RowSize="DataGridRowSize.Medium"
GridTemplateColumns="1fr 1.5fr"
GridTemplateColumns="1fr 1fr 0.5fr"
ShowHover="true">
<AspireTemplateColumn Sortable="true" SortBy="@_urlValueSort" Title="@ControlStringsLoc[nameof(ControlsStrings.LinkColumnHeader)]">
<GridValue ValueDescription="@ControlStringsLoc[nameof(ControlsStrings.LinkColumnHeader)]"
<AspireTemplateColumn Sortable="true" SortBy="@_urlValueSort" Title="@ControlStringsLoc[nameof(ControlsStrings.LinkAddressColumnHeader)]">
<GridValue ValueDescription="@ControlStringsLoc[nameof(ControlsStrings.LinkAddressColumnHeader)]"
Value="@context.OriginalUrlString"
ValueTemplate="@(_ => RenderUrlValue(context, _filter))"
EnableHighlighting="@(!string.IsNullOrEmpty(_filter))"
IsMaskedChanged="@(_ => OnValueMaskedChanged(context))"
HighlightText="@_filter" />
</AspireTemplateColumn>
<AspireTemplateColumn Sortable="true" SortBy="@(GridSort<DisplayedUrl>.ByAscending(i => i.DisplayName))" Title="@ControlStringsLoc[nameof(ControlsStrings.EndpointNameColumnHeader)]">
<AspireTemplateColumn Sortable="true" SortBy="@_urlValueSort" Title="@ControlStringsLoc[nameof(ControlsStrings.LinkTextColumnHeader)]">
<GridValue ValueDescription="@ControlStringsLoc[nameof(ControlsStrings.LinkTextColumnHeader)]"
Value="@context.Text"
ValueTemplate="@(_ => RenderTextValue(context, _filter))"
EnableHighlighting="@(!string.IsNullOrEmpty(_filter))"
IsMaskedChanged="@(_ => OnValueMaskedChanged(context))"
HighlightText="@_filter" />
</AspireTemplateColumn>
<AspireTemplateColumn Sortable="true" SortBy="@(GridSort<DisplayedUrl>.ByAscending(i => i.DisplayName))" Title="@ControlStringsLoc[nameof(ControlsStrings.EndpointNameColumnHeader)]">
<GridValue ValueDescription="@ControlStringsLoc[nameof(ControlsStrings.EndpointNameColumnHeader)]"
Value="@context.Name"
EnableHighlighting="@(!string.IsNullOrEmpty(_filter) && context.Name != "-")"
Expand Down Expand Up @@ -292,15 +300,26 @@
}
return @<span>@vm.Text</span>;
}
// If the URL and text are the same, render a link for the URL
else if (string.Equals(vm.Url, vm.Text, StringComparison.Ordinal))
// Otherwise, render a link for the URL
else
{
if (highlighting)
{
return @<a href="@vm.Url" target="_blank"><FluentHighlighter HighlightedText="@filter" Text="@vm.Url" /></a>;
}
return @<a href="@vm.Url" target="_blank">@vm.Url</a>;
}
}

private static RenderFragment RenderTextValue(DisplayedUrl vm, string filter)
{
var highlighting = !string.IsNullOrEmpty(filter) && vm.Text != "-";

// If there's no URL, e.g. this is a tcp:// URI, show nothing, or URL is same as Text, then show nothing
if (vm.Url is null || string.Equals(vm.Url, vm.Text, StringComparison.Ordinal))
{
return @<span></span>;
}
// Otherwise, render a link with the text as the anchor text & title as the URL
else
{
Expand Down
15 changes: 12 additions & 3 deletions src/Aspire.Dashboard/Resources/ControlsStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/Aspire.Dashboard/Resources/ControlsStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@
<data name="EndpointNameColumnHeader" xml:space="preserve">
<value>Endpoint name</value>
</data>
<data name="LinkColumnHeader" xml:space="preserve">
<value>Link</value>
<data name="LinkAddressColumnHeader" xml:space="preserve">
<value>Address</value>
</data>
<data name="ResourceGraphNoEndpoints" xml:space="preserve">
<value>No endpoints</value>
Expand All @@ -484,4 +484,7 @@
<data name="TotalItemsFooterCapturePaused" xml:space="preserve">
<value>Capture paused</value>
</data>
<data name="LinkTextColumnHeader" xml:space="preserve">
<value>Text</value>
</data>
</root>
11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/Aspire.Dashboard/Resources/xlf/ControlsStrings.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ public sealed record ResourceStateSnapshot(string Text, string? Style)
public sealed record EnvironmentVariableSnapshot(string Name, string? Value, bool IsFromSpec);

/// <summary>
/// A snapshot of the url.
/// A snapshot of the URL.
/// </summary>
/// <param name="Name">Name of the endpoint associated with the url.</param>
/// <param name="Url">The full uri.</param>
/// <param name="IsInternal">Determines if this url is internal.</param>
/// <param name="Name">Name of the endpoint associated with the URL.</param>
/// <param name="Url">The full URL.</param>
/// <param name="IsInternal">Determines if this URL is internal. Internal URLs are only shown in the details grid for a resource.</param>
[DebuggerDisplay("{Url}", Name = "{Name}")]
public sealed record UrlSnapshot(string? Name, string Url, bool IsInternal)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Aspire.Hosting/ApplicationModel/ResourceUrlAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,24 @@ public sealed class ResourceUrlAnnotation : IResourceAnnotation
/// The display order the URL. Higher values mean sort higher in the list.
/// </summary>
public int? DisplayOrder;

/// <summary>
/// Whether this URL should be shown on the dashboard resources page. Defaults to <see langword="true"/>.
/// </summary>
/// <remarks>
/// Set this to <see langword="false"/> to only show this URL in the resource details grid.
/// </remarks>
public bool ShowOnResourcesPage { get; set; } = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on the property name? This maps to the IsInternal property on the URL snapshot and resource server APIs but that name is pretty terrible so trying to make it more descriptive here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it an enum?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha I actually started that way, a flags enum.

Copy link
Member Author

@DamianEdwards DamianEdwards Apr 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not flags as the resource snapshots, dashboard, and resource server protocol currently only support the boolean state (IsInternal). So perhaps something like the following, although I admit I don't love it:

/// <summary>
/// Specifies where the URL should be displayed.
/// </summary>
public enum UrlDisplayLocation
{
    /// <summary>
    /// Show the URL in locations where either the resource summary or resource details are being displayed.
    /// </summary>
    SummaryAndDetails,
    /// <summary>
    /// Show the URL in locations where the full details of the resource are being displayed.
    /// </summary>
    DetailsOnly
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flags

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And modify the protocol?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe flags is wrong anyways because alll combinations aren’t valid so the above is fine?


internal ResourceUrlAnnotation WithEndpoint(EndpointReference endpoint)
{
return new()
{
Url = Url,
DisplayText = DisplayText,
Endpoint = endpoint,
DisplayOrder = DisplayOrder,
ShowOnResourcesPage = ShowOnResourcesPage
};
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to support the new overload of WithUrlForEndpoint that allows adding a new URL for an endpoint. The callback in that case has the user return the ResourceUrlAnnotation and then we call this method to ensure the correct endpoint is associated with it. The user could set it themselves in the callback as we pass them the EndpointReference, but this way ensures it's always correct. The Endpoint property is currently marked init and it didn't seem to me that anything else warranted changing it to set but I could be convinced otherwise.

}
Loading