From 626b19367bb0a216c3435d6628583db6dab05015 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Mon, 11 Dec 2023 16:35:12 -0800 Subject: [PATCH] Show proxy URL for all executables For multiple replica, replica endpoint will be shown in bracket Resolves #1335 --- .../Components/Pages/Resources.razor | 2 +- .../Components/Pages/Resources.razor.cs | 18 ++++++++++++++++++ .../EndpointsColumnDisplay.razor | 13 ++++++++++++- .../Model/ResourceViewModel.cs | 4 +++- .../Dashboard/DashboardViewModelService.cs | 5 ++++- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Aspire.Dashboard/Components/Pages/Resources.razor b/src/Aspire.Dashboard/Components/Pages/Resources.razor index 9c05c75250..77d683736c 100644 --- a/src/Aspire.Dashboard/Components/Pages/Resources.razor +++ b/src/Aspire.Dashboard/Components/Pages/Resources.razor @@ -56,7 +56,7 @@ - + ResourceViewModel.GetResourceName(resource, _resourcesMap.Values); + private bool HasMultipleReplicas(ResourceViewModel resource) + { + var count = 0; + foreach (var item in _resourcesMap.Values) + { + if (item.DisplayName == resource.DisplayName) + { + count++; + if (count >= 2) + { + return true; + } + } + } + + return false; + } + protected virtual void Dispose(bool disposing) { if (disposing) diff --git a/src/Aspire.Dashboard/Components/ResourcesGridColumns/EndpointsColumnDisplay.razor b/src/Aspire.Dashboard/Components/ResourcesGridColumns/EndpointsColumnDisplay.razor index 5b22e17c7e..c47623d405 100644 --- a/src/Aspire.Dashboard/Components/ResourcesGridColumns/EndpointsColumnDisplay.razor +++ b/src/Aspire.Dashboard/Components/ResourcesGridColumns/EndpointsColumnDisplay.razor @@ -11,7 +11,15 @@ @* If we have any, regardless of the state, go ahead and display them *@ foreach (var endpoint in Resource.Endpoints.OrderBy(e => e)) { - @endpoint + if (HasMultipleReplicas) + { + @endpoint.ProxyUrl + (@endpoint.EndpointUrl) + } + else + { + @endpoint.ProxyUrl + } } @* If we're expecting more, say Starting..., unless the app isn't running anymore *@ if (Resource.State != FinishedState @@ -30,4 +38,7 @@ [Parameter, EditorRequired] public required ResourceViewModel Resource { get; set; } + + [Parameter, EditorRequired] + public required bool HasMultipleReplicas { get; set; } } diff --git a/src/Aspire.Dashboard/Model/ResourceViewModel.cs b/src/Aspire.Dashboard/Model/ResourceViewModel.cs index d447dfbca4..7d8b8190b5 100644 --- a/src/Aspire.Dashboard/Model/ResourceViewModel.cs +++ b/src/Aspire.Dashboard/Model/ResourceViewModel.cs @@ -13,7 +13,7 @@ public abstract class ResourceViewModel public DateTime? CreationTimeStamp { get; init; } public List Environment { get; } = new(); public required ILogSource LogSource { get; init; } - public List Endpoints { get; } = new(); + public List Endpoints { get; } = new(); public List Services { get; } = new(); public int? ExpectedEndpointsCount { get; init; } public abstract string ResourceType { get; } @@ -46,3 +46,5 @@ public sealed class ResourceService(string name, string? allocatedAddress, int? } public sealed record NamespacedName(string Name, string? Namespace); + +public sealed record EndpointViewModel(string EndpointUrl, string ProxyUrl); diff --git a/src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs b/src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs index 72f792d023..b38ff4e3c2 100644 --- a/src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs +++ b/src/Aspire.Hosting/Dashboard/DashboardViewModelService.cs @@ -405,6 +405,7 @@ private void FillEndpoints( if (matchingService?.UsesHttpProtocol(out var uriScheme) == true) { var endpointString = $"{uriScheme}://{endpoint.Spec.Address}:{endpoint.Spec.Port}"; + var proxyUrlString = $"{uriScheme}://{matchingService.AllocatedAddress}:{matchingService.AllocatedPort}"; // For project look into launch profile to append launch url if (resourceViewModel is ProjectViewModel projectViewModel @@ -416,6 +417,7 @@ private void FillEndpoints( { // This is relative URL endpointString += $"/{launchUrl}"; + proxyUrlString += $"/{launchUrl}"; } else { @@ -424,13 +426,14 @@ private void FillEndpoints( && launchUrl.StartsWith(applicationUrl)) { endpointString = launchUrl.Replace(applicationUrl, endpointString); + proxyUrlString = launchUrl; } } // If we cannot process launchUrl then we just show endpoint string } - resourceViewModel.Endpoints.Add(endpointString); + resourceViewModel.Endpoints.Add(new(endpointString, proxyUrlString)); } }