Skip to content

Commit 157fdd4

Browse files
authored
Add hidden to protocol, support in dashboard (#9069)
* Add hidden to protocol, support in dashboard * Obsolete Hidden state, rename to IsHidden * Also disable CS0618 in DistributedApplicationExtensions.cs
1 parent 95d0647 commit 157fdd4

File tree

20 files changed

+47
-18
lines changed

20 files changed

+47
-18
lines changed

playground/Stress/Stress.AppHost/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
}
2727
}
2828

29+
builder.AddParameter("testParameterResource", () => "value", secret: true);
30+
2931
// TODO: OTEL env var can be removed when OTEL libraries are updated to 1.9.0
3032
// See https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/RELEASENOTES.md#1100
3133
var serviceBuilder = builder.AddProject<Projects.Stress_ApiService>("stress-apiservice", launchProfileName: null)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ internal static ImmutableList<SelectViewModel<ResourceTypeDetails>> GetConsoleLo
393393
var builder = ImmutableList.CreateBuilder<SelectViewModel<ResourceTypeDetails>>();
394394

395395
foreach (var grouping in resourcesByName
396-
.Where(r => !r.Value.IsHiddenState())
396+
.Where(r => !r.Value.IsResourceHidden())
397397
.OrderBy(c => c.Value, ResourceViewModelNameComparer.Instance)
398398
.GroupBy(r => r.Value.DisplayName, StringComparers.ResourceName))
399399
{

src/Aspire.Dashboard/Components/Pages/Resources.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private bool Filter(ResourceViewModel resource)
118118
&& IsKeyValueTrue(resource.State ?? string.Empty, PageViewModel.ResourceStatesToVisibility)
119119
&& IsKeyValueTrue(resource.HealthStatus?.Humanize() ?? string.Empty, PageViewModel.ResourceHealthStatusesToVisibility)
120120
&& (_filter.Length == 0 || resource.MatchesFilter(_filter))
121-
&& !resource.IsHiddenState();
121+
&& !resource.IsResourceHidden();
122122

123123
static bool IsKeyValueTrue(string key, IDictionary<string, bool> dictionary) => dictionary.TryGetValue(key, out var value) && value;
124124
}
@@ -451,7 +451,7 @@ private void UpdateMenuButtons()
451451

452452
private bool HasCollapsedResources()
453453
{
454-
return _resourceByName.Any(r => !r.Value.IsHiddenState() && _collapsedResourceNames.Contains(r.Key));
454+
return _resourceByName.Any(r => !r.Value.IsResourceHidden() && _collapsedResourceNames.Contains(r.Key));
455455
}
456456

