Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display nested resources in the dashboard #6589

Merged
merged 4 commits into from
Nov 12, 2024
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: 10 additions & 1 deletion playground/Stress/Stress.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@

for (var i = 0; i < 10; i++)
{
builder.AddTestResource($"test-{i:0000}");
var name = $"test-{i:0000}";
var rb = builder.AddTestResource(name);
IResource parent = rb.Resource;

for (int j = 0; j < 3; j++)
{
name = name + $"-n{j}";
var nestedRb = builder.AddNestedResource(name, parent);
parent = nestedRb.Resource;
}
}

var serviceBuilder = builder.AddProject<Projects.Stress_ApiService>("stress-apiservice", launchProfileName: null);
Expand Down
3 changes: 2 additions & 1 deletion playground/Stress/Stress.AppHost/Stress.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\KnownResourceNames.cs" Link="KnownResourceNames.cs" />
<Compile Include="$(SharedDir)KnownResourceNames.cs" Link="KnownResourceNames.cs" />
<Compile Include="$(SharedDir)Model\KnownProperties.cs" Link="KnownProperties.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions playground/Stress/Stress.AppHost/TestResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using Aspire.Dashboard.Model;
using Aspire.Hosting.Lifecycle;
using Microsoft.Extensions.Logging;

Expand All @@ -25,6 +26,24 @@ public static IResourceBuilder<TestResource> AddTestResource(this IDistributedAp

return rb;
}

public static IResourceBuilder<TestNestedResource> AddNestedResource(this IDistributedApplicationBuilder builder, string name, IResource parent)
{
var rb = builder.AddResource(new TestNestedResource(name, parent))
.WithInitialState(new()
{
ResourceType = "Test Nested Resource",
State = "Starting",
Properties = [
new("P1", "P2"),
new(CustomResourceKnownProperties.Source, "Custom"),
new(KnownProperties.Resource.ParentName, parent.Name)
]
})
.ExcludeFromManifest();

return rb;
}
}

internal sealed class TestResourceLifecycleHook(ResourceNotificationService notificationService, ResourceLoggerService loggerService) : IDistributedApplicationLifecycleHook, IAsyncDisposable
Expand Down Expand Up @@ -81,3 +100,8 @@ sealed class TestResource(string name) : Resource(name)
{

}

