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

Allow filtering by resource state and health status, and update the filters based on visible grid items #6925

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
45 changes: 45 additions & 0 deletions src/Aspire.Dashboard/Components/Controls/ResourceFilters.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@using System.Collections.Concurrent

@inject IStringLocalizer<Dashboard.Resources.Resources> Loc

<FluentStack Orientation="Orientation.Vertical" VerticalGap="15">
<div>
<h4>@Loc[nameof(Resources.Resources.ResourcesResourceTypesHeader)]</h4>
Copy link
Member

Choose a reason for hiding this comment

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

Titles feel too big. Make them h5.

<SelectResourceOptions
AllValues="AllResourceTypes"
OnAllResourceTypesCheckedChangedAsync="OnAllFilterVisibilityCheckedChangedAsync"
OnValueVisibilityChangedAsync="OnResourceFilterVisibilityChangedAsync"/>
</div>
<div>
<h4>@Loc[nameof(Resources.Resources.ResourcesResourceStatesHeader)]</h4>
<SelectResourceOptions
AllValues="AllResourceStates"
OnAllResourceTypesCheckedChangedAsync="OnAllFilterVisibilityCheckedChangedAsync"
OnValueVisibilityChangedAsync="OnResourceFilterVisibilityChangedAsync"/>
</div>
<div>
<h4>@Loc[nameof(Resources.Resources.ResourcesDetailsHealthStateProperty)]</h4>
<SelectResourceOptions
AllValues="AllResourceHealthStates"
OnAllResourceTypesCheckedChangedAsync="OnAllFilterVisibilityCheckedChangedAsync"
OnValueVisibilityChangedAsync="OnResourceFilterVisibilityChangedAsync"/>
</div>
</FluentStack>

