Skip to content

Commit 406eb5a

Browse files
ArgoZhangcqths
andauthored
feat(AutoGenerateColumnAttribute): remove Required parameter (#5416)
* refactor: 支持 Required 设置 * test: 更新单元测试 * refactor: 代码格式化 * refactor: 重构代码 * refactor: 屏蔽 IsRequiredWhenAdd/IsRequiredWhenEdit 设置 * test: 更新单元测试 * chore: bump version 9.3.1-beta27 Co-Authored-By: cqths <[email protected]> --------- Co-authored-by: cqths <[email protected]>
1 parent 1a219dc commit 406eb5a

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

src/BootstrapBlazor.Server/Data/Foo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public class Foo
109109
/// Generate Foo class, random data
110110
/// </summary>
111111
/// <returns>返回一个Foo类的List,Return a List of Foo class</returns>
112-
public static List<Foo> GenerateFoo(IStringLocalizer<Foo> localizer, int count = 80) => Enumerable.Range(1, count).Select(i => new Foo()
112+
public static List<Foo> GenerateFoo(IStringLocalizer<Foo> localizer, int count = 80) => [.. Enumerable.Range(1, count).Select(i => new Foo()
113113
{
114114
Id = i,
115115
Name = localizer["Foo.Name", $"{i:d4}"],
@@ -119,7 +119,7 @@ public class Foo
119119
Complete = Random.Shared.Next(1, 100) > 50,
120120
Education = Random.Shared.Next(1, 100) > 50 ? EnumEducation.Primary : EnumEducation.Middle,
121121
ReadonlyColumn = Random.Shared.Next(10, 50)
122-
}).ToList();
122+
})];
123123

124124
/// <summary>
125125
/// 生成 Foo 类 Hobbies 数据

src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,12 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
8181
set => IsVisibleWhenEdit = value ?? true;
8282
}
8383

84-
/// <summary>
85-
/// <inheritdoc/>
86-
/// </summary>
87-
public bool? Required { get; set; }
84+
bool? IEditorItem.Required { get; set; }
8885

89-
/// <summary>
90-
/// <inheritdoc/>
91-
/// </summary>
92-
public bool? IsRequiredWhenAdd { get; set; }
9386

94-
/// <summary>
95-
/// <inheritdoc/>
96-
/// </summary>
97-
public bool? IsRequiredWhenEdit { get; set; }
87+
bool? ITableColumn.IsRequiredWhenAdd { get; set; }
88+
89+
bool? ITableColumn.IsRequiredWhenEdit { get; set; }
9890

9991
/// <summary>
10092
/// <inheritdoc/>
@@ -109,7 +101,7 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
109101
bool? IEditorItem.ShowLabelTooltip
110102
{
111103
get => ShowLabelTooltip;
112-
set => ShowLabelTooltip = value.HasValue && value.Value;
104+
set => ShowLabelTooltip = value ?? false;
113105
}
114106

115107
/// <summary>

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>9.3.1-beta26</Version>
4+
<Version>9.3.1-beta27</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

test/UnitTest/Attributes/AutoGenerateClassTest.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ public void AutoGenerateColumn_Ok()
7070
HeaderTextWrap = true,
7171
IsMarkupString = true,
7272

73-
Required = true,
74-
RequiredErrorMessage = "test",
75-
IsRequiredWhenAdd = true,
76-
IsRequiredWhenEdit = true
73+
RequiredErrorMessage = "test"
7774
};
7875
Assert.Equal(1, attr.Order);
7976
Assert.True(attr.Ignore);
@@ -201,6 +198,11 @@ public void AutoGenerateColumn_Ok()
201198
attrInterface.ToolboxTemplate = col => builder => builder.AddContent(0, "test");
202199
Assert.NotNull(attrInterface.ToolboxTemplate);
203200

201+
attrInterface.IsRequiredWhenAdd = true;
202+
Assert.True(attrInterface.IsRequiredWhenAdd);
203+
attrInterface.IsRequiredWhenEdit = true;
204+
Assert.True(attrInterface.IsRequiredWhenEdit);
205+
204206
var attrEditor = (IEditorItem)attr;
205207
attrEditor.Items = null;
206208
Assert.Null(attrEditor.Items);
@@ -226,13 +228,13 @@ public void AutoGenerateColumn_Ok()
226228
attrEditor.LookupService = new LookupService();
227229
Assert.NotNull(attrEditor.LookupService);
228230

231+
attrEditor.Required = true;
232+
Assert.True(attrEditor.Required);
233+
229234
// 增加 GetDisplay 单元覆盖率
230235
attr.Text = null;
231236
Assert.Equal(string.Empty, attr.GetDisplayName());
232237

233-
Assert.True(attr.Required);
234-
Assert.True(attr.IsRequiredWhenEdit);
235-
Assert.True(attr.IsRequiredWhenAdd);
236238
Assert.Equal("test", attr.RequiredErrorMessage);
237239
}
238240

0 commit comments

Comments
 (0)