Skip to content

Commit 06ed5f0

Browse files
authored
fix(ITableColumn): add GetTooltipText method (#4889)
* doc: 代码格式化 * refactor: 增加 GetTooltipText 属性 * doc: 更新示例 * test: 更新单元测试 * refactor: 消除警告信息 * test: 提高代码覆盖率 * refactor: 重构代码 * doc: 更新文档 * doc: 更新文档
1 parent 578c404 commit 06ed5f0

File tree

15 files changed

+54
-25
lines changed

15 files changed

+54
-25
lines changed

src/BootstrapBlazor.Server/Components/Samples/Table/TablesWrap.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<TableColumns>
7272
<TableColumn @bind-Field="@context.DateTime" Width="180" Text="@Localizer["TablesWrapDataResizingColumHeaderText_DateTime"]" />
7373
<TableColumn @bind-Field="@context.Name" Text="@Localizer["TablesWrapDataResizingColumHeaderText_Name"]" />
74-
<TableColumn @bind-Field="@context.Address" Text="@Localizer["TablesWrapDataResizingColumHeaderText_Address"]" Width="200" TextEllipsis="true" ShowTips="true" GetTooltipTextCallback="GetTooltipTextCallback" />
74+
<TableColumn @bind-Field="@context.Address" Text="@Localizer["TablesWrapDataResizingColumHeaderText_Address"]" Width="200" TextEllipsis="true" ShowTips="true" GetTooltipText="GetTooltipText" />
7575
<TableColumn @bind-Field="@context.Education" />
7676
<TableColumn @bind-Field="@context.Count" />
7777
<TableColumn @bind-Field="@context.Complete" />

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
3838
return Task.FromResult(new QueryData<Foo>() { Items = items, TotalCount = total, IsSorted = true, IsFiltered = true, IsSearch = true });
3939
}
4040

