!3591 feat(#I655QS): add ShowSearchWhenSelect parameter on IEditItem

* feat: 支持自定义组件为 Select 是设置是否显示搜索框
* refactor: 重命名 ShowSearchWhenSelect
* chore: 更新 wasm 模式升级到 NET7
* test: 增加单元测试
* feat: 增加 ShowSearchWhenLookup 实现逻辑
* feat: 增加 ShowSearchWhenLookup 参数
* refactor: 格式化代码
This commit is contained in:
Argo 2022-12-07 12:00:02 +00:00
parent 66e6022e5f
commit 42f427bb58
13 changed files with 45 additions and 9 deletions

View File

@ -182,6 +182,11 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
/// </summary>
IEnumerable<SelectedItem>? IEditorItem.Lookup { get; set; }
/// <summary>
/// 获得/设置 字段数据源下拉框是否显示搜索栏 默认 false 不显示
/// </summary>
public bool ShowSearchWhenSelect { get; set; }
/// <summary>
/// 获得/设置 字典数据源字符串比较规则 默认 StringComparison.OrdinalIgnoreCase 大小写不敏感
/// </summary>

View File

@ -154,6 +154,12 @@ public class EditorItem<TValue> : ComponentBase, IEditorItem
[Parameter]
public IEnumerable<SelectedItem>? Lookup { get; set; }
/// <summary>
/// 获得/设置 字段数据源下拉框是否显示搜索栏 默认 false 不显示
/// </summary>
[Parameter]
public bool ShowSearchWhenSelect { get; set; }
/// <summary>
/// 获得/设置 字典数据源字符串比较规则 默认 StringComparison.OrdinalIgnoreCase 大小写不敏感
/// </summary>

View File

@ -90,6 +90,11 @@ public interface IEditorItem
/// </summary>
IEnumerable<SelectedItem>? Lookup { get; set; }
/// <summary>
/// 获得/设置 字段数据源下拉框是否显示搜索栏 默认 false 不显示
/// </summary>
bool ShowSearchWhenSelect { get; set; }
/// <summary>
/// 获得/设置 字典数据源字符串比较规则 默认 StringComparison.OrdinalIgnoreCase 大小写不敏感
/// </summary>

View File

@ -11,7 +11,6 @@
{
<GoTop Target="@Target"></GoTop>
}
}
else
{

View File

@ -121,6 +121,11 @@ internal class InternalTableColumn : ITableColumn
/// </summary>
public IEnumerable<SelectedItem>? Lookup { get; set; }
/// <summary>
/// 获得/设置 字段数据源下拉框是否显示搜索栏 默认 false 不显示
/// </summary>
public bool ShowSearchWhenSelect { get; set; }
/// <summary>
/// 获得/设置 字典数据源字符串比较规则 默认 StringComparison.OrdinalIgnoreCase 大小写不敏感
/// </summary>

View File

@ -345,6 +345,12 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
[Parameter]
public IEnumerable<SelectedItem>? Lookup { get; set; }
/// <summary>
/// 获得/设置 字段数据源下拉框是否显示搜索栏 默认 false 不显示
/// </summary>
[Parameter]
public bool ShowSearchWhenSelect { get; set; }
/// <summary>
/// 获得/设置 字典数据源字符串比较规则 默认 StringComparison.OrdinalIgnoreCase 大小写不敏感
/// </summary>

View File

@ -41,6 +41,7 @@ public static class IEditItemExtensions
if (source.EditTemplate != null) dest.EditTemplate = source.EditTemplate;
if (source.Items != null) dest.Items = source.Items;
if (source.Lookup != null) dest.Lookup = source.Lookup;
if (source.ShowSearchWhenSelect) dest.ShowSearchWhenSelect = source.ShowSearchWhenSelect;
if (source.LookupStringComparison != StringComparison.OrdinalIgnoreCase) dest.LookupStringComparison = source.LookupStringComparison;
if (source.LookupServiceKey != null) dest.LookupServiceKey = source.LookupServiceKey;
if (source.IsReadonlyWhenAdd) dest.IsReadonlyWhenAdd = source.IsReadonlyWhenAdd;

View File

@ -391,7 +391,7 @@ public static class Utility
// Lookup
if (lookup != null && item.Items == null)
{
builder.AddAttribute(11, nameof(Select<SelectedItem>.ShowSearch), true);
builder.AddAttribute(11, nameof(Select<SelectedItem>.ShowSearch), item.ShowSearchWhenSelect);
builder.AddAttribute(12, nameof(Select<SelectedItem>.Items), lookup.Clone());
builder.AddAttribute(13, nameof(Select<SelectedItem>.StringComparison), item.LookupStringComparison);
}
@ -400,25 +400,26 @@ public static class Utility
if (item.Items != null && item.ComponentType == typeof(Select<>).MakeGenericType(fieldType))
{
builder.AddAttribute(14, nameof(Select<SelectedItem>.Items), item.Items.Clone());
builder.AddAttribute(15, nameof(Select<SelectedItem>.ShowSearch), item.ShowSearchWhenSelect);
}
// 设置 SkipValidate 参数
if (IsValidatableComponent(componentType))
{
builder.AddAttribute(15, nameof(IEditorItem.SkipValidate), item.SkipValidate);
builder.AddAttribute(16, nameof(IEditorItem.SkipValidate), item.SkipValidate);
}
builder.AddMultipleAttributes(16, CreateMultipleAttributes(fieldType, model, fieldName, item));
builder.AddMultipleAttributes(17, CreateMultipleAttributes(fieldType, model, fieldName, item));
if (item.ComponentParameters != null)
{
builder.AddMultipleAttributes(17, item.ComponentParameters);
builder.AddMultipleAttributes(18, item.ComponentParameters);
}
// 设置 IsPopover
if (componentType.GetPropertyByName(nameof(Select<string>.IsPopover)) != null)
{
builder.AddAttribute(18, nameof(Select<string>.IsPopover), true);
builder.AddAttribute(19, nameof(Select<string>.IsPopover), true);
}
builder.CloseComponent();
}

