Skip to content

Commit be0ec84

Browse files
authored
feat(Table): add DisableExtendEditButton parameter (dotnetcore#2914)
* doc: 更新参数说明文档 * feat: 支持禁用行内编辑与删除按钮 * test: 增加单元测试 * chore: bump version 8.2.3-beta03
1 parent ce59363 commit be0ec84

File tree

9 files changed

+110
-7
lines changed

9 files changed

+110
-7
lines changed

src/BootstrapBlazor.Server/Components/Samples/Table/Tables.razor.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,30 @@ private AttributeItem[] GetAttributes() =>
813813
DefaultValue = "true"
814814
},
815815
new()
816+
{
817+
Name = nameof(Table<Foo>.ShowExtendEditButtonCallback),
818+
Description = Localizer["ShowExtendEditButtonCallbackAttr"],
819+
Type = "Func<TItem, bool>",
820+
ValueList = " - ",
821+
DefaultValue = " - "
822+
},
823+
new()
824+
{
825+
Name = nameof(Table<Foo>.DisableExtendEditButton),
826+
Description = Localizer["ShowExtendEditButtonAttr"],
827+
Type = "boolean",
828+
ValueList = "true / false",
829+
DefaultValue = "true"
830+
},
831+
new()
832+
{
833+
Name = nameof(Table<Foo>.DisableExtendEditButtonCallback),
834+
Description = Localizer["DisableExtendEditButtonCallbackAttr"],
835+
Type = "Func<TItem, bool>",
836+
ValueList = " - ",
837+
DefaultValue = " - "
838+
},
839+
new()
816840
{
817841
Name = nameof(Table<Foo>.ShowExtendDeleteButton),
818842
Description = Localizer["ShowExtendDeleteButtonAttr"],
@@ -821,6 +845,30 @@ private AttributeItem[] GetAttributes() =>
821845
DefaultValue = "true"
822846
},
823847
new()
848+
{
849+
Name = nameof(Table<Foo>.ShowExtendDeleteButtonCallback),
850+
Description = Localizer["ShowExtendDeleteButtonCallbackAttr"],
851+
Type = "Func<TItem, bool>",
852+
ValueList = " - ",
853+
DefaultValue = " - "
854+
},
855+
new()
856+
{
857+
Name = nameof(Table<Foo>.DisableExtendDeleteButton),
858+
Description = Localizer["ShowExtendDeleteButtonAttr"],
859+
Type = "boolean",
860+
ValueList = "true / false",
861+
DefaultValue = "true"
862+
},
863+
new()
864+
{
865+
Name = nameof(Table<Foo>.DisableExtendDeleteButtonCallback),
866+
Description = Localizer["DisableExtendDeleteButtonCallbackAttr"],
867+
Type = "Func<TItem, bool>",
868+
ValueList = " - ",
869+
DefaultValue = " - "
870+
},
871+
new()
824872
{
825873
Name = nameof(Table<Foo>.ShowUnsetGroupItemsOnTop),
826874
Description = Localizer["ShowUnsetGroupItemsOnTopAttr"],

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4698,7 +4698,13 @@
46984698
"ShowDeleteButtonCallbackAttr": "Show Use ShowEditButton value when the inline delete button is not set",
46994699
"ShowExtendButtonsAttr": "Show row action button",
47004700
"ShowExtendEditButtonAttr": "Show row edit action button",
4701+
"ShowExtendEditButtonCallbackAttr": "Show row edit action button callback",
47014702
"ShowExtendDeleteButtonAttr": "Show row delete action button",
4703+
"ShowExtendDeleteButtonCallbackAttr": "Show row delete action button callback",
4704+
"DisableExtendEditButtonAttr": "Disable row edit action button",
4705+
"DisableExtendEditButtonCallbackAttr": "Disable row edit action button callback",
4706+
"DisableExtendDeleteButtonAttr": "Disable row delete action button",
4707+
"DisableExtendDeleteButtonCallbackAttr": "Disable row delete action button callback",
47024708
"ShowUnsetGroupItemsOnTopAttr": "Whether ungrouped edits are rendered at the beginning",
47034709
"ShowSkeletonAttr": "Whether to display skeleton screen when first render",
47044710
"ShowLoadingInFirstRenderAttr": "Whether to display the loading animation when first render",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4697,8 +4697,14 @@
46974697
"ShowDeleteButtonAttr": "显示删除按钮",
46984698
"ShowDeleteButtonCallbackAttr": "显示行内删除按钮未设置时使用 ShowEditButton 值",
46994699
"ShowExtendButtonsAttr": "显示行操作按钮",
4700-
"ShowExtendEditButtonAttr": "显示行编辑操作按钮",
4701-
"ShowExtendDeleteButtonAttr": "显示行删除操作按钮",
4700+
"ShowExtendEditButtonAttr": "是否显示行编辑操作按钮",
4701+
"ShowExtendEditButtonCallbackAttr": "是否显示行内编辑操作按钮回调方法",
4702+
"ShowExtendDeleteButtonAttr": "是否显示行删除操作按钮",
4703+
"ShowExtendDeleteButtonCallbackAttr": "是否显示行内删除操作按钮回调方法",
4704+
"DisableExtendEditButtonAttr": "是否禁用行内编辑操作按钮",
4705+
"DisableExtendEditButtonCallbackAttr": "是否禁用行内编辑操作按钮回调方法",
4706+
"DisableExtendDeleteButtonAttr": "是否禁用行内删除操作按钮",
4707+
"DisableExtendDeleteButtonCallbackAttr": "是否禁用行内删除操作按钮回调方法",
47024708
"ShowUnsetGroupItemsOnTopAttr": "未分组编辑项是否在开头渲染",
47034709
"ShowSkeletonAttr": "首次加载时是否显示骨架屏",
47044710
"ShowLoadingInFirstRenderAttr": "首次加载时是否显示加载动画",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>8.2.3-beta02</Version>
4+
<Version>8.2.3-beta03</Version>
55
</PropertyGroup>
66

77
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,17 +869,16 @@
869869
}
870870
else
871871
{
872-
<Button Size="Size.ExtraSmall" OnClick="() => ClickEditButton(item)" Icon="@EditButtonIcon" Text="@EditButtonText"></Button>
872+
<Button Size="Size.ExtraSmall" OnClick="() => ClickEditButton(item)" IsDisabled="GetEditButtonDisabledState(item)" Icon="@EditButtonIcon" Text="@EditButtonText"></Button>
873873
}
874874
}
875875
@if (!isInCell && GetShowExtendDeleteButton(item))
876876
{
877877
<PopConfirmButton Placement="Placement.Left" Size="Size.ExtraSmall"
878-
Color="Color.Danger" Icon="@DeleteButtonIcon" Text="@DeleteButtonText"
878+
Color="Color.Danger" Icon="@DeleteButtonIcon" Text="@DeleteButtonText" IsDisabled="GetDeleteButtonDisabledState(item)"
879879
CloseButtonText="@CancelDeleteButtonText" Content="@ConfirmDeleteContentText"
880880
ConfirmButtonColor="Color.Danger" ConfirmButtonText="@ConfirmDeleteButtonText"
881-
OnBeforeClick="@ClickBeforeDelete(item)"
882-
OnConfirm="DeleteAsync" />
881+
OnBeforeClick="@ClickBeforeDelete(item)" OnConfirm="DeleteAsync" />
883882
}
884883
@if (!isInCell)
885884
{

src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ private async Task ClickEditButton(TItem item)
618618
await EditAsync();
619619
}
620620

