diff --git a/src/Aspire.Dashboard/Components/Pages/Resources.razor b/src/Aspire.Dashboard/Components/Pages/Resources.razor index b66ac73bc1..dd6c06cc99 100644 --- a/src/Aspire.Dashboard/Components/Pages/Resources.razor +++ b/src/Aspire.Dashboard/Components/Pages/Resources.razor @@ -9,21 +9,28 @@

Resources

+ Title="@(AreAllTypesVisible is true ? "Type Filter: All Types Visible" : "Type Filter: Filtered")" + aria-label="@(AreAllTypesVisible is true ? "Type Filter: All Types Visible" : "Type Filter: Filtered")" />
Resource Types
- - - - + + @foreach (string resourceType in _allResourceTypes) { + bool isChecked = _visibleResourceTypes.Contains(resourceType); + + }
diff --git a/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs b/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs index 011e45ab91..7a205d0b5b 100644 --- a/src/Aspire.Dashboard/Components/Pages/Resources.razor.cs +++ b/src/Aspire.Dashboard/Components/Pages/Resources.razor.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 System.Collections.Immutable; +using Aspire.Dashboard.Extensions; using Aspire.Dashboard.Model; using Aspire.Dashboard.Otlp.Model; using Aspire.Dashboard.Otlp.Storage; @@ -25,45 +27,56 @@ public partial class Resources : ComponentBase, IDisposable private ResourceViewModel? SelectedResource { get; set; } private bool Filter(ResourceViewModel resource) - => ((resource.ResourceType == "Project" && _areProjectsVisible) || - (resource.ResourceType == "Container" && _areContainersVisible) || - (resource.ResourceType == "Executable" && _areExecutablesVisible)) && + => _visibleResourceTypes.Contains(resource.ResourceType) && (resource.Name.Contains(_filter, StringComparison.CurrentCultureIgnoreCase) || (resource is ContainerViewModel containerViewModel && containerViewModel.Image.Contains(_filter, StringComparison.CurrentCultureIgnoreCase))); - private readonly Dictionary _resourcesMap = new(); private readonly CancellationTokenSource _watchTaskCancellationTokenSource = new(); + private readonly Dictionary _resourcesMap = []; + // TODO populate resource types from server data + private readonly ImmutableArray _allResourceTypes = ["Project", "Executable", "Container"]; + private readonly HashSet _visibleResourceTypes; private string _filter = ""; private bool _isTypeFilterVisible; - private bool? _allTypesVisible = true; - private bool _areProjectsVisible = true; - private bool _areContainersVisible = true; - private bool _areExecutablesVisible = true; - private bool AreAllTypesVisible => _areProjectsVisible && _areContainersVisible && _areExecutablesVisible; + public Resources() + { + _visibleResourceTypes = new HashSet(_allResourceTypes, StringComparers.ResourceType); + } - private void HandleTypeFilterShowAllChanged(bool? newValue) + protected void OnResourceTypeVisibilityChanged(string resourceType, bool isVisible) { - if (newValue.HasValue) + if (isVisible) + { + _visibleResourceTypes.Add(resourceType); + } + else { - _allTypesVisible = _areProjectsVisible = _areContainersVisible = _areExecutablesVisible = newValue.Value; + _visibleResourceTypes.Remove(resourceType); } } - private void HandleTypeFilterTypeChanged() + private bool? AreAllTypesVisible { - if (_areProjectsVisible && _areContainersVisible && _areExecutablesVisible) - { - _allTypesVisible = true; - } - else if (!_areProjectsVisible && !_areContainersVisible && !_areExecutablesVisible) + get { - _allTypesVisible = false; + return _visibleResourceTypes.SetEquals(_allResourceTypes) + ? true + : _visibleResourceTypes.Count == 0 + ? false + : null; } - else + set { - _allTypesVisible = null; + if (value is true) + { + _visibleResourceTypes.UnionWith(_allResourceTypes); + } + else if (value is false) + { + _visibleResourceTypes.Clear(); + } } } diff --git a/src/Aspire.Dashboard/Extensions/StringComparers.cs b/src/Aspire.Dashboard/Extensions/StringComparers.cs new file mode 100644 index 0000000000..3c8cd0de89 --- /dev/null +++ b/src/Aspire.Dashboard/Extensions/StringComparers.cs @@ -0,0 +1,9 @@ +// 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; + +internal static class StringComparers +{ + public static StringComparer ResourceType => StringComparer.Ordinal; +}