diff --git a/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs b/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs index 7a205d0b5b..6be2d7e417 100644 --- a/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs +++ b/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs @@ -21,17 +21,11 @@ public partial class Resources : ComponentBase, IDisposable [Inject] public required TelemetryRepository TelemetryRepository { get; init; } [Inject] - public required NavigationManager NavigationManager { get; set; } + public required NavigationManager NavigationManager { get; init; } private IEnumerable? SelectedEnvironmentVariables { get; set; } private ResourceViewModel? SelectedResource { get; set; } - private bool Filter(ResourceViewModel resource) - => _visibleResourceTypes.Contains(resource.ResourceType) && - (resource.Name.Contains(_filter, StringComparison.CurrentCultureIgnoreCase) || - (resource is ContainerViewModel containerViewModel && - containerViewModel.Image.Contains(_filter, StringComparison.CurrentCultureIgnoreCase))); - private readonly CancellationTokenSource _watchTaskCancellationTokenSource = new(); private readonly Dictionary _resourcesMap = []; // TODO populate resource types from server data @@ -45,6 +39,8 @@ public Resources() _visibleResourceTypes = new HashSet(_allResourceTypes, StringComparers.ResourceType); } + private bool Filter(ResourceViewModel resource) => _visibleResourceTypes.Contains(resource.ResourceType) && (_filter.Length == 0 || resource.MatchesFilter(_filter)); + protected void OnResourceTypeVisibilityChanged(string resourceType, bool isVisible) { if (isVisible) diff --git a/src/Aspire.Dashboard/Extensions/StringComparers.cs b/src/Aspire.Dashboard/Extensions/StringComparers.cs index 3c8cd0de89..806537cd64 100644 --- a/src/Aspire.Dashboard/Extensions/StringComparers.cs +++ b/src/Aspire.Dashboard/Extensions/StringComparers.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace Aspire.Dashboard.Extensions; @@ -6,4 +6,11 @@ namespace Aspire.Dashboard.Extensions; internal static class StringComparers { public static StringComparer ResourceType => StringComparer.Ordinal; + public static StringComparer UserTextSearch => StringComparer.CurrentCultureIgnoreCase; +} + +internal static class StringComparisons +{ + public static StringComparison ResourceType => StringComparison.Ordinal; + public static StringComparison UserTextSearch => StringComparison.CurrentCultureIgnoreCase; } diff --git a/src/Aspire.Dashboard/Model/ContainerViewModel.cs b/src/Aspire.Dashboard/Model/ContainerViewModel.cs index ae59b47eed..bc61fb8280 100644 --- a/src/Aspire.Dashboard/Model/ContainerViewModel.cs +++ b/src/Aspire.Dashboard/Model/ContainerViewModel.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Aspire.Dashboard.Extensions; + namespace Aspire.Dashboard.Model; public class ContainerViewModel : ResourceViewModel @@ -11,4 +13,9 @@ public class ContainerViewModel : ResourceViewModel public List Ports { get; } = new(); public string? Command { get; init; } public List? Args { get; init; } + + internal override bool MatchesFilter(string filter) + { + return base.MatchesFilter(filter) || Image.Contains(filter, StringComparisons.UserTextSearch); + } } diff --git a/src/Aspire.Dashboard/Model/ResourceViewModel.cs b/src/Aspire.Dashboard/Model/ResourceViewModel.cs index 4ce7c90cd3..795e2d5674 100644 --- a/src/Aspire.Dashboard/Model/ResourceViewModel.cs +++ b/src/Aspire.Dashboard/Model/ResourceViewModel.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Aspire.Dashboard.Extensions; + namespace Aspire.Dashboard.Model; public abstract class ResourceViewModel @@ -34,6 +36,11 @@ public static string GetResourceName(ResourceViewModel resource, IEnumerable