41-
private async Task<string?> GetTooltipTextCallback(object? v)
41+
private static string? GetTooltipText(object? v)
4242
{
43-
await Task.Delay(0);
44-
4543
var ret = string.Empty;
4644
if (v is Foo foo)
4745
{
48-
ret = $"{foo.Name}-{DateTime.Now}";
46+
ret = $"{foo.Name}-{foo.Address}";
4947
}
5048
return ret;
5149
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5265,7 +5265,7 @@
52655265
"TablesWrapDataResizingTips1": "You can drag the window size, and the <b>address</b> column will be automatically omitted if the window is too small",
52665266
"TablesWrapDataResizingTips2": "Enable text ellipsis by setting <code>TextEllipsis</code>",
52675267
"TablesWrapDataResizingTips3": "<b>Note:</b> It is recommended to use <code>Width</code> to set the column width. If the column width is not set, it will automatically use 200px width inside",
5268-
"TablesWrapDataResizingTips4": "After the text in the cell is omitted, you can use the <code>ShowTips</code> property to control whether to display all the text on mouse hover, the default is <code>false</code>, You can customize the display content of <code>Tooltip</code> by setting the <code>GetTooltipTextCallback</code> callback method",
5268+
"TablesWrapDataResizingTips4": "After the text in the cell is omitted, you can use the <code>ShowTips</code> property to control whether to display all the text on mouse hover, the default is <code>false</code>, You can customize the display content of <code>Tooltip</code> by setting the <code>GetTooltipText</code> callback method",
52695269
"TablesWrapDataResizingTips5": "Drag the address column, the cell display content will automatically increase and decrease",
52705270
"TablesWrapCustomCellTitle": "Custom in-cell typography",
52715271
"TablesWrapCustomCellIntro": "Use templates for special layout of in-cell data",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5265,7 +5265,7 @@
52655265
"TablesWrapDataResizingTips1": "可以拖动窗口大小,窗口过小时 <b>地址</b> 列自动进行省略处理",
52665266
"TablesWrapDataResizingTips2": "通过设置 <code>TextEllipsis</code> 来开启文本超长省略功能",
52675267
"TablesWrapDataResizingTips3": "<b>注意:</b>推荐使用 <code>Width</code> 对列宽度进行设置,如未设置列宽内部自动使用 200px 宽度",
5268-
"TablesWrapDataResizingTips4": "单元格内文本被省略后,可以通过 <code>ShowTips</code> 属性来控制鼠标悬停是否显示全部文本,默认为 <code>false</code>,通过设置 <code>GetTooltipTextCallback</code> 回调方法可以自定义 <code>Tooltip</code> 显示内容",
5268+
"TablesWrapDataResizingTips4": "单元格内文本被省略后,可以通过 <code>ShowTips</code> 属性来控制鼠标悬停是否显示全部文本,默认为 <code>false</code>,通过设置 <code>GetTooltipText</code> 回调方法可以自定义 <code>Tooltip</code> 显示内容;注意异步方法 <code>GetTooltipTextCallback</code> 已弃用请勿使用",
52695269
"TablesWrapDataResizingTips5": "拖动地址列,单元格显示内容自动增加与减少",
52705270
"TablesWrapCustomCellTitle": "自定义单元格内排版",
52715271
"TablesWrapCustomCellIntro": "使用模板对单元格内数据进行特殊布局",

src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,15 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
203203
/// <summary>
204204
/// <inheritdoc/>
205205
/// </summary>
206+
[Obsolete("已弃用,请使用同步方法 GetTooltipText;Deprecated, please use the synchronous method GetTooltipText")]
207+
[ExcludeFromCodeCoverage]
206208
Func<object?, Task<string?>>? ITableColumn.GetTooltipTextCallback { get; set; }
207209

210+
/// <summary>
211+
/// <inheritdoc/>
212+
/// </summary>
213+
Func<object?, string?>? ITableColumn.GetTooltipText { get; set; }
214+
208215
/// <summary>
209216
/// <inheritdoc/>
210217
/// </summary>

src/BootstrapBlazor/Components/Filters/LookupFilter.razor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ protected override async Task OnParametersSetAsync()
9696
await base.OnParametersSetAsync();
9797

9898
var items = new List<SelectedItem>
99-
{
100-
new("", Localizer["EnumFilter.AllText"].Value)
101-
};
99+
{
100+
new("", Localizer["EnumFilter.AllText"].Value)
101+
};
102102
if (Lookup != null)
103103
{
104104
items.AddRange(Lookup);

src/BootstrapBlazor/Components/Table/ITableColumn.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,15 @@ public interface ITableColumn : IEditorItem
143143
/// <summary>
144144
/// 获得/设置 鼠标悬停提示自定义内容回调委托 默认 null 使用当前值
145145
/// </summary>
146+
[Obsolete("已弃用,请使用同步方法 GetTooltipText;Deprecated, please use the synchronous method GetTooltipText")]
147+
[ExcludeFromCodeCoverage]
146148
Func<object?, Task<string?>>? GetTooltipTextCallback { get; set; }
147149

150+
/// <summary>
151+
/// 获得/设置 鼠标悬停提示自定义内容回调委托 默认 null 使用当前值
152+
/// </summary>
153+
Func<object?, string?>? GetTooltipText { get; set; }
154+
148155
/// <summary>
149156
/// 获得/设置 单元格回调方法
150157
/// </summary>

src/BootstrapBlazor/Components/Table/InternalTableColumn.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,18 @@ class InternalTableColumn(string fieldName, Type fieldType, string? fieldText =
133133

134134
public bool? ShowTips { get; set; }
135135

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

143+
/// <summary>
144+
/// <inheritdoc/>
145+
/// </summary>
146+
public Func<object?, string?>? GetTooltipText { get; set; }
147+
138148
public Type PropertyType { get; } = fieldType;
139149

140150
[ExcludeFromCodeCoverage]

src/BootstrapBlazor/Components/Table/TableColumn.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,16 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
269269
/// <inheritdoc/>
270270
/// </summary>
271271
[Parameter]
272+
[Obsolete("已弃用,请使用同步方法 GetTooltipText;Deprecated, please use the synchronous method GetTooltipText")]
273+
[ExcludeFromCodeCoverage]
272274
public Func<object?, Task<string?>>? GetTooltipTextCallback { get; set; }
273275

276+
/// <summary>
277+
/// <inheritdoc/>
278+
/// </summary>
279+
[Parameter]
280+
public Func<object?, string?>? GetTooltipText { get; set; }
281+
274282
/// <summary>
275283
/// 获得/设置 列 td 自定义样式 默认为 null 未设置
276284
/// </summary>

src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private static void CopyValue(this ITableColumn col, ITableColumn dest)
105105
if (col.IsVisibleWhenEdit.HasValue) dest.IsVisibleWhenEdit = col.IsVisibleWhenEdit;
106106
if (col.IsReadonlyWhenAdd.HasValue) dest.IsReadonlyWhenAdd = col.IsReadonlyWhenAdd;
107107
if (col.IsReadonlyWhenEdit.HasValue) dest.IsReadonlyWhenEdit = col.IsReadonlyWhenEdit;
108-
if (col.GetTooltipTextCallback != null) dest.GetTooltipTextCallback = col.GetTooltipTextCallback;
108+
if (col.GetTooltipText != null) dest.GetTooltipText = col.GetTooltipText;
109109
if (col.CustomSearch != null) dest.CustomSearch = col.CustomSearch;
110110
if (col.ToolboxTemplate != null) dest.ToolboxTemplate = col.ToolboxTemplate;
111111
if (col.IsRequiredWhenAdd.HasValue) dest.IsRequiredWhenAdd = col.IsRequiredWhenAdd;
@@ -238,14 +238,14 @@ internal static RenderFragment RenderColor<TItem>(this ITableColumn col, TItem i
238238
builder.CloseElement();
239239
};
240240

241-
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => async pb =>
241+
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => pb =>
242242
{
243243
if (col.GetShowTips())
244244
{
245245
var tooltipText = text;
246-
if (col.GetTooltipTextCallback != null)
246+
if (col.GetTooltipText != null)
247247
{
248-
tooltipText = await col.GetTooltipTextCallback(item);
248+
tooltipText = col.GetTooltipText(item);
249249
}
250250
pb.OpenComponent<Tooltip>(0);
251251
pb.AddAttribute(1, nameof(Tooltip.Title), tooltipText);

0 commit comments

Comments
 (0)