Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ITableColumn): add GetTooltipText method #4889

Merged
merged 9 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" Text="@Localizer["TablesWrapDataResizingColumHeaderText_DateTime"]" />
<TableColumn @bind-Field="@context.Name" Text="@Localizer["TablesWrapDataResizingColumHeaderText_Name"]" />
<TableColumn @bind-Field="@context.Address" Text="@Localizer["TablesWrapDataResizingColumHeaderText_Address"]" Width="200" TextEllipsis="true" ShowTips="true" GetTooltipTextCallback="GetTooltipTextCallback" />
<TableColumn @bind-Field="@context.Address" Text="@Localizer["TablesWrapDataResizingColumHeaderText_Address"]" Width="200" TextEllipsis="true" ShowTips="true" GetTooltipText="GetTooltipText" />
<TableColumn @bind-Field="@context.Education" />
<TableColumn @bind-Field="@context.Count" />
<TableColumn @bind-Field="@context.Complete" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
return Task.FromResult(new QueryData<Foo>() { Items = items, TotalCount = total, IsSorted = true, IsFiltered = true, IsSearch = true });
}

private async Task<string?> GetTooltipTextCallback(object? v)
private static string? GetTooltipText(object? v)
{
await Task.Delay(0);

var ret = string.Empty;
if (v is Foo foo)
{
ret = $"{foo.Name}-{DateTime.Now}";
ret = $"{foo.Name}-{foo.Address}";
}
return ret;
}
Expand Down
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,15 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
/// <summary>
/// <inheritdoc/>
/// </summary>
[Obsolete("已弃用,请使用同步方法 GetTooltipText;Deprecated, please use the synchronous method GetTooltipText")]
[ExcludeFromCodeCoverage]
Func<object?, Task<string?>>? ITableColumn.GetTooltipTextCallback { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
Func<object?, string?>? ITableColumn.GetTooltipText { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/BootstrapBlazor/Components/Filters/LookupFilter.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ protected override async Task OnParametersSetAsync()
await base.OnParametersSetAsync();

var items = new List<SelectedItem>
{
new("", Localizer["EnumFilter.AllText"].Value)
};
{
new("", Localizer["EnumFilter.AllText"].Value)
};
if (Lookup != null)
{
items.AddRange(Lookup);
Expand Down
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Components/Table/ITableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ public interface ITableColumn : IEditorItem
/// <summary>
/// 获得/设置 鼠标悬停提示自定义内容回调委托 默认 null 使用当前值
/// </summary>
[Obsolete("已弃用,请使用同步方法 GetTooltipText;Deprecated, please use the synchronous method GetTooltipText")]
[ExcludeFromCodeCoverage]
Func<object?, Task<string?>>? GetTooltipTextCallback { get; set; }

/// <summary>
/// 获得/设置 鼠标悬停提示自定义内容回调委托 默认 null 使用当前值
/// </summary>
Func<object?, string?>? GetTooltipText { get; set; }

/// <summary>
/// 获得/设置 单元格回调方法
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/BootstrapBlazor/Components/Table/InternalTableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,18 @@ class InternalTableColumn(string fieldName, Type fieldType, string? fieldText =

public bool? ShowTips { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
[Obsolete("已弃用,请使用同步方法 GetTooltipText;Deprecated, please use the synchronous method GetTooltipText")]
[ExcludeFromCodeCoverage]
public Func<object?, Task<string?>>? GetTooltipTextCallback { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
public Func<object?, string?>? GetTooltipText { get; set; }

public Type PropertyType { get; } = fieldType;

[ExcludeFromCodeCoverage]
Expand Down
8 changes: 8 additions & 0 deletions src/BootstrapBlazor/Components/Table/TableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,16 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
/// <inheritdoc/>
/// </summary>
[Parameter]
[Obsolete("已弃用,请使用同步方法 GetTooltipText;Deprecated, please use the synchronous method GetTooltipText")]
[ExcludeFromCodeCoverage]
public Func<object?, Task<string?>>? GetTooltipTextCallback { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
[Parameter]
public Func<object?, string?>? GetTooltipText { get; set; }

/// <summary>
/// 获得/设置 列 td 自定义样式 默认为 null 未设置
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static void CopyValue(this ITableColumn col, ITableColumn dest)
if (col.IsVisibleWhenEdit.HasValue) dest.IsVisibleWhenEdit = col.IsVisibleWhenEdit;
if (col.IsReadonlyWhenAdd.HasValue) dest.IsReadonlyWhenAdd = col.IsReadonlyWhenAdd;
if (col.IsReadonlyWhenEdit.HasValue) dest.IsReadonlyWhenEdit = col.IsReadonlyWhenEdit;
if (col.GetTooltipTextCallback != null) dest.GetTooltipTextCallback = col.GetTooltipTextCallback;
if (col.GetTooltipText != null) dest.GetTooltipText = col.GetTooltipText;
if (col.CustomSearch != null) dest.CustomSearch = col.CustomSearch;
if (col.ToolboxTemplate != null) dest.ToolboxTemplate = col.ToolboxTemplate;
if (col.IsRequiredWhenAdd.HasValue) dest.IsRequiredWhenAdd = col.IsRequiredWhenAdd;
Expand Down Expand Up @@ -238,14 +238,14 @@ internal static RenderFragment RenderColor<TItem>(this ITableColumn col, TItem i
builder.CloseElement();
};

private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => async pb =>
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => pb =>
{
if (col.GetShowTips())
{
var tooltipText = text;
if (col.GetTooltipTextCallback != null)
if (col.GetTooltipText != null)
{
tooltipText = await col.GetTooltipTextCallback(item);
tooltipText = col.GetTooltipText(item);
}
pb.OpenComponent<Tooltip>(0);
pb.AddAttribute(1, nameof(Tooltip.Title), tooltipText);
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/Attributes/AutoGenerateClassTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public void AutoGenerateColumn_Ok()
attrInterface.IsReadonlyWhenEdit = true;
Assert.True(attrInterface.IsReadonlyWhenEdit);

attrInterface.GetTooltipTextCallback = _ => Task.FromResult((string?)"Test");
Assert.NotNull(attrInterface.GetTooltipTextCallback);
attrInterface.GetTooltipText = _ => "Test";
Assert.NotNull(attrInterface.GetTooltipText);

attrInterface.CustomSearch = (_, _) => new SearchFilterAction("test", "test");
Assert.NotNull(attrInterface.CustomSearch);
Expand Down
7 changes: 3 additions & 4 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ public void Column_IsFixedDetailColumn()

class MockTableColumn : AutoGenerateColumnAttribute
{
public new string GetFieldName() => "Test";
public static new string GetFieldName() => "Test";
}

[Fact]
Expand Down Expand Up @@ -4916,7 +4916,7 @@ public void ShowTips_Ok(bool markup)
}

[Fact]
public void GetTooltipTextCallback_Ok()
public void GetTooltipText_Ok()
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var items = Foo.GenerateFoo(localizer, 2);
Expand All @@ -4934,9 +4934,8 @@ public void GetTooltipTextCallback_Ok()
builder.AddAttribute(3, "Editable", true);
builder.AddAttribute(7, "Text", "test");
builder.AddAttribute(9, "ShowTips", true);
builder.AddAttribute(10, "GetTooltipTextCallback", new Func<object, Task<string?>>(async v =>
builder.AddAttribute(10, "GetTooltipText", new Func<object, string?>(v =>
{
await Task.Delay(0);
return "test-tips-callback";
}));
builder.CloseComponent();
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/Extensions/ITableColumnExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void CopyValue_Ok()
Step = "0.01",
Order = -1,
IsMarkupString = true,
GetTooltipTextCallback = _ => Task.FromResult<string?>(null),
GetTooltipText = _ => null,
CustomSearch = (_, _) => new SearchFilterAction("test", "test"),

Required = true,
Expand Down Expand Up @@ -169,7 +169,7 @@ public void CopyValue_Ok()
Assert.True(col.ShowCopyColumn);
Assert.Equal("0.01", col.Step);
Assert.Equal(-1, col.Order);
Assert.NotNull(col.GetTooltipTextCallback);
Assert.NotNull(col.GetTooltipText);
Assert.True(col.IsMarkupString);
Assert.NotNull(col.CustomSearch);

Expand Down
Loading