Skip to content
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

fix(Table): not trigger OnAfterCancelSaveAsync on EditForm/InCell mode #4817

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.1.3-beta02</Version>
<Version>9.1.3-beta03</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ private async Task ShowDeleteToastAsync(string title, string content, ToastCateg
/// 取消保存方法
/// </summary>
/// <returns></returns>
protected void CancelSave()
protected async Task CancelSave()
{
if (EditMode == EditMode.EditForm)
{
Expand All @@ -635,6 +635,11 @@ protected void CancelSave()
AddInCell = false;
EditInCell = false;
}

if (OnAfterCancelSaveAsync != null)
{
await OnAfterCancelSaveAsync();
}
}

/// <summary>
Expand Down
82 changes: 82 additions & 0 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5507,6 +5507,88 @@ public async Task OnSaveAsync_Ok()
Assert.True(afterModify);
}

[Fact]
public async Task OnAfterCancelSaveAsync_EditForm()
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var items = Foo.GenerateFoo(localizer, 2);
var afterCancelSave = false;
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Table<Foo>>(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.EditForm);
pb.Add(a => a.OnAfterCancelSaveAsync, () =>
{
afterCancelSave = true;
return Task.CompletedTask;
});
pb.Add(a => a.TableColumns, foo => builder =>
{
builder.OpenComponent<TableColumn<Foo, string>>(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(".form-footer .btn-secondary");
await cut.InvokeAsync(() => cancelButton.Click());
Assert.True(afterCancelSave);
}

[Fact]
public async Task OnAfterCancelSaveAsync_InCell()
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var items = Foo.GenerateFoo(localizer, 2);
var afterCancelSave = false;
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Table<Foo>>(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.EditForm);
pb.Add(a => a.OnAfterCancelSaveAsync, () =>
{
afterCancelSave = true;
return Task.CompletedTask;
});
pb.Add(a => a.TableColumns, foo => builder =>
{
builder.OpenComponent<TableColumn<Foo, string>>(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());

// 取消按钮
button = cut.FindAll("tbody tr button");
await cut.InvokeAsync(() => button[1].Click());
Assert.True(afterCancelSave);
}

[Fact]
public async Task OnAfterCancelSaveAsync_Popup()
{
Expand Down
Loading