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
8 changes: 4 additions & 4 deletions src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public async Task EditAsync()
if (SelectedRows.Count == 1)
{
// 检查是否选中了不可编辑行(行内无编辑按钮),同时检查按钮禁用状态(禁用时不可编辑)
if (CanEdit())
if (ProhibitEdit())
{
// 提示不可编辑
await ShowToastAsync(EditButtonToastTitle, EditButtonToastReadonlyContent);
Expand Down Expand Up @@ -992,7 +992,7 @@ protected async Task<bool> ConfirmDelete()
{
await ShowDeleteToastAsync(DeleteButtonToastTitle, DeleteButtonToastContent);
}
else if (CanDelete())
else if (ProhibitDelete())
{
await ShowDeleteToastAsync(DeleteButtonToastTitle, DeleteButtonToastCanNotDeleteContent);
}
Expand All @@ -1003,12 +1003,12 @@ protected async Task<bool> ConfirmDelete()
return ret;
}

private bool CanEdit() => (ShowExtendEditButtonCallback != null && !ShowExtendEditButtonCallback(SelectedRows[0]))
private bool ProhibitEdit() => (ShowExtendEditButtonCallback != null && !ShowExtendEditButtonCallback(SelectedRows[0]))
|| !ShowExtendEditButton
|| (DisableExtendEditButtonCallback != null && DisableExtendEditButtonCallback(SelectedRows[0]))
|| DisableExtendEditButton;

private bool CanDelete() => (ShowExtendDeleteButtonCallback != null && SelectedRows.Any(i => !ShowExtendDeleteButtonCallback(i)))
private bool ProhibitDelete() => (ShowExtendDeleteButtonCallback != null && SelectedRows.Any(i => !ShowExtendDeleteButtonCallback(i)))
|| !ShowExtendDeleteButton
|| (DisableExtendDeleteButtonCallback != null && SelectedRows.Any(x => DisableExtendDeleteButtonCallback(x)))
|| DisableExtendDeleteButton;
Expand Down
20 changes: 10 additions & 10 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8651,8 +8651,8 @@ public void Modify_Ok()
pb.Add(a => a.ShowExtendEditButton, false);
pb.Add(a => a.ShowExtendDeleteButton, false);
});
Assert.True(CanEdit(cut.Instance));
Assert.True(CanDelete(cut.Instance));
Assert.True(ProhibitEdit(cut.Instance));
Assert.True(ProhibitDelete(cut.Instance));

cut.SetParametersAndRender(pb =>
{
Expand All @@ -8661,8 +8661,8 @@ public void Modify_Ok()
pb.Add(a => a.DisableExtendEditButton, true);
pb.Add(a => a.DisableExtendDeleteButton, true);
});
Assert.True(CanEdit(cut.Instance));
Assert.True(CanDelete(cut.Instance));
Assert.True(ProhibitEdit(cut.Instance));
Assert.True(ProhibitDelete(cut.Instance));

cut.SetParametersAndRender(pb =>
{
Expand All @@ -8680,14 +8680,14 @@ public void Modify_Ok()
return true;
});
});
Assert.True(CanEdit(cut.Instance));
Assert.True(CanDelete(cut.Instance));
Assert.True(ProhibitEdit(cut.Instance));
Assert.True(ProhibitDelete(cut.Instance));
}

static bool CanEdit(Table<Foo> @this)
static bool ProhibitEdit(Table<Foo> @this)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding test cases for scenarios where editing/deleting is permitted.

Add tests confirming ProhibitEdit(cut.Instance) and ProhibitDelete(cut.Instance) return false when editing and deleting are allowed (e.g., buttons enabled and callbacks permit the action) to ensure the logic doesn’t wrongly block these operations.

{
var ret = false;
var methodInfo = @this.GetType().GetMethod("CanEdit", BindingFlags.Instance | BindingFlags.NonPublic);
var methodInfo = @this.GetType().GetMethod("ProhibitEdit", BindingFlags.Instance | BindingFlags.NonPublic);
if (methodInfo != null)
{
var result = methodInfo.Invoke(@this, null);
Expand All @@ -8699,10 +8699,10 @@ static bool CanEdit(Table<Foo> @this)
return ret;
}

static bool CanDelete(Table<Foo> @this)
static bool ProhibitDelete(Table<Foo> @this)
{
var ret = false;
var methodInfo = @this.GetType().GetMethod("CanDelete", BindingFlags.Instance | BindingFlags.NonPublic);
var methodInfo = @this.GetType().GetMethod("ProhibitDelete", BindingFlags.Instance | BindingFlags.NonPublic);
if (methodInfo != null)
{
var result = methodInfo.Invoke(@this, null);
Expand Down