View File

@ -6,9 +6,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.*" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="6.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.*" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="7.*" />
</ItemGroup>
<ItemGroup>

View File

@ -136,5 +136,8 @@ public class AutoGenerateClassTest
attrEditor.ValidateRules = null;
Assert.Null(attrEditor.ValidateRules);
attrEditor.ShowSearchWhenSelect = true;
Assert.True(attrEditor.ShowSearchWhenSelect);
}
}

View File

@ -284,6 +284,7 @@ public class EditorFormTest : BootstrapBlazorTestBase
new("True", "Test-True"),
new("False", "Test-False")
});
builder.AddAttribute(index++, nameof(EditorItem<Foo, bool>.ShowSearchWhenSelect), false);
builder.CloseComponent();
});
});

View File

@ -3316,6 +3316,7 @@ public class TableTest : TableTestBase
builder.AddAttribute(26, "ValidateRules", new List<IValidator>());
builder.AddAttribute(27, "GroupName", "test");
builder.AddAttribute(28, "GroupOrder", 1);
builder.AddAttribute(29, "ShowSearchWhenLookup", true);
builder.CloseComponent();
});
});
@ -3347,6 +3348,7 @@ public class TableTest : TableTestBase
Assert.NotNull(column.Instance.ValidateRules);
Assert.Equal("test", column.Instance.GroupName);
Assert.Equal(1, column.Instance.GroupOrder);
Assert.True(column.Instance.ShowSearchWhenSelect);
var col = column.Instance as ITableColumn;
Assert.NotNull(col.Template);

View File

@ -97,6 +97,8 @@ internal class MockTableColumn : ITableColumn
public IEnumerable<SelectedItem>? Lookup { get; set; }
public bool ShowSearchWhenSelect { get; set; }
public StringComparison LookupStringComparison { get; set; } = StringComparison.OrdinalIgnoreCase;
public string? LookupServiceKey { get; set; }