Skip to content

Commit 902e266

Browse files
authored
bug(EditDialog): trigger OnCloseAsync callback twice (#4787)
* refactor: 移除基类方法调用 * refactor: 移除 IJSRuntime 注入服务 * doc: 更新文档 * chore: 更新 auto 文件夹 * revert: 撤销更改 * refactor: 单独响应 OnCloseAsync 参数 * refactor: 修复关闭触发两次问题 * chore: 更新目录结构 * test: 更新单元测试 * revert: 撤销更改 * Revert "refactor: 单独响应 OnCloseAsync 参数" This reverts commit e25a10d. * Revert "test: 更新单元测试" This reverts commit 0634cc1. * refactor: 重构扩展方法修复触发两次 Close 回调问题 * test: 更新单元测试 * test: 更新单元测试 * test: 更新单元测试
1 parent 2be3326 commit 902e266

File tree

10 files changed

+36
-30
lines changed

10 files changed

+36
-30
lines changed

BootstrapBlazor.sln

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazorAuto", "src\
7373
EndProject
7474
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazorAuto.Client", "src\BootstrapBlazorAuto\BootstrapBlazorAuto.Client\BootstrapBlazorAuto.Client.csproj", "{7D3FFBD8-A43C-490F-92D1-4F669E7E550F}"
7575
EndProject
76+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "auto", "auto", "{0C783146-82BE-4E81-99A2-EEFF356F1BCC}"
77+
EndProject
7678
Global
7779
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7880
Debug|Any CPU = Debug|Any CPU
@@ -135,8 +137,9 @@ Global
135137
{D8AEAFE7-10AF-4A5B-BC67-FE740A2CA1DF} = {7C1D79F1-87BC-42C1-BD5A-CDE4044AC1BD}
136138
{01DA4687-0973-4CA6-97F5-04E0B8DD1B13} = {7C1D79F1-87BC-42C1-BD5A-CDE4044AC1BD}
137139
{A6E8F478-213E-44EC-BF4D-7C9342C3DEED} = {A2182155-43ED-44C1-BF6F-1B70EBD2DFFE}
138-
{2A69B4F8-7C7D-4AC3-BE13-B862DE078F6E} = {A2182155-43ED-44C1-BF6F-1B70EBD2DFFE}
139-
{7D3FFBD8-A43C-490F-92D1-4F669E7E550F} = {A2182155-43ED-44C1-BF6F-1B70EBD2DFFE}
140+
{2A69B4F8-7C7D-4AC3-BE13-B862DE078F6E} = {0C783146-82BE-4E81-99A2-EEFF356F1BCC}
141+
{7D3FFBD8-A43C-490F-92D1-4F669E7E550F} = {0C783146-82BE-4E81-99A2-EEFF356F1BCC}
142+
{0C783146-82BE-4E81-99A2-EEFF356F1BCC} = {A2182155-43ED-44C1-BF6F-1B70EBD2DFFE}
140143
EndGlobalSection
141144
GlobalSection(ExtensibilityGlobals) = postSolution
142145
SolutionGuid = {0DCB0756-34FA-4FD0-AE1D-D3F08B5B3A6B}

src/BootstrapBlazor.Shared/Components/Components/CultureChooser.razor.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ public partial class CultureChooser
1818
[NotNull]
1919
private IOptionsMonitor<BootstrapBlazorOptions>? BootstrapOptions { get; set; }
2020

21-
[Inject]
22-
[NotNull]
23-
private IJSRuntime? JSRuntime { get; set; }
24-
2521
[Inject]
2622
[NotNull]
2723
private IStringLocalizer<CultureChooser>? Localizer { get; set; }

src/BootstrapBlazor.Shared/Components/Samples/EditDialogs.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</Tips>
1212

1313
<DemoBlock Title="@Localizer["NormalTitle"]" Introduction="@Localizer["NormalIntro"]" Name="Normal">
14-
<div>
15-
<Button Text="@Localizer["LeftAlignedButton"]" OnClickWithoutRender="@NormalShowDialog" />
16-
<Button Text="@Localizer["RightAlignedButton"]" OnClickWithoutRender="@NormalShowAlignDialog" />
14+
<Button Text="@Localizer["LeftAlignedButton"]" OnClickWithoutRender="@NormalShowDialog" />
15+
<Button Text="@Localizer["RightAlignedButton"]" OnClickWithoutRender="@NormalShowAlignDialog" />
16+
<section ignore>
1717
<ConsoleLogger @ref="NormalLogger" />
18-
</div>
18+
</section>
1919
</DemoBlock>
2020

2121
<DemoBlock Title="@Localizer["NoRenderTitle"]" Introduction="@Localizer["NoRenderIntro"]" Name="NoRender">

src/BootstrapBlazor.Shared/Locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@
607607
"NormalTitle": "Basic usage",
608608
"NormalIntro": "Automatically generate editable forms for each field of the model by binding the <code>TModel</code> data model",
609609
"NoRenderTitle": "Setting bound model part property does not show",
610-
"NoRenderIntro": "By setting the <code>Ignore=true</code> of the <code>IEditorItem</code> instance, the editable pop-up window do not shown.",
610+
"NoRenderIntro": "By setting the <b>Address</b> <b>Count</b> <code>Ignore=true</code> of the <code>IEditorItem</code> instance, the editable pop-up window do not shown.",
611611
"EditDialogOption": "EditDialogOption property",
612612
"LeftAlignedButton": "Edit popup (left-aligned)",
613613
"RightAlignedButton": "Edit popup (right aligned)",

src/BootstrapBlazor.Shared/Locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@
607607
"NormalTitle": "基础用法",
608608
"NormalIntro": "通过绑定 <code>TModel</code> 数据模型,自动生成模型各个字段的可编辑表单",
609609
"NoRenderTitle": "设置绑定模型部分属性不显示",
610-
"NoRenderIntro": "通过设置 <code>IEditorItem</code> 实例的 <code>Ignore=true</code>, 实现编辑弹窗不显示",
610+
"NoRenderIntro": "通过设置 <code>IEditorItem</code> 实例的 <b>地址</b> <b>数量</b> 参数 <code>Ignore=true</code>, 实现编辑弹窗不显示",
611611
"EditDialogOption": "EditDialogOption 属性",
612612
"LeftAlignedButton": "编辑弹窗(左对齐)",
613613
"RightAlignedButton": "编辑弹窗(右对齐)",

src/BootstrapBlazor/Extensions/DrawerExtensions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ public static class DrawerExtensions
1414
/// 弹出编辑抽屉
1515
/// </summary>
1616
/// <param name="service"><see cref="DrawerService"/> 服务实例</param>
17-
/// <param name="editOption"><see cref="ITableEditDialogOption{TModel}"/> 配置类实例</param>
17+
/// <param name="editDialogOption"><see cref="ITableEditDialogOption{TModel}"/> 配置类实例</param>
1818
/// <param name="option"><see cref="DrawerOption"/> 配置类实例</param>
19-
public static async Task ShowEditDrawer<TModel>(this DrawerService service, ITableEditDialogOption<TModel> editOption, DrawerOption option)
19+
public static async Task ShowEditDrawer<TModel>(this DrawerService service, TableEditDrawerOption<TModel> editDialogOption, DrawerOption option)
2020
{
21-
option.ChildContent = BootstrapDynamicComponent.CreateComponent<EditDialog<TModel>>(editOption.ToParameter()).Render();
21+
var parameters = editDialogOption.ToParameter();
22+
parameters.Add(nameof(EditDialog<TModel>.OnCloseAsync), editDialogOption.OnCloseAsync);
23+
option.ChildContent = BootstrapDynamicComponent.CreateComponent<EditDialog<TModel>>(parameters).Render();
2224
await service.Show(option);
2325
}
2426
}

