Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions playground/Stress/Stress.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
}
}

builder.AddParameter("testParameterResource", () => "value", secret: true);

// TODO: OTEL env var can be removed when OTEL libraries are updated to 1.9.0
// See https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/RELEASENOTES.md#1100
var serviceBuilder = builder.AddProject<Projects.Stress_ApiService>("stress-apiservice", launchProfileName: null)
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ internal static ImmutableList<SelectViewModel<ResourceTypeDetails>> GetConsoleLo
var builder = ImmutableList.CreateBuilder<SelectViewModel<ResourceTypeDetails>>();

foreach (var grouping in resourcesByName
.Where(r => !r.Value.IsHiddenState())
.Where(r => !r.Value.IsHidden())
.OrderBy(c => c.Value, ResourceViewModelNameComparer.Instance)
.GroupBy(r => r.Value.DisplayName, StringComparers.ResourceName))
{
Expand Down
8 changes: 4 additions & 4 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private bool Filter(ResourceViewModel resource)
&& IsKeyValueTrue(resource.State ?? string.Empty, PageViewModel.ResourceStatesToVisibility)
&& IsKeyValueTrue(resource.HealthStatus?.Humanize() ?? string.Empty, PageViewModel.ResourceHealthStatusesToVisibility)
&& (_filter.Length == 0 || resource.MatchesFilter(_filter))
&& !resource.IsHiddenState();
&& !resource.IsHidden();

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

private bool HasCollapsedResources()
{
return _resourceByName.Any(r => !r.Value.IsHiddenState() && _collapsedResourceNames.Contains(r.Key));
return _resourceByName.Any(r => !r.Value.IsHidden() && _collapsedResourceNames.Contains(r.Key));
}

private void UpdateMaxHighlightedCount()
Expand Down Expand Up @@ -619,7 +619,7 @@ private bool HasMultipleReplicas(ResourceViewModel resource)
var count = 0;
foreach (var (_, item) in _resourceByName)
{
if (item.IsHiddenState())
if (item.IsHidden())
{
continue;
}
Expand Down Expand Up @@ -693,7 +693,7 @@ private async Task OnToggleCollapse(ResourceGridViewModel viewModel)
private async Task OnToggleCollapseAll()
{
var resourcesWithChildren = _resourceByName.Values
.Where(r => !r.IsHiddenState())
.Where(r => !r.IsHidden())
.Where(r => _resourceByName.Values.Any(nested => nested.GetResourcePropertyValue(KnownProperties.Resource.ParentName) == r.Name))
.ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ namespace Aspire.Dashboard.Extensions;

internal static class ResourceViewModelExtensions
{
public static bool IsHiddenState(this ResourceViewModel resource)
{
return resource.KnownState is KnownResourceState.Hidden;
}

public static bool IsRunningState(this ResourceViewModel resource)
{
return resource.KnownState is KnownResourceState.Running;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static ResourceDto MapResource(ResourceViewModel r, IDictionary<string, R
{
var matches = resourcesByName.Values
.Where(r => string.Equals(r.DisplayName, resourceRelationships.Key, StringComparisons.ResourceName))
.Where(r => r.KnownState != KnownResourceState.Hidden)
.Where(r => !r.IsHidden())
.ToList();

foreach (var match in matches)
Expand Down
9 changes: 7 additions & 2 deletions src/Aspire.Dashboard/Model/ResourceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Aspire.Dashboard.Components.Controls;
using Aspire.Dashboard.Extensions;
using Aspire.Dashboard.Utils;
using Google.Protobuf.WellKnownTypes;
using Humanizer;
Expand Down Expand Up @@ -39,6 +38,7 @@ public sealed class ResourceViewModel
public required ImmutableArray<CommandViewModel> Commands { get; init; }
/// <summary>The health status of the resource. <see langword="null"/> indicates that health status is expected but not yet available.</summary>
public HealthStatus? HealthStatus { get; private set; }
public bool Hidden { private get; init; }

public required ImmutableArray<HealthReportViewModel> HealthReports
{
Expand Down Expand Up @@ -79,6 +79,11 @@ internal bool MatchesFilter(string filter)
return null;
}

public bool IsHidden()
{
return Hidden || KnownState is KnownResourceState.Hidden;
}

internal static HealthStatus? ComputeHealthStatus(ImmutableArray<HealthReportViewModel> healthReports, KnownResourceState? state)
{
if (state != KnownResourceState.Running)
Expand All @@ -100,7 +105,7 @@ public static string GetResourceName(ResourceViewModel resource, IDictionary<str
var count = 0;
foreach (var (_, item) in allResources)
{
if (item.IsHiddenState())
if (item.IsHidden())
{
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Dashboard/ResourceService/Partials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public ResourceViewModel ToViewModel(IKnownPropertyLookup knownPropertyLookup, I
StateStyle = HasStateStyle ? StateStyle : null,
Commands = GetCommands(),
HealthReports = HealthReports.Select(ToHealthReportViewModel).OrderBy(vm => vm.Name).ToImmutableArray(),
Hidden = Hidden
};
}
catch (Exception ex)
Expand Down
6 changes: 6 additions & 0 deletions src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ internal init
/// </summary>
public ImmutableArray<RelationshipSnapshot> Relationships { get; init; } = [];

/// <summary>
/// Whether this resource should be hidden in UI.
/// </summary>
public bool Hidden { get; init; }

internal static HealthStatus? ComputeHealthStatus(ImmutableArray<HealthReportSnapshot> healthReports, string? state)
{
if (state != KnownResourceStates.Running)
Expand Down Expand Up @@ -337,6 +342,7 @@ public static class KnownResourceStates
/// <summary>
/// The hidden state. Useful for hiding the resource.
/// </summary>
/// <remarks>This member is obsolete. Please set <see cref="CustomResourceSnapshot.Hidden"/> instead.</remarks>
public static readonly string Hidden = nameof(Hidden);

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Aspire.Hosting/Dashboard/DashboardServiceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ static GenericResourceSnapshot CreateResourceSnapshot(IResource resource, string
State = snapshot.State?.Text,
StateStyle = snapshot.State?.Style,
HealthReports = snapshot.HealthReports,
Commands = snapshot.Commands
Commands = snapshot.Commands,
Hidden = snapshot.Hidden,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting/Dashboard/ResourceSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal abstract class ResourceSnapshot
public required ImmutableArray<RelationshipSnapshot> Relationships { get; init; }
public required ImmutableArray<HealthReportSnapshot> HealthReports { get; init; }
public required ImmutableArray<ResourceCommandSnapshot> Commands { get; init; }
public required bool Hidden { get; init; }

protected abstract IEnumerable<(string Key, Value Value, bool IsSensitive)> GetProperties();

Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting/Dashboard/proto/Partials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static Resource FromSnapshot(ResourceSnapshot snapshot)
Uid = snapshot.Uid,
State = snapshot.State ?? "",
StateStyle = snapshot.StateStyle ?? "",
Hidden = snapshot.Hidden
};

if (snapshot.CreationTimeStamp.HasValue)
Expand Down
3 changes: 3 additions & 0 deletions src/Aspire.Hosting/Dashboard/proto/resource_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ message Resource {

// The list of relationships for this resource.
repeated ResourceRelationship relationships = 20;

// Whether the resource should be visually hidden in the dashboard.
bool hidden = 21;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is optional bool a thing @JamesNK? We need to distinguish false and not set.

if you have state “Hidden” and Hidden false what does it mean @adamint ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want a tri state bool.

IMO a resource is hidden if hidden property is true or the state is hidden (for backwards compatibility).

}

////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ private static ResourceViewModel CreateResource(string name, string type, string
Relationships = default,
Properties = ImmutableDictionary<string, ResourcePropertyViewModel>.Empty,
Commands = [],
Hidden = false,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ private static GenericResourceSnapshot CreateResourceSnapshot(string name)
Environment = [],
HealthReports = [],
Commands = [],
Relationships = []
Relationships = [],
Hidden = false
};
}

Expand Down
4 changes: 3 additions & 1 deletion tests/Shared/DashboardModel/ModelTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public static ResourceViewModel CreateResource(
HealthStatus? reportHealthStatus = null,
bool createNullHealthReport = false,
ImmutableArray<CommandViewModel>? commands = null,
ImmutableArray<RelationshipViewModel>? relationships = null)
ImmutableArray<RelationshipViewModel>? relationships = null,
bool hidden = false)
{
return new ResourceViewModel
{
Expand All @@ -42,6 +43,7 @@ public static ResourceViewModel CreateResource(
HealthReports = reportHealthStatus is null && !createNullHealthReport ? [] : [new HealthReportViewModel("healthcheck", reportHealthStatus, null, null)],
Commands = commands ?? [],
Relationships = relationships ?? [],
Hidden = hidden
};
}
}