Skip to content

Conversation

@DamianEdwards
Copy link
Member

@DamianEdwards DamianEdwards commented Apr 11, 2025

Description

Bunch of changes to resource URL customization based on user feedback in 9.2:

  • Control whether URL is visible on resources page or not
  • Add helper method to get resource endpoint from ResourceUrlsCallbackContext
  • Support relative URLs for endpoints
  • Add overload of WithUrlForEndpoint for adding extra endpoint URLs

Fixes #8725, #8636, #8640, #8638, #6454

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
  • Does the change make any security assumptions or guarantees?
    • No
  • Does the change require an update in our Aspire docs?

Image shows the Frontend resource in TestShop only showing one URL in the Resources table but all URLs in the details view. The details view has been updated to show three columns so that the URL address, text, and endpoint are now clear.

image

Here's an example of the details view for a resource with a non-HTTP URL:

image

- Control whether URL is visible on resources page or not
- Add helper method to get resource endpoint from ResourceUrlsCallbackContext
- Support relative URLs for endpoints
- Add overload of WithUrlForEndpoint for adding extra endpoint URLs

Fixes #8725, #8636, #8640, #8638, #6454
/// <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?

Comment on lines 42 to 52
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.

Comment on lines +29 to +34
public EndpointReference? GetEndpoint(string name) =>
Resource switch
{
IResourceWithEndpoints resourceWithEndpoints => resourceWithEndpoints.GetEndpoint(name),
_ => null
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Makes it easy for callers of WithUrls to get an endpoint on the resource without needing to do type checking/casting to IResourceWithEndpoints.

Copy link
Member

Choose a reason for hiding this comment

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

Should it throw instead of returning null?

Copy link
Member

Choose a reason for hiding this comment

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

Throwing is a bit mean how do you avoid throwing?

Comment on lines +936 to +954
public static IResourceBuilder<T> WithUrlForEndpoint<T>(this IResourceBuilder<T> builder, string endpointName, Func<EndpointReference, ResourceUrlAnnotation> callback)
where T : IResourceWithEndpoints
{
builder.WithUrls(context =>
{
var endpoint = builder.GetEndpoint(endpointName);
if (endpoint.Exists)
{
var url = callback(endpoint).WithEndpoint(endpoint);
context.Urls.Add(url);
}
else
{
context.Logger.LogWarning("Could not execute callback to add an endpoint URL as no endpoint with name '{EndpointName}' could be found on resource '{ResourceName}'.", endpointName, builder.Resource.Name);
}
});

return builder;
}
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 new overload can be used to add a URL for an endpoint, whereas the existing overload is used to update the (first) URL for an endpoint.

@DamianEdwards DamianEdwards marked this pull request as ready for review April 11, 2025 23:13
@DamianEdwards DamianEdwards assigned JamesNK and unassigned JamesNK Apr 11, 2025
@davidfowl
Copy link
Member

cc @afscrome @paulomorgado

@mitchdenny
Copy link
Member

This looks good to me. Just one comment about throwing vs. returning null. Should we ever get into the situation where that resource is no IResourceWithEndpoints?

@DamianEdwards
Copy link
Member Author

@mitchdenny

This looks good to me. Just one comment about throwing vs. returning null. Should we ever get into the situation where that resource is no IResourceWithEndpoints?

Yes, because you can add URLs to any resource

@DamianEdwards DamianEdwards merged commit 3f9e7d2 into main Apr 12, 2025
174 checks passed
@DamianEdwards DamianEdwards deleted the damianedwards/WithUrlsImprovements branch April 12, 2025 04:57
@JamesNK
Copy link
Member

JamesNK commented Apr 12, 2025

Bugs:

  1. There should be - (dashes) in the grid when there are no values.
    image

  2. Clicking the details button for an empty text column shows the address. Instead, the details icon shouldn't be display.
    image

An example of no correctly displaying no value is Source column with resource like a database which has no source. It has a dash, it has no details icon on mouse over:
image

@JamesNK
Copy link
Member

JamesNK commented Apr 12, 2025

#8745

@akoeplinger
Copy link
Member

FYI this only closed the first issue:

Fixes #8725, #8636, #8640, #8638, #6454

@davidfowl
Copy link
Member

LLMs can’t parse the comma!?😅

@paulomorgado
Copy link
Contributor

Looks like I'm late to the party. 😄

When will this be available?

@JamesNK
Copy link
Member

JamesNK commented Apr 14, 2025

9.3

@paulomorgado
Copy link
Contributor

9.3

When will that be available? Any previews, in the meantime?

@davidfowl
Copy link
Member

There’s always daily builds https://github.com/dotnet/aspire/blob/main/docs/using-latest-daily.md

@paulomorgado
Copy link
Contributor

paulomorgado commented Apr 17, 2025

@DamianEdwards, does this also add the possibility for the display text for the URL to be only on the summary but not on the details?

The way I see it, on the summary view, the text should be the display name. On the details view, it should show the Link, the Display name and the Endpoint name.

The configuration of the endpoint should assume the Display name as the Endpoint name by default.

@DamianEdwards
Copy link
Member Author

@paulomorgado

The way I see it, on the summary view, the text should be the display name. On the details view, it should show the Link, the Display name and the Endpoint name.

That's what it does now.

@paulomorgado
Copy link
Contributor

@paulomorgado

The way I see it, on the summary view, the text should be the display name. On the details view, it should show the Link, the Display name and the Endpoint name.

That's what it does now.

"now" == 9.3.0 ?

@DamianEdwards
Copy link
Member Author

@paulomorgado yes

@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow independent control of URLs in dashboard and details

6 participants