Skip to content
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
10 changes: 7 additions & 3 deletions src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,19 +624,23 @@ protected async Task ShowEditDialog(ItemChangedType changedType)
OnEditAsync = async context =>
{
await ToggleLoading(true);
saved = await SaveModelAsync(context, changedType);
if (IsTracking)
{
saved = true;
if (changedType == ItemChangedType.Add)
{
var index = InsertRowMode == InsertRowMode.First ? 0 : Rows.Count;
Rows.Insert(index, EditModel);
}
await InvokeItemsChanged();
}
else if (saved)
else
{
await QueryAsync();
saved = await SaveModelAsync(context, changedType);
if (saved)
{
await QueryAsync();
}
}
await ToggleLoading(false);
return saved;
Expand Down
37 changes: 36 additions & 1 deletion test/UnitTest/Components/TableDialogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

using AngleSharp.Dom;
using BootstrapBlazor.Shared;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
Expand Down Expand Up @@ -59,10 +60,11 @@ public async Task EditAsync_Ok()
// 编辑弹窗逻辑
var form = cut.Find(".modal-body form");
await cut.InvokeAsync(() => form.Submit());
var modal = cut.FindComponent<Modal>();
await cut.InvokeAsync(() => modal.Instance.CloseCallback());

// 内置数据服务取消回调
await cut.InvokeAsync(() => table.Instance.EditAsync());
var modal = cut.FindComponent<Modal>();
await cut.InvokeAsync(() => modal.Instance.CloseCallback());

// 自定义数据服务取消回调测试
Expand Down Expand Up @@ -99,6 +101,39 @@ public async Task EditAsync_Ok()
await cut.InvokeAsync(() => table.Instance.AddAsync());
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
Assert.True(closed);

// IsTracking mode
table.SetParametersAndRender(pb =>
{
pb.Add(a => a.IsTracking, true);
});
// Add 弹窗
await cut.InvokeAsync(() => table.Instance.AddAsync());

// 编辑弹窗逻辑
input = cut.Find(".modal-body form input.form-control");
await cut.InvokeAsync(() => input.Change("Test_Name"));

form = cut.Find(".modal-body form");
await cut.InvokeAsync(() => form.Submit());
await cut.InvokeAsync(() => modal.Instance.CloseCallback());

// 更新插入模式
table.SetParametersAndRender(pb =>
{
pb.Add(a => a.InsertRowMode, InsertRowMode.First);
});

// Add 弹窗
await cut.InvokeAsync(() => table.Instance.AddAsync());

// 编辑弹窗逻辑
input = cut.Find(".modal-body form input.form-control");
await cut.InvokeAsync(() => input.Change("Test_Name"));

form = cut.Find(".modal-body form");
await cut.InvokeAsync(() => form.Submit());
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
}

private class MockEFCoreDataService : IDataService<Foo>, IEntityFrameworkCoreDataService
Expand Down