Skip to content
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
11 changes: 0 additions & 11 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,6 @@ private List<DisplayedEndpoint> GetDisplayedEndpoints(ResourceViewModel resource

additionalMessage = null;

// Make sure that endpoints have a consistent ordering. Show https first, then everything else.
return [.. GetEndpoints(resource)
.OrderByDescending(e => e.Url?.StartsWith("https") == true)
.ThenBy(e=> e.Url ?? e.Text)];
}

/// <summary>
/// A resource has services and endpoints. These can overlap. This method attempts to return a single list without duplicates.
/// </summary>
private static List<DisplayedEndpoint> GetEndpoints(ResourceViewModel resource)
{
return ResourceEndpointHelpers.GetEndpoints(resource, includeInteralUrls: false);
}

Expand Down
13 changes: 12 additions & 1 deletion src/Aspire.Dashboard/Model/ResourceEndpointHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ public static List<DisplayedEndpoint> GetEndpoints(ResourceViewModel resource, b
}
}

return endpoints;
// Make sure that endpoints have a consistent ordering.
// Order:
// - https
// - other urls
// - endpoint name
var orderedEndpoints = endpoints
.OrderByDescending(e => e.Url?.StartsWith("https") == true)
.ThenByDescending(e => e.Url != null)
.ThenBy(e => e.Name, StringComparers.EndpointAnnotationName)
.ToList();

return orderedEndpoints;
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/Aspire.Dashboard.Tests/Model/ResourceEndpointHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@ public void GetEndpoints_IncludesIncludeInternalUrls()
});
}

[Fact]
public void GetEndpoints_OrderByName()
{
var endpoints = GetEndpoints(CreateResource([
new("a", new("http://localhost:8080"), isInternal: false),
new("C", new("http://localhost:8080"), isInternal: false),
new("D", new("tcp://localhost:8080"), isInternal: false),
new("B", new("tcp://localhost:8080"), isInternal: false),
new("Z", new("https://localhost:8080"), isInternal: false)
]));

Assert.Collection(endpoints,
e => Assert.Equal("Z", e.Name),
e => Assert.Equal("a", e.Name),
e => Assert.Equal("C", e.Name),
e => Assert.Equal("B", e.Name),
e => Assert.Equal("D", e.Name));
}

private static ResourceViewModel CreateResource(ImmutableArray<UrlViewModel> urls)
{
return new ResourceViewModel
Expand Down