457457
private void UpdateMaxHighlightedCount()
@@ -619,7 +619,7 @@ private bool HasMultipleReplicas(ResourceViewModel resource)
619619
var count = 0;
620620
foreach (var (_, item) in _resourceByName)
621621
{
622-
if (item.IsHiddenState())
622+
if (item.IsResourceHidden())
623623
{
624624
continue;
625625
}
@@ -693,7 +693,7 @@ private async Task OnToggleCollapse(ResourceGridViewModel viewModel)
693693
private async Task OnToggleCollapseAll()
694694
{
695695
var resourcesWithChildren = _resourceByName.Values
696-
.Where(r => !r.IsHiddenState())
696+
.Where(r => !r.IsResourceHidden())
697697
.Where(r => _resourceByName.Values.Any(nested => nested.GetResourcePropertyValue(KnownProperties.Resource.ParentName) == r.Name))
698698
.ToList();
699699

src/Aspire.Dashboard/Extensions/ResourceViewModelExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ namespace Aspire.Dashboard.Extensions;
77

88
internal static class ResourceViewModelExtensions
99
{
10-
public static bool IsHiddenState(this ResourceViewModel resource)
11-
{
12-
return resource.KnownState is KnownResourceState.Hidden;
13-
}
14-
1510
public static bool IsRunningState(this ResourceViewModel resource)
1611
{
1712
return resource.KnownState is KnownResourceState.Running;

src/Aspire.Dashboard/Model/ResourceGraph/ResourceGraphMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static ResourceDto MapResource(ResourceViewModel r, IDictionary<string, R
2424
{
2525
var matches = resourcesByName.Values
2626
.Where(r => string.Equals(r.DisplayName, resourceRelationships.Key, StringComparisons.ResourceName))
27-
.Where(r => r.KnownState != KnownResourceState.Hidden)
27+
.Where(r => !r.IsResourceHidden())
2828
.ToList();
2929

3030
foreach (var match in matches)

src/Aspire.Dashboard/Model/ResourceViewModel.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Diagnostics.CodeAnalysis;
77
using System.Globalization;
88
using Aspire.Dashboard.Components.Controls;
9-
using Aspire.Dashboard.Extensions;
109
using Aspire.Dashboard.Utils;
1110
using Google.Protobuf.WellKnownTypes;
1211
using Humanizer;
@@ -39,6 +38,7 @@ public sealed class ResourceViewModel
3938
public required ImmutableArray<CommandViewModel> Commands { get; init; }
4039
/// <summary>The health status of the resource. <see langword="null"/> indicates that health status is expected but not yet available.</summary>
4140
public HealthStatus? HealthStatus { get; private set; }
41+
public bool IsHidden { private get; init; }
4242

4343
public required ImmutableArray<HealthReportViewModel> HealthReports
4444
{
@@ -79,6 +79,11 @@ internal bool MatchesFilter(string filter)
7979
return null;
8080
}
8181

82+
public bool IsResourceHidden()
83+
{
84+
return IsHidden || KnownState is KnownResourceState.Hidden;
85+
}
86+
8287
internal static HealthStatus? ComputeHealthStatus(ImmutableArray<HealthReportViewModel> healthReports, KnownResourceState? state)
8388
{
8489
if (state != KnownResourceState.Running)
@@ -100,7 +105,7 @@ public static string GetResourceName(ResourceViewModel resource, IDictionary<str
100105
var count = 0;
101106
foreach (var (_, item) in allResources)
102107
{
103-
if (item.IsHiddenState())
108+
if (item.IsResourceHidden())
104109
{
105110
continue;
106111
}

src/Aspire.Dashboard/ResourceService/Partials.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public ResourceViewModel ToViewModel(IKnownPropertyLookup knownPropertyLookup, I
4141
StateStyle = HasStateStyle ? StateStyle : null,
4242
Commands = GetCommands(),
4343
HealthReports = HealthReports.Select(ToHealthReportViewModel).OrderBy(vm => vm.Name).ToImmutableArray(),
44+
IsHidden = IsHidden
4445
};
4546
}
4647
catch (Exception ex)

src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ internal init
123123
/// </summary>
124124
public ImmutableArray<RelationshipSnapshot> Relationships { get; init; } = [];
125125

126+
/// <summary>
127+
/// Whether this resource should be hidden in UI.
128+
/// </summary>
129+
public bool IsHidden { get; init; }
130+
126131
internal static HealthStatus? ComputeHealthStatus(ImmutableArray<HealthReportSnapshot> healthReports, string? state)
127132
{
128133
if (state != KnownResourceStates.Running)
@@ -337,6 +342,7 @@ public static class KnownResourceStates
337342
/// <summary>
338343
/// The hidden state. Useful for hiding the resource.
339344
/// </summary>
345+
[Obsolete("Use CustomResourceSnapshot.Hidden instead.")]
340346
public static readonly string Hidden = nameof(Hidden);
341347

342348
/// <summary>

src/Aspire.Hosting/ConnectionStringBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public static IResourceBuilder<ConnectionStringResource> AddConnectionString(thi
4444
{
4545
ResourceType = "ConnectionString",
4646
// TODO: We'll hide this until we come up with a sane representation of these in the dashboard
47+
#pragma warning disable CS0618 // Type or member is obsolete
4748
State = KnownResourceStates.Hidden,
49+
#pragma warning restore CS0618 // Type or member is obsolete
4850
Properties = []
4951
});
5052
}

src/Aspire.Hosting/Dashboard/DashboardLifecycleHook.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ private void ConfigureAspireDashboardResource(IResource dashboardResource)
172172
},
173173
State = configuration.GetBool(KnownConfigNames.ShowDashboardResources, KnownConfigNames.Legacy.ShowDashboardResources) is true
174174
? null
175+
#pragma warning disable CS0618 // Type or member is obsolete
175176
: KnownResourceStates.Hidden
177+
#pragma warning restore CS0618 // Type or member is obsolete
176178
};
177179

178180
dashboardResource.Annotations.Add(new ResourceSnapshotAnnotation(snapshot));

0 commit comments

Comments
 (0)