621+
private bool GetEditButtonDisabledState(TItem item) => DisableExtendEditButtonCallback?.Invoke(item) ?? DisableExtendEditButton;
622+
623+
private bool GetDeleteButtonDisabledState(TItem item) => DisableExtendDeleteButtonCallback?.Invoke(item) ?? DisableExtendDeleteButton;
624+
621625
private async Task ClickUpdateButtonCallback()
622626
{
623627
var context = new EditContext(EditModel);

src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,30 @@ public partial class Table<TItem>
195195
[Parameter]
196196
public Func<TItem, bool>? ShowExtendEditButtonCallback { get; set; }
197197

198+
/// <summary>
199+
/// 获得/设置 是否禁用行内扩展编辑按钮 默认 false 不禁用
200+
/// </summary>
201+
[Parameter]
202+
public bool DisableExtendEditButton { get; set; }
203+
204+
/// <summary>
205+
/// 获得/设置 是否禁用行内扩展编辑按钮 默认为 null 未设置时使用 <see cref="DisableExtendEditButton"/> 值
206+
/// </summary>
207+
[Parameter]
208+
public Func<TItem, bool>? DisableExtendEditButtonCallback { get; set; }
209+
210+
/// <summary>
211+
/// 获得/设置 是否禁用行内扩展删除按钮 默认 false 不禁用
212+
/// </summary>
213+
[Parameter]
214+
public bool DisableExtendDeleteButton { get; set; }
215+
216+
/// <summary>
217+
/// 获得/设置 是否禁用行内扩展删除按钮 默认为 null 未设置时使用 <see cref="DisableExtendDeleteButton"/> 值
218+
/// </summary>
219+
[Parameter]
220+
public Func<TItem, bool>? DisableExtendDeleteButtonCallback { get; set; }
221+
198222
/// <summary>
199223
/// 获得/设置 是否显示行内扩展编辑按钮 默认为 null 未设置时使用 <see cref="ShowExtendEditButton"/> 值
200224
/// </summary>

test/UnitTest/Components/TableTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5951,6 +5951,7 @@ public void ShowExtendEditButton_Ok()
59515951
pb.Add(a => a.ExtendButtonColumnWidth, 130);
59525952
pb.Add(a => a.ShowExtendButtons, true);
59535953
pb.Add(a => a.ShowExtendEditButton, true);
5954+
pb.Add(a => a.DisableExtendEditButton, false);
59545955
pb.Add(a => a.TableColumns, foo => builder =>
59555956
{
59565957
builder.OpenComponent<TableColumn<Foo, string>>(0);
@@ -5975,8 +5976,12 @@ public void ShowExtendEditButton_Ok()
59755976
pb.Add(a => a.ShowExtendEditButton, true);
59765977
pb.Add(a => a.ShowDefaultButtons, false);
59775978
pb.Add(a => a.ShowExtendEditButtonCallback, foo => true);
5979+
pb.Add(a => a.DisableExtendEditButtonCallback, foo => true);
59785980
});
59795981
Assert.Contains("fa-regular fa-pen-to-square", table.Find("tbody").ToMarkup());
5982+
5983+
var button = table.Find("tbody tr:first-child .btn-primary");
5984+
Assert.Contains("disabled=\"disabled\"", button.OuterHtml);
59805985
}
59815986

