-
Notifications
You must be signed in to change notification settings - Fork 525
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
62de9e2
bd9bbbc
42132a6
451fa5a
21abd03
ec3d504
f5589cf
dcdf0dd
c04043e
c8aa3f2
d2c6443
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||||
@using System.Collections.Concurrent | ||||||
@using Aspire.Dashboard.Model | ||||||
@using Humanizer | ||||||
|
||||||
@inject IStringLocalizer<Dashboard.Resources.Resources> Loc | ||||||
|
||||||
<FluentStack Orientation="Orientation.Vertical" VerticalGap="15"> | ||||||
<div> | ||||||
<h4>@Loc[nameof(Resources.Resources.ResourcesResourceTypesHeader)]</h4> | ||||||
<SelectResourceOptions | ||||||
Resources="AllResources" | ||||||
ResourceContainsValue="@((r, type) => StringComparers.ResourceType.Equals(r.ResourceType, type))" | ||||||
AllValues="AllResourceTypes" | ||||||
VisibleValues="VisibleResourceTypes" | ||||||
JamesNK marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
OnAllResourceTypesCheckedChangedAsync="OnAllFilterVisibilityCheckedChangedAsync" | ||||||
@bind-AreAllVisible="AreAllTypesVisible" | ||||||
OnValueVisibilityChangedAsync="OnResourceFilterVisibilityChangedAsync"/> | ||||||
</div> | ||||||
<div> | ||||||
<h4>@Loc[nameof(Resources.Resources.ResourcesResourceStatesHeader)]</h4> | ||||||
<SelectResourceOptions | ||||||
Resources="AllResources" | ||||||
ResourceContainsValue="@((r, state) => StringComparers.ResourceState.Equals(Pages.Resources.GetStateOrDefaultText(r.State, Loc), state))" | ||||||
AllValues="AllResourceStates" | ||||||
VisibleValues="VisibleResourceStates" | ||||||
OnAllResourceTypesCheckedChangedAsync="OnAllFilterVisibilityCheckedChangedAsync" | ||||||
@bind-AreAllVisible="AreAllStatesVisible" | ||||||
OnValueVisibilityChangedAsync="OnResourceFilterVisibilityChangedAsync"/> | ||||||
</div> | ||||||
<div> | ||||||
<h4>@Loc[nameof(Resources.Resources.ResourcesDetailsHealthStateProperty)]</h4> | ||||||
<SelectResourceOptions | ||||||
Resources="AllResources" | ||||||
ResourceContainsValue="@((r, healthStatus) => StringComparer.Ordinal.Equals(Pages.Resources.GetStateOrDefaultText(r.HealthStatus?.Humanize(), Loc), healthStatus))" | ||||||
AllValues="AllResourceHealthStates" | ||||||
VisibleValues="VisibleResourceHealthStates" | ||||||
OnAllResourceTypesCheckedChangedAsync="OnAllFilterVisibilityCheckedChangedAsync" | ||||||
@bind-AreAllVisible="AreAllHealthStatesVisible" | ||||||
OnValueVisibilityChangedAsync="OnResourceFilterVisibilityChangedAsync"/> | ||||||
</div> | ||||||
</FluentStack> | ||||||
|
||||||
@code { | ||||||
[Parameter, EditorRequired] | ||||||
public required IEnumerable<ResourceViewModel> AllResources { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required ConcurrentDictionary<string, bool> AllResourceTypes { get; set; } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same for the rest |
||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required ConcurrentDictionary<string, bool> VisibleResourceTypes { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required ConcurrentDictionary<string, bool> AllResourceStates { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required ConcurrentDictionary<string, bool> VisibleResourceStates { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required ConcurrentDictionary<string, bool> AllResourceHealthStates { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required ConcurrentDictionary<string, bool> VisibleResourceHealthStates { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required Func<Task> OnAllFilterVisibilityCheckedChangedAsync { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required Func<string, bool, Task> OnResourceFilterVisibilityChangedAsync { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required bool? AreAllTypesVisible { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required bool? AreAllStatesVisible { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required bool? AreAllHealthStatesVisible { get; set; } | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||||
@namespace Aspire.Dashboard.Components | ||||||
|
||||||
@using System.Collections.Concurrent | ||||||
@using Aspire.Dashboard.Model | ||||||
@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="@AreAllVisible" | ||||||
@bind-CheckState:set="@OnAllValuesCheckedChangedInternalAsync" | ||||||
/> | ||||||
|
||||||
@foreach (var (resourceType, _) in AllValues | ||||||
.Where(pair => Resources.Any(resource => ResourceContainsValue(resource, pair.Key))) | ||||||
adamint marked this conversation as resolved.
Show resolved
Hide resolved
adamint marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
.OrderBy(pair => pair.Key.ToString(), StringComparer.OrdinalIgnoreCase)) | ||||||
{ | ||||||
var isChecked = VisibleValues.ContainsKey(resourceType); | ||||||
<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; } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required bool? AreAllVisible { get; set; } | ||||||
|
||||||
[Parameter] | ||||||
public EventCallback<bool?> AreAllVisibleChanged { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required ConcurrentDictionary<TValue, bool> VisibleValues { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required Func<Task> OnAllResourceTypesCheckedChangedAsync { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required Func<TValue, bool, Task> OnValueVisibilityChangedAsync { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required IEnumerable<ResourceViewModel> Resources { get; set; } | ||||||
|
||||||
[Parameter, EditorRequired] | ||||||
public required Func<ResourceViewModel, TValue, bool> ResourceContainsValue { get; set; } | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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) | ||
{ | ||
AreAllVisible = newAreAllVisible; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously this line (and the logic in OnValueVisibilityChangedInternalAsync) was done in the callback but can be done directly in this component before invoking the callback. |
||
await AreAllVisibleChanged.InvokeAsync(AreAllVisible); | ||
await OnAllResourceTypesCheckedChangedAsync(); | ||
} | ||
|
||
private async Task OnValueVisibilityChangedInternalAsync(TValue value, bool isVisible) | ||
{ | ||
if (isVisible) | ||
{ | ||
VisibleValues[value] = true; | ||
} | ||
else | ||
{ | ||
VisibleValues.TryRemove(value, out _); | ||
} | ||
|
||
await OnValueVisibilityChangedAsync(value, isVisible); | ||
} | ||
|
||
internal static bool? GetFieldVisibility(ConcurrentDictionary<TValue, bool> visibleValues, ConcurrentDictionary<TValue, bool> allValues, StringComparer comparer) | ||
{ | ||
static bool SetEqualsKeys(ConcurrentDictionary<TValue, bool> left, ConcurrentDictionary<TValue, bool> right, StringComparer comparer) | ||
{ | ||
// PERF: This is inefficient since Keys locks and copies the keys. | ||
var keysLeft = left.Keys.Select(key => key.ToString()).ToList(); | ||
var keysRight = right.Keys.Select(key => key.ToString()).ToList(); | ||
|
||
return keysLeft.Count == keysRight.Count && keysLeft.OrderBy(key => key, comparer).SequenceEqual(keysRight.OrderBy(key => key, comparer), comparer); | ||
} | ||
|
||
return SetEqualsKeys(visibleValues, allValues, comparer) | ||
? true | ||
: visibleValues.IsEmpty | ||
? false | ||
: null; | ||
} | ||
|
||
internal static void SetFieldVisibility(ConcurrentDictionary<TValue, bool> visibleValues, ConcurrentDictionary<TValue, bool> allValues, bool? value, Action stateHasChanged) | ||
{ | ||
static bool UnionWithKeys(ConcurrentDictionary<TValue, bool> left, ConcurrentDictionary<TValue, bool> right) | ||
{ | ||
// .Keys locks and copies the keys so avoid it here. | ||
foreach (var (key, _) in right) | ||
{ | ||
left[key] = true; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
if (value is true) | ||
{ | ||
UnionWithKeys(visibleValues, allValues); | ||
} | ||
else if (value is false) | ||
{ | ||
visibleValues.Clear(); | ||
} | ||
|
||
stateHasChanged(); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -34,35 +33,48 @@ | |
@if (ViewportInformation.IsDesktop) | ||
{ | ||
<FluentButton id="typeFilterButton" slot="end" | ||
Appearance="@(AreAllTypesVisible is true ? Appearance.Stealth : Appearance.Accent)" | ||
Appearance="@(AreAllVisibleInAnyFilter ? Appearance.Stealth : Appearance.Accent)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
AllResources="@_visibleResources" | ||
AllResourceStates="@_allResourceStates" | ||
VisibleResourceStates="@_visibleResourceStates" | ||
AllResourceTypes="@_allResourceTypes" | ||
VisibleResourceTypes="@_visibleResourceTypes" | ||
AllResourceHealthStates="@_allResourceHealthStates" | ||
VisibleResourceHealthStates="@_visibleResourceHealthStates" | ||
OnAllFilterVisibilityCheckedChangedAsync="@OnAllFilterVisibilityCheckedChangedAsync" | ||
OnResourceFilterVisibilityChangedAsync="@OnResourceFilterVisibilityChangedAsync" | ||
AreAllTypesVisible="@AreAllTypesVisible" | ||
AreAllStatesVisible="@AreAllStatesVisible" | ||
AreAllHealthStatesVisible="@AreAllHealthStatesVisible" /> | ||
</div> | ||
} | ||
</ToolbarSection> | ||
|
||
<MainSection> | ||
<FluentPopover AnchorId="typeFilterButton" @bind-Open="_isTypeFilterVisible" AutoFocus="true" FixedPlacement="true"> | ||
<Header>@Loc[nameof(Dashboard.Resources.Resources.ResourcesResourceTypesHeader)]</Header> | ||
<FluentPopover AnchorId="typeFilterButton" @bind-Open="_isFilterPopupVisible" AutoFocus="true" FixedPlacement="true"> | ||
<Body> | ||
<SelectResourceTypes AllResourceTypes="_allResourceTypes" | ||
VisibleResourceTypes="_visibleResourceTypes" | ||
OnAllResourceTypesCheckedChangedAsync="@OnAllResourceTypesCheckedChangedAsync" | ||
AreAllTypesVisible="@(() => AreAllTypesVisible)" | ||
OnResourceTypeVisibilityChangedAsync="@OnResourceTypeVisibilityChangedAsync" /> | ||
<ResourceFilters | ||
AllResources="@_visibleResources" | ||
AllResourceStates="@_allResourceStates" | ||
VisibleResourceStates="@_visibleResourceStates" | ||
AllResourceTypes="@_allResourceTypes" | ||
VisibleResourceTypes="@_visibleResourceTypes" | ||
AllResourceHealthStates="@_allResourceHealthStates" | ||
VisibleResourceHealthStates="@_visibleResourceHealthStates" | ||
OnAllFilterVisibilityCheckedChangedAsync="@OnAllFilterVisibilityCheckedChangedAsync" | ||
OnResourceFilterVisibilityChangedAsync="@OnResourceFilterVisibilityChangedAsync" | ||
AreAllTypesVisible="@AreAllTypesVisible" | ||
AreAllStatesVisible="@AreAllStatesVisible" | ||
AreAllHealthStatesVisible="@AreAllHealthStatesVisible" /> | ||
</Body> | ||
</FluentPopover> | ||
|
||
|
There was a problem hiding this comment.
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.