mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-11-30 02:58:37 +08:00
!2813 fix(#I58SW7): can't save on table component in dynamic object mode
* chore: bump version 6.6.13 * test: 增加动态数据类型保存逻辑单元测试 * revert: 恢复动态类型保存逻辑
This commit is contained in:
parent
814805ef49
commit
2ef2e3ae39
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>6.6.12</Version>
|
||||
<Version>6.6.13</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
|
@ -400,14 +400,23 @@ public partial class Table<TItem>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> SaveModelAsync(EditContext context, ItemChangedType changedType)
|
||||
{
|
||||
bool valid = await InternalOnSaveAsync((TItem)context.Model, changedType);
|
||||
bool valid;
|
||||
if (DynamicContext != null)
|
||||
{
|
||||
await DynamicContext.SetValue(context.Model);
|
||||
RowItemsCache = null;
|
||||
valid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = await InternalOnSaveAsync((TItem)context.Model, changedType);
|
||||
}
|
||||
|
||||
// 回调外部自定义方法
|
||||
if (OnAfterSaveAsync != null)
|
||||
{
|
||||
await OnAfterSaveAsync((TItem)context.Model);
|
||||
}
|
||||
|
||||
if (ShowToastAfterSaveOrDeleteModel)
|
||||
{
|
||||
var option = new ToastOption
|
||||
|
@ -3,6 +3,7 @@
|
||||
// Website: https://www.blazor.zone or https://argozhang.github.io/
|
||||
|
||||
using BootstrapBlazor.Shared;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@ -3208,7 +3209,7 @@ public class TableTest : TableTestBase
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DynamicContext_Ok()
|
||||
public async Task DynamicContext_Add()
|
||||
{
|
||||
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
|
||||
var items = Foo.GenerateFoo(localizer, 2);
|
||||
@ -3229,6 +3230,30 @@ public class TableTest : TableTestBase
|
||||
await cut.InvokeAsync(() => delete.Instance.OnConfirm());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DynamicContext_Edit()
|
||||
{
|
||||
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
|
||||
var items = Foo.GenerateFoo(localizer, 2);
|
||||
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
|
||||
{
|
||||
pb.AddChildContent<MockDynamicTable>(pb =>
|
||||
{
|
||||
pb.Add(a => a.RenderMode, TableRenderMode.Table);
|
||||
pb.Add(a => a.IsMultipleSelect, true);
|
||||
pb.Add(a => a.ShowToolbar, true);
|
||||
pb.Add(a => a.DynamicContext, CreateDynamicContext(localizer));
|
||||
});
|
||||
});
|
||||
|
||||
var input = cut.Find("tbody tr input");
|
||||
await cut.InvokeAsync(() => input.Click());
|
||||
|
||||
var table = cut.FindComponent<MockDynamicTable>();
|
||||
var saved = await table.Instance.SaveModelTest();
|
||||
Assert.True(saved);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CustomerSearchs_Ok()
|
||||
{
|
||||
@ -3897,7 +3922,7 @@ public class TableTest : TableTestBase
|
||||
return userData;
|
||||
}
|
||||
|
||||
private static DataTableDynamicContext CreateDynamicContext(IStringLocalizer<Foo> localizer)
|
||||
public static DataTableDynamicContext CreateDynamicContext(IStringLocalizer<Foo> localizer)
|
||||
{
|
||||
var UserData = CreateDataTable(localizer);
|
||||
return new DataTableDynamicContext(UserData, (context, col) =>
|
||||
@ -4093,4 +4118,13 @@ public class TableTest : TableTestBase
|
||||
return base.ActiveRenderMode;
|
||||
}
|
||||
}
|
||||
|
||||
private class MockDynamicTable : Table<DynamicObject>
|
||||
{
|
||||
public async Task<bool> SaveModelTest()
|
||||
{
|
||||
var context = new EditContext(SelectedRows[0]);
|
||||
return await base.SaveModelAsync(context, ItemChangedType.Update);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user