@code {

[Parameter, EditorRequired]
public required ConcurrentDictionary<string, bool> AllResourceTypes { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public required ConcurrentDictionary<string, bool> AllResourceTypes { get; set; }
public required ConcurrentDictionary<string, bool> ResourceTypes { get; set; }

Same for the rest


[Parameter, EditorRequired]
public required ConcurrentDictionary<string, bool> AllResourceStates { get; set; }

[Parameter, EditorRequired]
public required ConcurrentDictionary<string, bool> AllResourceHealthStates { get; set; }

[Parameter, EditorRequired]
public required Func<Task> OnAllFilterVisibilityCheckedChangedAsync { get; set; }

[Parameter, EditorRequired]
public required Func<string, bool, Task> OnResourceFilterVisibilityChangedAsync { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@namespace Aspire.Dashboard.Components

@using System.Collections.Concurrent
@using Aspire.Dashboard.Resources

@inject IStringLocalizer<ControlsStrings> ControlsStringsLoc

@typeparam TValue where TValue : notnull

<FluentStack Orientation="Orientation.Vertical">
<FluentCheckbox Label="@ControlsStringsLoc[nameof(ControlsStrings.LabelAll)]"
ThreeState="true"
ShowIndeterminate="false"
ThreeStateOrderUncheckToIntermediate="true"
@bind-CheckState:get="@GetCheckState(AllValues)"
@bind-CheckState:set="@OnAllValuesCheckedChangedInternalAsync"
/>

@foreach (var (resourceType, isChecked) in AllValues.OrderBy(pair => pair.Key.ToString(), StringComparer.OrdinalIgnoreCase))
{
<FluentCheckbox Label="@(resourceType.ToString())"
@bind-Value:get="@isChecked"
@bind-Value:set="@(c => OnValueVisibilityChangedInternalAsync(resourceType, c))" />
}
</FluentStack>

@code {
[Parameter, EditorRequired]
public required ConcurrentDictionary<TValue, bool> AllValues { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public required ConcurrentDictionary<TValue, bool> AllValues { get; set; }
public required ConcurrentDictionary<TValue, bool> Values { get; set; }


[Parameter]
public EventCallback<bool?> AreAllVisibleChanged { get; set; }

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

[Parameter, EditorRequired]
public required Func<TValue, bool, Task> OnValueVisibilityChangedAsync { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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.Concurrent;

namespace Aspire.Dashboard.Components;

public partial class SelectResourceOptions<TValue>
{
private async Task OnAllValuesCheckedChangedInternalAsync(bool? newAreAllVisible)
{
SetCheckState(newAreAllVisible, AllValues);
await OnAllResourceTypesCheckedChangedAsync();
}
Comment on lines +10 to +14
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private async Task OnAllValuesCheckedChangedInternalAsync(bool? newAreAllVisible)
{
SetCheckState(newAreAllVisible, AllValues);
await OnAllResourceTypesCheckedChangedAsync();
}
private async Task OnAllValuesCheckedChangedInternalAsync(bool? newAreAllVisible)
{
SetCheckState(newAreAllVisible, Values);
await OnResourceTypesCheckedChangedAsync();
}

Don't need All in many of these names anymore (I think this suggestion is right). All should just be used when working with the all button now.


private async Task OnValueVisibilityChangedInternalAsync(TValue value, bool isVisible)
{
if (isVisible)
{
AllValues[value] = true;
}
else
{
AllValues[value] = false;
}
Comment on lines +18 to +25
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (isVisible)
{
AllValues[value] = true;
}
else
{
AllValues[value] = false;
}
AllValues[value] = isVisible;


await OnValueVisibilityChangedAsync(value, isVisible);
}

private static void SetCheckState(bool? newAreAllVisible, ConcurrentDictionary<TValue, bool> values)
{
if (newAreAllVisible is null)
{
return;
}

foreach (var key in values.Keys)
{
values[key] = newAreAllVisible.Value;
}
}

private static bool? GetCheckState(ConcurrentDictionary<TValue, bool> values)
{
if (values.IsEmpty)
{
return true;
}

var areAllChecked = true;
var areAllUnchecked = true;

foreach (var value in values.Values)
{
if (value)
{
areAllUnchecked = false;
}
else
{
areAllChecked = false;
}
}

return areAllChecked
? true
: areAllUnchecked
? false
: null;
Comment on lines +65 to +69
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 like nested ternary statements. Make at least one of these an if.

Copy link
Member

Choose a reason for hiding this comment

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

You can flatten them or use switch expressions 😄

}
}
39 changes: 0 additions & 39 deletions src/Aspire.Dashboard/Components/Controls/SelectResourceTypes.razor

This file was deleted.

42 changes: 22 additions & 20 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@using System.Globalization
@using Aspire.Dashboard.Components.Controls.Grid
@using Aspire.Dashboard.Model
@using Humanizer
@inject IStringLocalizer<Dashboard.Resources.Resources> Loc
@inject IStringLocalizer<ControlsStrings> ControlsStringsLoc
@inject IStringLocalizer<Columns> ColumnsLoc
Expand Down Expand Up @@ -33,36 +32,39 @@
<FluentDivider slot="end" Role="DividerRole.Presentation" Orientation="Orientation.Vertical" />
@if (ViewportInformation.IsDesktop)
{
<FluentButton id="typeFilterButton" slot="end"
Appearance="@(AreAllTypesVisible is true ? Appearance.Stealth : Appearance.Accent)"
<FluentButton id="resourceFilterButton" slot="end"
Appearance="@(AreAllVisibleInAnyFilter ? Appearance.Stealth : Appearance.Accent)"
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem to work anymore.

IconEnd="@(new Icons.Regular.Size20.Filter())"
@onclick="() => _isTypeFilterVisible = !_isTypeFilterVisible"
Title="@(AreAllTypesVisible is true ? Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeFilterAllVisible)] : Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeFiltered)])"
aria-label="@(AreAllTypesVisible is true ? Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeFilterAllVisible)] : Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeFiltered)])" />
@onclick="() => _isFilterPopupVisible = !_isFilterPopupVisible"
Title="@(AreAllVisibleInAnyFilter ? Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeFilterAllVisible)] : Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeFiltered)])"
aria-label="@(AreAllVisibleInAnyFilter ? Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeFilterAllVisible)] : Loc[nameof(Dashboard.Resources.Resources.ResourcesTypeFiltered)])"></FluentButton>
Comment on lines +39 to +40
Copy link
Member

Choose a reason for hiding this comment

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

The resource text doesn't make sense anymore. It should be made generic to "has filters" vs "no filters"

}
else
{
<div>
<h5>@Loc[nameof(Dashboard.Resources.Resources.ResourcesResourceTypesHeader)]</h5>

<SelectResourceTypes AllResourceTypes="_allResourceTypes"
VisibleResourceTypes="_visibleResourceTypes"
OnAllResourceTypesCheckedChangedAsync="@OnAllResourceTypesCheckedChangedAsync"
AreAllTypesVisible="@(() => AreAllTypesVisible)"
OnResourceTypeVisibilityChangedAsync="@OnResourceTypeVisibilityChangedAsync" />
<ResourceFilters
AllResourceStates="@_resourceStatesToVisibility"
AllResourceTypes="@_resourceTypesToVisibility"
AllResourceHealthStates="@_resourceHealthStatusesToVisibility"
OnAllFilterVisibilityCheckedChangedAsync="@OnAllFilterVisibilityCheckedChangedAsync"
OnResourceFilterVisibilityChangedAsync="@OnResourceFilterVisibilityChangedAsync" />
</div>
}
</ToolbarSection>

<MainSection>
<FluentPopover AnchorId="typeFilterButton" @bind-Open="_isTypeFilterVisible" AutoFocus="true" FixedPlacement="true">
<Header>@Loc[nameof(Dashboard.Resources.Resources.ResourcesResourceTypesHeader)]</Header>
<FluentPopover AnchorId="resourceFilterButton"
@bind-Open="_isFilterPopupVisible"
AutoFocus="true"
FixedPlacement="true"
Class="resources-popup">
<Body>
<SelectResourceTypes AllResourceTypes="_allResourceTypes"
VisibleResourceTypes="_visibleResourceTypes"
OnAllResourceTypesCheckedChangedAsync="@OnAllResourceTypesCheckedChangedAsync"
AreAllTypesVisible="@(() => AreAllTypesVisible)"
OnResourceTypeVisibilityChangedAsync="@OnResourceTypeVisibilityChangedAsync" />
<ResourceFilters
AllResourceStates="@_resourceStatesToVisibility"
AllResourceTypes="@_resourceTypesToVisibility"
AllResourceHealthStates="@_resourceHealthStatusesToVisibility"
OnAllFilterVisibilityCheckedChangedAsync="@OnAllFilterVisibilityCheckedChangedAsync"
OnResourceFilterVisibilityChangedAsync="@OnResourceFilterVisibilityChangedAsync" />
</Body>
</FluentPopover>

Expand Down
Loading
Loading