Skip to content

Commit 2dc0cff

Browse files
ArgoZhangshakugans
andauthored
fix(Table): unsupported filter data type cause filter icon misalignment (#6298)
* wip: 临时提交 * chore: bump version 9.8.0-beta03 Co-Authored-By: shakugans <[email protected]> * refactor: 重构 NotSupportFilter 组件 * refactor: 重构 TableColumnFilter 组件 * refactor: 增加搜索重置按钮样式 * test: 更新单元测试 * test: 更新单元测试 * refactor: 使用基类本地化服务 * test: 补充单元测试 * test: 更新单元测试 --------- Co-authored-by: shakugans <[email protected]>
1 parent 79b91d9 commit 2dc0cff

File tree

8 files changed

+109
-25
lines changed

8 files changed

+109
-25
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.8.0-beta02</Version>
4+
<Version>9.8.0-beta03</Version>
55
</PropertyGroup>
66

77
<ItemGroup>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@namespace BootstrapBlazor.Components
2+
@inherits FilterBase
3+
4+
<div>@NotSupportedMessage</div>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// NotSupportFilter component
10+
/// </summary>
11+
public partial class NotSupportFilter
12+
{
13+
/// <summary>
14+
/// 获得/设置 不支持过滤类型提示信息 默认 null 读取资源文件内容
15+
/// </summary>
16+
[Parameter]
17+
public string? NotSupportedMessage { get; set; }
18+
19+
/// <summary>
20+
/// <inheritdoc/>
21+
/// </summary>
22+
protected override void OnParametersSet()
23+
{
24+
base.OnParametersSet();
25+
26+
NotSupportedMessage ??= Localizer[nameof(NotSupportedMessage)];
27+
}
28+
29+
/// <summary>
30+
/// <inheritdoc/>
31+
/// </summary>
32+
/// <returns></returns>
33+
public override FilterKeyValueAction GetFilterConditions()
34+
{
35+
return new();
36+
}
37+
38+
/// <summary>
39+
/// <inheritdoc/>
40+
/// </summary>
41+
public override void Reset()
42+
{
43+
44+
}
45+
}

src/BootstrapBlazor/Components/Filters/TableColumnFilter.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ else
8888
</FilterProvider>
8989
break;
9090
default:
91-
<div>@NotSupportedMessage</div>
91+
<FilterProvider>
92+
<NotSupportFilter NotSupportedMessage="@NotSupportedMessage"></NotSupportFilter>
93+
</FilterProvider>
9294
break;
9395
}
9496
}

src/BootstrapBlazor/Components/Filters/TableColumnFilter.razor.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public partial class TableColumnFilter : IFilter
5050
[NotNull]
5151
public ITable? Table { get; set; }
5252

53-
[Inject]
54-
[NotNull]
55-
private IStringLocalizer<TableColumnFilter>? Localizer { get; set; }
56-
5753
/// <summary>
5854
/// 获得 过滤小图标样式
5955
/// </summary>
@@ -87,16 +83,6 @@ protected override void OnInitialized()
8783
_fieldKey = Column.GetFieldName();
8884
}
8985

90-
/// <summary>
91-
/// <inheritdoc/>
92-
/// </summary>
93-
protected override void OnParametersSet()
94-
{
95-
base.OnParametersSet();
96-
97-
NotSupportedMessage ??= Localizer[nameof(NotSupportedMessage)];
98-
}
99-
10086
/// <summary>
10187
/// <inheritdoc/>
10288
/// </summary>

src/BootstrapBlazor/Components/Tab/Tab.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public partial class Tab
487487
private bool IsPreventDefault => _contextMenuZone != null;
488488

489489
private static string? GetTabItemClassString(TabItem item) => CssBuilder.Default("tabs-body-content")
490-
.AddClass("d-none", item is { IsActive: false })
490+
.AddClass("d-none", !item.IsActive)
491491
.Build();
492492

493493
/// <summary>

test/UnitTest/Components/TabTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,20 @@ public async Task IsLoopSwitchTabItem_Ok()
191191
pb.Add(a => a.ChildContent, "Tab2-Content");
192192
});
193193
});
194-
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none").InnerHtml);
194+
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none .tabs-body-content-wrap").InnerHtml);
195195