sealed class TestNestedResource(string name, IResource parent) : Resource(name), IResourceWithParent
{
public IResource Parent { get; } = parent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
<FluentCheckbox Label="@ControlsStringsLoc[nameof(ControlsStrings.LabelAll)]"
ThreeState="true"
ShowIndeterminate="false"
onkeydown="e => console.log(e)"
ThreeStateOrderUncheckToIntermediate="true"
@bind-CheckState:get="@AreAllTypesVisible()"
@bind-CheckState:set="@OnAllResourceTypesCheckedChanged"
@bind-CheckState:set="@OnAllResourceTypesCheckedChangedAsync"
/>
@foreach (var (resourceType, _) in AllResourceTypes)
{
Expand All @@ -33,7 +32,7 @@
public required ConcurrentDictionary<string,bool> VisibleResourceTypes { get; set; }

[Parameter, EditorRequired]
public required Action<bool?> OnAllResourceTypesCheckedChanged { get; set; }
public required Func<bool?, Task> OnAllResourceTypesCheckedChangedAsync { get; set; }

[Parameter, EditorRequired]
public required Func<string, bool,Task> OnResourceTypeVisibilityChangedAsync { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
@PageTitleSection

<FluentToolbar Orientation="Orientation.Horizontal">
<FluentToolbar Class="main-toolbar" Orientation="Orientation.Horizontal">
@ToolbarSection
</FluentToolbar>
}
Expand Down
75 changes: 44 additions & 31 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<SelectResourceTypes AllResourceTypes="_allResourceTypes"
VisibleResourceTypes="_visibleResourceTypes"
OnAllResourceTypesCheckedChanged="@(b => AreAllTypesVisible = b)"
OnAllResourceTypesCheckedChangedAsync="@OnAllResourceTypesCheckedChangedAsync"
AreAllTypesVisible="@(() => AreAllTypesVisible)"
OnResourceTypeVisibilityChangedAsync="@OnResourceTypeVisibilityChangedAsync" />
</div>
Expand All @@ -58,12 +58,11 @@
<FluentPopover AnchorId="typeFilterButton" @bind-Open="_isTypeFilterVisible" AutoFocus="true" FixedPlacement="true">
<Header>@Loc[nameof(Dashboard.Resources.Resources.ResourcesResourceTypesHeader)]</Header>
<Body>
<SelectResourceTypes
AllResourceTypes="_allResourceTypes"
VisibleResourceTypes="_visibleResourceTypes"
OnAllResourceTypesCheckedChanged="@(b => AreAllTypesVisible = b)"
AreAllTypesVisible="@(() => AreAllTypesVisible)"
OnResourceTypeVisibilityChangedAsync="@OnResourceTypeVisibilityChangedAsync" />
<SelectResourceTypes AllResourceTypes="_allResourceTypes"
VisibleResourceTypes="_visibleResourceTypes"
OnAllResourceTypesCheckedChangedAsync="@OnAllResourceTypesCheckedChangedAsync"
AreAllTypesVisible="@(() => AreAllTypesVisible)"
OnResourceTypeVisibilityChangedAsync="@OnResourceTypeVisibilityChangedAsync" />
</Body>
</FluentPopover>

Expand All @@ -75,34 +74,48 @@
OnResize="@(r => _manager.SetWidthFraction(r.Orientation == Orientation.Horizontal ? r.Panel1Fraction : 1))">
<Summary>
<GridColumnManager @ref="_manager" Columns="@_gridColumns">
<FluentDataGrid ResizeLabel="@AspireFluentDataGridHeaderCell.GetResizeLabel(ControlsStringsLoc)"
<FluentDataGrid @ref="_dataGrid"
ResizeLabel="@AspireFluentDataGridHeaderCell.GetResizeLabel(ControlsStringsLoc)"
ResizeType="DataGridResizeType.Discrete"
Virtualize="true"
GenerateHeader="GenerateHeaderOption.Sticky"
ItemSize="46"
Items="@FilteredResources"
ItemsProvider="@GetData"
ResizableColumns="true"
GridTemplateColumns="@_manager.GetGridTemplateColumns()"
RowClass="GetRowClass"
RowClass="@(r => GetRowClass(r.Resource))"
Loading="_isLoading"
ShowHover="true"
TGridItem="ResourceViewModel"
ItemKey="@(r => r.Name)"
OnRowClick="@(r => r.ExecuteOnDefault(d => ShowResourceDetailsAsync(d, buttonId: null)))"
Class="enable-row-click">
TGridItem="ResourceGridViewModel"
ItemKey="@(r => r.Resource.Name)"
OnRowClick="@(r => r.ExecuteOnDefault(d => ShowResourceDetailsAsync(d.Resource, buttonId: null)))"
Class="main-grid enable-row-click">
<ChildContent>
<AspirePropertyColumn ColumnId="@TypeColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeColumnHeader)]" Property="@(c => c.ResourceType)" Sortable="true" Tooltip="true" TooltipText="@(c => c.ResourceType)" />
<AspireTemplateColumn ColumnId="@NameColumn" ColumnManager="@_manager" Title="@ControlsStringsLoc[nameof(ControlsStrings.NameColumnHeader)]" Sortable="true" SortBy="@_nameSort" Tooltip="true" TooltipText="@(c => GetResourceName(c))">
<ResourceNameDisplay Resource="context" FilterText="@_filter" FormatName="GetResourceName" />
<AspireTemplateColumn ColumnId="@NameColumn" ColumnManager="@_manager" Title="@ControlsStringsLoc[nameof(ControlsStrings.NameColumnHeader)]" Sortable="true" SortBy="@_nameSort" Tooltip="true" TooltipText="@(c => GetResourceName(c.Resource))" Class="expand-col">
@{
var indent = context.Depth * 16;
}
<span class="resources-name-container" style="margin-left: @(indent)px;">
<span @onclick:stopPropagation="true" class="main-grid-expand-container @(context.IsCollapsed ? "main-grid-collapsed" : "main-grid-expanded")">
@if (context.Children.Count > 0)
{
<FluentButton Appearance="Appearance.Lightweight" Class="main-grid-expand-button" OnClick="@(() => OnToggleCollapse(context))">
<FluentIcon Icon="Icons.Regular.Size12.ChevronRight" Color="Color.Neutral" />
</FluentButton>
}
</span>
<ResourceNameDisplay Resource="context.Resource" FilterText="@_filter" FormatName="GetResourceName" />
</span>
</AspireTemplateColumn>
<AspireTemplateColumn ColumnId="@StateColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesStateColumnHeader)]" Sortable="true" SortBy="@_stateSort" Tooltip="true" TooltipText="@(c => ResourceStateViewModel.GetResourceStateTooltip(c, ColumnsLoc))">
<StateColumnDisplay Resource="@context" UnviewedErrorCounts="@_applicationUnviewedErrorCounts" />
<AspireTemplateColumn ColumnId="@StateColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesStateColumnHeader)]" Sortable="true" SortBy="@_stateSort" Tooltip="true" TooltipText="@(c => ResourceStateViewModel.GetResourceStateTooltip(c.Resource, ColumnsLoc))">
<StateColumnDisplay Resource="@context.Resource" UnviewedErrorCounts="@_applicationUnviewedErrorCounts" />
</AspireTemplateColumn>
<AspireTemplateColumn ColumnId="@StartTimeColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesStartTimeColumnHeader)]" Sortable="true" SortBy="@_startTimeSort" TooltipText="@(context => context.CreationTimeStamp != null ? FormatHelpers.FormatDateTime(TimeProvider, context.CreationTimeStamp.Value, MillisecondsDisplay.None, CultureInfo.CurrentCulture) : null)" Tooltip="true">
<StartTimeColumnDisplay Resource="@context" />
<AspireTemplateColumn ColumnId="@StartTimeColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesStartTimeColumnHeader)]" Sortable="true" SortBy="@_startTimeSort" TooltipText="@(context => context.Resource.CreationTimeStamp != null ? FormatHelpers.FormatDateTime(TimeProvider, context.Resource.CreationTimeStamp.Value, MillisecondsDisplay.None, CultureInfo.CurrentCulture) : null)" Tooltip="true">
<StartTimeColumnDisplay Resource="@context.Resource" />
</AspireTemplateColumn>
<AspireTemplateColumn ColumnId="@SourceColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesSourceColumnHeader)]" Tooltip="true" TooltipText="@(ctx => GetSourceColumnValueAndTooltip(ctx)?.Tooltip)">
@if (GetSourceColumnValueAndTooltip(context) is { } columnDisplay)
<AspirePropertyColumn ColumnId="@TypeColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeColumnHeader)]" Property="@(c => c.Resource.ResourceType)" Sortable="true" SortBy="@_typeSort" IsDefaultSortColumn="true" Tooltip="true" TooltipText="@(c => c.Resource.ResourceType)" />
<AspireTemplateColumn ColumnId="@SourceColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesSourceColumnHeader)]" Tooltip="true" TooltipText="@(ctx => GetSourceColumnValueAndTooltip(ctx.Resource)?.Tooltip)">
@if (GetSourceColumnValueAndTooltip(context.Resource) is { } columnDisplay)
{
<SourceColumnDisplay FilterText="@_filter" Value="@columnDisplay.Value" ContentAfterValue="@columnDisplay.ContentAfterValue" ValueToCopy="@columnDisplay.ValueToCopy" Tooltip="@columnDisplay.Tooltip" />
}
Expand All @@ -111,17 +124,17 @@
<span class="empty-data"></span>
}
</AspireTemplateColumn>
<AspireTemplateColumn ColumnId="@EndpointsColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesEndpointsColumnHeader)]" Tooltip="true" TooltipText="@(ctx => GetEndpointsTooltip(ctx))">
<EndpointsColumnDisplay Resource="context"
HasMultipleReplicas="HasMultipleReplicas(context)"
DisplayedEndpoints="GetDisplayedEndpoints(context)" />
<AspireTemplateColumn ColumnId="@EndpointsColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesEndpointsColumnHeader)]" Tooltip="true" TooltipText="@(ctx => GetEndpointsTooltip(ctx.Resource))">
<EndpointsColumnDisplay Resource="context.Resource"
HasMultipleReplicas="HasMultipleReplicas(context.Resource)"
DisplayedEndpoints="GetDisplayedEndpoints(context.Resource)" />
</AspireTemplateColumn>
<AspireTemplateColumn ColumnId="@ActionsColumn" ColumnManager="@_manager" Title="@Loc[nameof(Dashboard.Resources.Resources.ResourcesActionsColumnHeader)]" Class="no-ellipsis">
<div class="grid-action-container" @onclick:stopPropagation="true">
<ResourceActions Commands="@context.Commands"
CommandSelected="async (command) => await ExecuteResourceCommandAsync(context, command)"
OnViewDetails="@((buttonId) => ShowResourceDetailsAsync(context, buttonId))"
Resource="context"
<ResourceActions Commands="@context.Resource.Commands"
CommandSelected="async (command) => await ExecuteResourceCommandAsync(context.Resource, command)"
OnViewDetails="@((buttonId) => ShowResourceDetailsAsync(context.Resource, buttonId))"
Resource="context.Resource"
GetResourceName="GetResourceName"
MaxHighlightedCount="_maxHighlightedCount" />
</div>
Expand Down
Loading
Loading