-
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 all 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,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> | ||||||
<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; } | ||||||
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> 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; } | ||||||
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] | ||||||
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
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
Don't need |
||||||||||||||||||||||
|
||||||||||||||||||||||
private async Task OnValueVisibilityChangedInternalAsync(TValue value, bool isVisible) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
if (isVisible) | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
AllValues[value] = true; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
else | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
AllValues[value] = false; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+18
to
+25
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
|
||||||||||||||||||||||
|
||||||||||||||||||||||
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
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. I don't like nested ternary statements. Make at least one of these an if. 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. You can flatten them or use switch expressions 😄 |
||||||||||||||||||||||
} | ||||||||||||||||||||||
} |
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 | ||
|
@@ -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)" | ||
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 | ||
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> | ||
|
||
|
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.