Skip to content

Conversation

adamint
Copy link
Member

@adamint adamint commented Apr 1, 2025

Description

When there is a single replica, uses the display name of the resource. If there are multiple replicas and a display name is provided as the resource name, no resource is selected.

Also disables the resource select control while resources are loading.

Fixes #8328

Checklist

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

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the console logs to use a resource’s friendly (display) name when there is a single replica and disables the resource select control while resources are loading.

  • Introduces an additional branch in TrackResourceSnapshotsAsync to select a resource by display name if there’s a single matching replica.
  • Refactors the resource selection logic by adding a new helper method GetSelectedOption and updates resource select component parameter nullability and event callbacks.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs Adds friendly name selection logic and refactors how the selected option is set.
src/Aspire.Dashboard/Components/Controls/ResourceSelect.razor.cs Updates nullability for parameters and simplifies the event callback logic.
src/Aspire.Dashboard/Components/Controls/ResourceSelect.razor Disables the resource select control when resources are loading.
Comments suppressed due to low confidence (2)

src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs:249

  • Using SingleOrDefault here may throw an exception if multiple matching resources exist. Consider checking if there is exactly one match before selecting, to align with the intended behavior described in the PR.
return _resources.SingleOrDefault(

src/Aspire.Dashboard/Components/Controls/ResourceSelect.razor.cs:41

  • [nitpick] Consider renaming 'ValuedChanged' to 'ValueChanged' for improved clarity.
private static void ValuedChanged(string? value)

@JamesNK
Copy link
Member

JamesNK commented Apr 1, 2025

Note: This change is for 9.3, not 9.2. This page is a bug magnet and we don't want to make large changes at the last minute.

@JamesNK
Copy link
Member

JamesNK commented Apr 2, 2025

Going to the console page via resources still has the full name:

image

image

Double check all the places the console page URL builder method is used and update them to pass the right value.

@adamint adamint requested a review from JamesNK April 3, 2025 20:11
private SelectViewModel<ResourceTypeDetails> GetSelectedOption()
{
Debug.Assert(_resources is not null);
return _resources.SingleOrDefault(
Copy link
Member

Choose a reason for hiding this comment

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

Can ApplicationsSelectHelpers.GetApplication be used here? That is what other pages with a selector (structured logs, traces, metrics) use to match the name to a select view model.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I don't know how I didn't find this.

Comment on lines 722 to 737
private bool TryGetResourceByName(string resourceName, [NotNullWhen(true)] out ResourceViewModel? resource)
{
if (_resourceByName.TryGetValue(resourceName, out resource))
{
return true;
}

var resourcesWithDisplayName = _resourceByName.Values.Where(r => string.Equals(resourceName, r.DisplayName, StringComparisons.ResourceName)).ToList();
if (resourcesWithDisplayName.Count == 1)
{
resource = resourcesWithDisplayName.Single();
return true;
}

return false;
}
Copy link
Member

@JamesNK JamesNK Apr 10, 2025

Choose a reason for hiding this comment

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

Could you move this to be a helper method on ResourceViewModel. That way other people doing the same thing can reuse this logic.

adamint added 2 commits April 14, 2025 11:25
…ith-single-replica

# Conflicts:
#	src/Aspire.Dashboard/Components/Controls/ResourceActions.razor.cs
#	src/Aspire.Dashboard/Components/Controls/ResourceDetails.razor
@adamint adamint merged commit dbd0026 into dotnet:main Apr 14, 2025
174 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 15, 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.

Refreshing console log page after restart results in blank page
2 participants