From f69c420d7a4349bd589c1a7f0f342614796b9f8d Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Fri, 29 Nov 2024 13:01:25 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20OnAfterCancelS?= =?UTF-8?q?aveAsync=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Table/Table.razor.Edit.cs | 6 +++++ .../Components/Table/Table.razor.Toolbar.cs | 22 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs index 08486602e5b..717244d5ed4 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs @@ -88,6 +88,12 @@ public partial class Table [Parameter] public Func? SetRowClassFormatter { get; set; } + /// + /// 获得/设置 取消保存后回调委托方法 + /// + [Parameter] + public Func? OnAfterCancelSaveAsync { get; set; } + /// /// 获得/设置 保存后回调委托方法 /// diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs index f8a61102667..0e8d4a4d8b7 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs @@ -850,6 +850,7 @@ private void AppendOptions(ITableEditDialogOption option, ItemChangedType protected async Task ShowEditDialog(ItemChangedType changedType) { var saved = false; + var triggerFromSave = false; var option = new EditDialogOption() { Class = "modal-dialog-table", @@ -860,10 +861,18 @@ protected async Task ShowEditDialog(ItemChangedType changedType) IsDraggable = EditDialogIsDraggable, ShowMaximizeButton = EditDialogShowMaximizeButton, FullScreenSize = EditDialogFullScreenSize, - OnCloseAsync = () => OnCloseEditDialogCallbackAsync(saved), + OnCloseAsync = async () => + { + if (triggerFromSave == false && OnAfterCancelSaveAsync != null) + { + await OnAfterCancelSaveAsync(); + } + await OnCloseEditDialogCallbackAsync(saved); + }, OnEditAsync = async context => { saved = await OnSaveEditCallbackAsync(context, changedType); + triggerFromSave = true; return saved; } }; @@ -877,12 +886,21 @@ protected async Task ShowEditDialog(ItemChangedType changedType) protected async Task ShowEditDrawer(ItemChangedType changedType) { var saved = false; + var triggerFromSave = false; var editOption = new TableEditDrawerOption() { - OnCloseAsync = () => OnCloseEditDialogCallbackAsync(saved), + OnCloseAsync = async () => + { + if (triggerFromSave == false && OnAfterCancelSaveAsync != null) + { + await OnAfterCancelSaveAsync(); + } + await OnCloseEditDialogCallbackAsync(saved); + }, OnEditAsync = async context => { saved = await OnSaveEditCallbackAsync(context, changedType); + triggerFromSave = true; return saved; } }; From 2ae9d0b615abf11ebc2dcd7484093e41c6cb1e45 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Fri, 29 Nov 2024 13:01:32 +0800 Subject: [PATCH 2/5] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TableTest.cs | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 509613a4476..96c89a8b16d 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -5505,6 +5505,49 @@ public async Task OnSaveAsync_Ok() Assert.True(afterModify); } + [Theory] + [InlineData(EditMode.Popup)] + [InlineData(EditMode.Drawer)] + public async Task OnAfterCancelSaveAsync_Ok(EditMode mode) + { + var localizer = Context.Services.GetRequiredService>(); + var items = Foo.GenerateFoo(localizer, 2); + var afterCancelSave = false; + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.RenderMode, TableRenderMode.Table); + pb.Add(a => a.Items, items); + pb.Add(a => a.IsMultipleSelect, true); + pb.Add(a => a.ShowToolbar, true); + pb.Add(a => a.ShowExtendButtons, true); + pb.Add(a => a.EditMode, mode); + pb.Add(a => a.OnAfterCancelSaveAsync, () => + { + afterCancelSave = true; + return Task.CompletedTask; + }); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + + // test edit button + var button = cut.FindAll("tbody tr button"); + await cut.InvokeAsync(() => button[0].Click()); + + // 取消按钮 + var cancelButton = cut.Find(".bb-editor-footer .btn"); + await cut.InvokeAsync(() => cancelButton.Click()); + Assert.True(afterCancelSave); + } + [Theory] [InlineData(EditMode.EditForm)] [InlineData(EditMode.InCell)] From db490ec344b3abdc57ca80fba7185cb43faa2b26 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Fri, 29 Nov 2024 13:02:05 +0800 Subject: [PATCH 3/5] chore: bump version 9.0.2-beta05 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index be74d62f614..41093d9b4be 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.0.2-beta04 + 9.0.2-beta05 From 3191c75fb2fc3170a0244232805ca6bab9dff5bc Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Fri, 29 Nov 2024 13:11:58 +0800 Subject: [PATCH 4/5] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/TableTest.cs | 67 +++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 96c89a8b16d..b1cf55712e1 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -5505,10 +5505,8 @@ public async Task OnSaveAsync_Ok() Assert.True(afterModify); } - [Theory] - [InlineData(EditMode.Popup)] - [InlineData(EditMode.Drawer)] - public async Task OnAfterCancelSaveAsync_Ok(EditMode mode) + [Fact] + public async Task OnAfterCancelSaveAsync_Popup() { var localizer = Context.Services.GetRequiredService>(); var items = Foo.GenerateFoo(localizer, 2); @@ -5522,7 +5520,58 @@ public async Task OnAfterCancelSaveAsync_Ok(EditMode mode) pb.Add(a => a.IsMultipleSelect, true); pb.Add(a => a.ShowToolbar, true); pb.Add(a => a.ShowExtendButtons, true); - pb.Add(a => a.EditMode, mode); + pb.Add(a => a.EditMode, EditMode.Popup); + pb.Add(a => a.OnAfterCancelSaveAsync, () => + { + afterCancelSave = true; + return Task.CompletedTask; + }); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + + // test edit button + var button = cut.FindAll("tbody tr button"); + await cut.InvokeAsync(() => button[0].Click()); + + // 保存按钮 + var saveButton = cut.Find(".bb-editor-footer .btn-primary"); + await cut.InvokeAsync(() => saveButton.Click()); + Assert.False(afterCancelSave); + + var modal = cut.FindComponent(); + await cut.InvokeAsync(modal.Instance.CloseCallback); + + await cut.InvokeAsync(() => button[0].Click()); + var cancelButton = cut.Find(".bb-editor-footer .btn"); + + // 取消按钮 + await cut.InvokeAsync(() => cancelButton.Click()); + Assert.True(afterCancelSave); + } + + [Fact] + public async Task OnAfterCancelSaveAsync_Drawer() + { + var localizer = Context.Services.GetRequiredService>(); + var items = Foo.GenerateFoo(localizer, 2); + var afterCancelSave = false; + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.RenderMode, TableRenderMode.Table); + pb.Add(a => a.Items, items); + pb.Add(a => a.IsMultipleSelect, true); + pb.Add(a => a.ShowToolbar, true); + pb.Add(a => a.ShowExtendButtons, true); + pb.Add(a => a.EditMode, EditMode.Drawer); pb.Add(a => a.OnAfterCancelSaveAsync, () => { afterCancelSave = true; @@ -5542,7 +5591,15 @@ public async Task OnAfterCancelSaveAsync_Ok(EditMode mode) var button = cut.FindAll("tbody tr button"); await cut.InvokeAsync(() => button[0].Click()); + // 保存按钮 + var saveButton = cut.Find(".bb-editor-footer .btn-primary"); + await cut.InvokeAsync(() => saveButton.Click()); + Assert.False(afterCancelSave); + // 取消按钮 + button = cut.FindAll("tbody tr button"); + await cut.InvokeAsync(() => button[0].Click()); + var cancelButton = cut.Find(".bb-editor-footer .btn"); await cut.InvokeAsync(() => cancelButton.Click()); Assert.True(afterCancelSave); From 891acca2b050299e836c71c9b1c8f1c0b82f2be7 Mon Sep 17 00:00:00 2001 From: Argo-AsicoTech Date: Fri, 29 Nov 2024 13:33:48 +0800 Subject: [PATCH 5/5] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs index 0e8d4a4d8b7..94b729568f6 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs @@ -886,12 +886,11 @@ protected async Task ShowEditDialog(ItemChangedType changedType) protected async Task ShowEditDrawer(ItemChangedType changedType) { var saved = false; - var triggerFromSave = false; var editOption = new TableEditDrawerOption() { OnCloseAsync = async () => { - if (triggerFromSave == false && OnAfterCancelSaveAsync != null) + if (OnAfterCancelSaveAsync != null) { await OnAfterCancelSaveAsync(); } @@ -900,7 +899,6 @@ protected async Task ShowEditDrawer(ItemChangedType changedType) OnEditAsync = async context => { saved = await OnSaveEditCallbackAsync(context, changedType); - triggerFromSave = true; return saved; } };