196196
// Click Prev
197197
var button = cut.Find(".nav-link-bar.left .nav-link-bar-button");
198198
await cut.InvokeAsync(() => button.Click());
199-
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none").InnerHtml);
199+
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none .tabs-body-content-wrap").InnerHtml);
200200

201201
// Click Next
202202
button = cut.Find(".nav-link-bar.right .nav-link-bar-button");
203203
await cut.InvokeAsync(() => button.Click());
204-
Assert.Equal("Tab1-Content", cut.Find(".tabs-body .d-none").InnerHtml);
204+
Assert.Equal("Tab1-Content", cut.Find(".tabs-body .d-none .tabs-body-content-wrap").InnerHtml);
205205

206206
await cut.InvokeAsync(() => button.Click());
207-
Assert.Equal("Tab1-Content", cut.Find(".tabs-body .d-none").InnerHtml);
207+
Assert.Equal("Tab1-Content", cut.Find(".tabs-body .d-none .tabs-body-content-wrap").InnerHtml);
208208
}
209209

210210
[Fact]
@@ -240,7 +240,7 @@ public void ClickTab_Ok()
240240
pb.Add(a => a.ChildContent, "Tab2-Content");
241241
});
242242
});
243-
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none").InnerHtml);
243+
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none .tabs-body-content-wrap").InnerHtml);
244244

245245
// Click TabItem
246246
cut.Find(".tabs-item").Click();
@@ -251,14 +251,14 @@ public void ClickTab_Ok()
251251
button.Click();
252252
button.Click();
253253
button.Click();
254-
Assert.Equal("Tab1-Content", cut.Find(".tabs-body .d-none").InnerHtml);
254+
Assert.Equal("Tab1-Content", cut.Find(".tabs-body .d-none .tabs-body-content-wrap").InnerHtml);
255255

256256
// Click Next
257257
button = cut.Find(".nav-link-bar.right .nav-link-bar-button");
258258
button.Click();
259259
button.Click();
260260
button.Click();
261-
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none").InnerHtml);
261+
Assert.Equal("Tab2-Content", cut.Find(".tabs-body .d-none .tabs-body-content-wrap").InnerHtml);
262262

263263
// Close
264264
Assert.Null(closedItem);
@@ -342,7 +342,7 @@ public void AddTab_Ok()
342342

343343
cut.InvokeAsync(() => tab.AddTab("/", "Tab2", "fa-solid fa-font-awesome", false, true));
344344
cut.InvokeAsync(() => tab.CloseOtherTabs());
345-
Assert.Equal("Tab1-Body", cut.Find(".tabs-body-content").InnerHtml);
345+
Assert.Equal("Tab1-Body", cut.Find(".tabs-body-content .tabs-body-content-wrap").InnerHtml);
346346

347347
// NotFound
348348
cut.InvokeAsync(() => tab.AddTab("/Test", "Tab3", "fa-solid fa-font-awesome", false, true));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace UnitTest.Components;
7+
8+
public class TableNotSupportFilterTest : BootstrapBlazorTestBase
9+
{
10+
[Fact]
11+
public void OnFilterAsync_Ok()
12+
{
13+
var cut = Context.RenderComponent<TableColumnFilter>(pb =>
14+
{
15+
pb.Add(a => a.Table, new MockTable());
16+
pb.Add(a => a.Column, new MockColumn());
17+
});
18+
19+
cut.Contains("不支持的类型,请使用 FilterTemplate 自定义过滤组件");
20+
21+
var filter = cut.FindComponent<NotSupportFilter>();
22+
var conditions = filter.Instance.GetFilterConditions();
23+
Assert.Empty(conditions.Filters);
24+
25+
filter.Instance.Reset();
26+
}
27+
28+
class MockTable : ITable
29+
{
30+
public Dictionary<string, IFilterAction> Filters { get; set; } = [];
31+
32+
public Func<Task>? OnFilterAsync { get; set; }
33+
34+
public List<ITableColumn> Columns => [];
35+
36+
public IEnumerable<ITableColumn> GetVisibleColumns() => Columns;
37+
}
38+
39+
class MockColumn : TableColumn<Foo, List<string>>
40+
{
41+
public MockColumn()
42+
{
43+
PropertyType = typeof(List<string>);
44+
FieldName = "Double";
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)