59825987
[Fact]
@@ -5993,6 +5998,7 @@ public void ShowExtendDeleteButton_Ok()
59935998
pb.Add(a => a.ShowToolbar, true);
59945999
pb.Add(a => a.ShowExtendButtons, true);
59956000
pb.Add(a => a.ShowExtendDeleteButton, true);
6001+
pb.Add(a => a.DisableExtendDeleteButton, false);
59966002
pb.Add(a => a.TableColumns, foo => builder =>
59976003
{
59986004
builder.OpenComponent<TableColumn<Foo, string>>(0);
@@ -6017,8 +6023,12 @@ public void ShowExtendDeleteButton_Ok()
60176023
pb.Add(a => a.ShowExtendDeleteButton, true);
60186024
pb.Add(a => a.ShowDefaultButtons, false);
60196025
pb.Add(a => a.ShowExtendDeleteButtonCallback, foo => true);
6026+
pb.Add(a => a.DisableExtendDeleteButtonCallback, foo => true);
60206027
});
60216028
Assert.Contains("fa-solid fa-xmark", table.Find("tbody").ToMarkup());
6029+
6030+
var button = table.Find("tbody tr:first-child .btn-danger");
6031+
Assert.Contains("pop-confirm disabled", button.OuterHtml);
60226032
}
60236033

60246034
[Theory]

test/UnitTest/Components/UploadTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
359359
new()
360360
})));
361361
cut.DoesNotContain("cancel-icon");
362+
363+
cut.SetParametersAndRender(pb =>
364+
{
365+
pb.Add(a => a.Size, Size.ExtraSmall);
366+
});
367+
cut.Contains("btn-xs");
362368
}
363369

364370
[Fact]

0 commit comments

Comments
 (0)