src/BootstrapBlazor/Extensions/TableEditDialogOptionExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public static class TableEditDialogOptionExtensions
3636
[nameof(EditDialog<TModel>.DisableAutoSubmitFormByEnter)] = option.DisableAutoSubmitFormByEnter,
3737
[nameof(EditDialog<TModel>.BodyTemplate)] = option.DialogBodyTemplate,
3838
[nameof(EditDialog<TModel>.FooterTemplate)] = option.DialogFooterTemplate,
39-
[nameof(EditDialog<TModel>.OnCloseAsync)] = option.OnCloseAsync,
4039
[nameof(EditDialog<TModel>.OnSaveAsync)] = new Func<EditContext, Task<bool>>(async context =>
4140
{
4241
var ret = false;

test/UnitTest/Components/DialogTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ await cut.InvokeAsync(() => dialog.Show(new DialogOption()
210210
return Task.CompletedTask;
211211
};
212212
await cut.InvokeAsync(() => dialog.ShowEditDialog(editOption));
213+
213214
// 点击关闭按钮
214215
button = cut.FindComponents<Button>().First(b => b.Instance.Text == "关闭");
215-
await cut.InvokeAsync(() => button.Instance.OnClickWithoutRender!.Invoke());
216+
// 关闭按钮未设置 OnClickWithoutRender 事件
217+
Assert.Null(button.Instance.OnClickWithoutRender);
216218
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
217219
Assert.True(closed);
218220

test/UnitTest/Components/TableDrawerTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,31 @@ public async Task EditAsync_Ok()
5555
await cut.InvokeAsync(() => table.Instance.EditAsync());
5656

5757
// 获得关闭按钮直接关闭抽屉
58-
var closeButton = cut.FindComponent<DialogCloseButton>();
59-
await cut.InvokeAsync(() => closeButton.Instance.OnClickWithoutRender!());
58+
var closeButton = cut.Find(".bb-editor-footer .btn-secondary");
59+
await cut.InvokeAsync(() => closeButton.Click());
6060

6161
// 自定义数据服务取消回调测试
6262
table.SetParametersAndRender(pb =>
6363
{
6464
pb.Add(a => a.DataService, new MockEFCoreDataService(localizer));
6565
});
6666
await cut.InvokeAsync(() => table.Instance.EditAsync());
67-
closeButton = cut.FindComponent<DialogCloseButton>();
68-
await cut.InvokeAsync(() => closeButton.Instance.OnClickWithoutRender!());
67+
closeButton = cut.Find(".bb-editor-footer .btn-secondary");
68+
await cut.InvokeAsync(() => closeButton.Click());
6969

7070
// Add 弹窗
7171
await cut.InvokeAsync(() => table.Instance.AddAsync());
72-
closeButton = cut.FindComponent<DialogCloseButton>();
73-
await cut.InvokeAsync(() => closeButton.Instance.OnClickWithoutRender!());
72+
closeButton = cut.Find(".bb-editor-footer .btn-secondary");
73+
await cut.InvokeAsync(() => closeButton.Click());
7474

7575
// 自定义数据服务取消回调测试
7676
table.SetParametersAndRender(pb =>
7777
{
7878
pb.Add(a => a.EditDialogFullScreenSize, FullScreenSize.Always);
7979
});
8080
await cut.InvokeAsync(() => table.Instance.AddAsync());
81-
closeButton = cut.FindComponent<DialogCloseButton>();
82-
await cut.InvokeAsync(() => closeButton.Instance.OnClickWithoutRender!());
81+
closeButton = cut.Find(".bb-editor-footer .btn-secondary");
82+
await cut.InvokeAsync(() => closeButton.Click());
8383

8484
var closed = false;
8585
// 测试 CloseCallback
@@ -92,8 +92,8 @@ public async Task EditAsync_Ok()
9292
});
9393
});
9494
await cut.InvokeAsync(() => table.Instance.AddAsync());
95-
closeButton = cut.FindComponent<DialogCloseButton>();
96-
await cut.InvokeAsync(() => closeButton.Instance.OnClickWithoutRender!());
95+
closeButton = cut.Find(".bb-editor-footer .btn-secondary");
96+
await cut.InvokeAsync(() => closeButton.Click());
9797
Assert.True(closed);
9898

9999
// 保存失败,不关闭抽屉

test/UnitTest/Components/TableTest.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,11 +5548,15 @@ public async Task OnAfterCancelSaveAsync_Popup()
55485548
var modal = cut.FindComponent<Modal>();
55495549
await cut.InvokeAsync(modal.Instance.CloseCallback);
55505550

5551+
// 弹窗
55515552
await cut.InvokeAsync(() => button[0].Click());
5552-
var cancelButton = cut.Find(".bb-editor-footer .btn");
55535553

5554-
// 取消按钮
5555-
await cut.InvokeAsync(() => cancelButton.Click());
5554+
// 关闭按钮未设置 OnClickWithoutRender 回调
5555+
var cancelButton = cut.FindComponent<DialogCloseButton>();
5556+
Assert.Null(cancelButton.Instance.OnClickWithoutRender);
5557+
5558+
// 关闭弹窗
5559+
await cut.InvokeAsync(modal.Instance.CloseCallback);
55565560
Assert.True(afterCancelSave);
55575561
}
55585562

0 commit comments

Comments
 (0)