Skip to content

Commit 9b67ccc

Browse files
authored
feat(BootstrapBlazorRoot): add ShowErrorLoggerToast parameter (#7485)
* refactor: 方法重命名 * refactor: 属性排序 * refactor: 使用可为空参数更新相应逻辑 * refactor: 重命名 ShowToast 参数 * test: 更新单元测试 * refactor: 移除默认值 * doc: 更新注释文档 * test: 更新单元测试
1 parent bbaa32e commit 9b67ccc

14 files changed

Lines changed: 114 additions & 62 deletions

src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
@inherits ComponentBase
1+
@inherits ComponentBase
22
@namespace BootstrapBlazor.Components
33

44
<CascadingValue Value="this" IsFixed="true">
5-
<ErrorLogger EnableErrorLogger="EnableErrorLoggerValue" ShowToast="ShowToastValue" ToastTitle="@ToastTitle"
5+
<ErrorLogger EnableErrorLogger="EnableErrorLoggerValue" EnableILogger="EnableErrorLoggerILoggerValue"
6+
ShowToast="ShowToastValue" ToastTitle="@ToastTitle"
67
OnErrorHandleAsync="OnErrorHandleAsync">
78
@ChildContent
89

src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -42,16 +42,30 @@ public partial class BootstrapBlazorRoot
4242
public ToastContainer? ToastContainer { get; private set; }
4343

4444
/// <summary>
45-
/// 获得/设置 自定义错误处理回调方法
45+
/// 获得/设置 是否开启全局异常捕获 默认 null 使用 <see cref="BootstrapBlazorOptions.EnableErrorLogger"/> 设置值
4646
/// </summary>
4747
[Parameter]
48-
public Func<ILogger, Exception, Task>? OnErrorHandleAsync { get; set; }
48+
public bool? EnableErrorLogger { get; set; }
49+
50+
/// <summary>
51+
/// 获得/设置 是否记录异常到 <see cref="ILogger"/> 默认 null 使用 <see cref="BootstrapBlazorOptions.EnableErrorLoggerILogger"/> 设置值
52+
/// </summary>
53+
[Parameter]
54+
public bool? EnableErrorLoggerILogger { get; set; }
55+
56+
/// <summary>
57+
/// 获得/设置 是否显示 Error 提示弹窗 默认 null 使用 <see cref="BootstrapBlazorOptions.ShowErrorLoggerToast"/> 设置值
58+
/// </summary>
59+
[Parameter]
60+
[Obsolete("已弃用,请使用 ShowErrorLoggerToast 参数. Deprecated, please use ShowErrorLoggerToast parameter")]
61+
[ExcludeFromCodeCoverage]
62+
public bool? ShowToast { get => ShowErrorLoggerToast; set => ShowErrorLoggerToast = value; }
4963

5064
/// <summary>
5165
/// 获得/设置 是否显示 Error 提示弹窗 默认 null 使用 <see cref="BootstrapBlazorOptions.ShowErrorLoggerToast"/> 设置值
5266
/// </summary>
5367
[Parameter]
54-
public bool? ShowToast { get; set; }
68+
public bool? ShowErrorLoggerToast { get; set; }
5569

5670
/// <summary>
5771
/// 获得/设置 Error Toast 弹窗标题
@@ -60,17 +74,19 @@ public partial class BootstrapBlazorRoot
6074
public string? ToastTitle { get; set; }
6175

6276
/// <summary>
63-
/// 获得/设置 是否开启全局异常捕获 默认 null 读取配置文件 EnableErrorLogger 值
77+
/// 获得/设置 自定义错误处理回调方法
6478
/// </summary>
6579
[Parameter]
66-
public bool? EnableErrorLogger { get; set; }
80+
public Func<ILogger, Exception, Task>? OnErrorHandleAsync { get; set; }
6781

6882
private bool EnableErrorLoggerValue => EnableErrorLogger ?? Options.CurrentValue.EnableErrorLogger;
6983

70-
private bool ShowToastValue => ShowToast ?? Options.CurrentValue.ShowErrorLoggerToast;
84+
private bool EnableErrorLoggerILoggerValue => EnableErrorLoggerILogger ?? Options.CurrentValue.EnableErrorLoggerILogger;
85+
86+
private bool ShowToastValue => ShowErrorLoggerToast ?? Options.CurrentValue.ShowErrorLoggerToast;
7187

7288
/// <summary>
73-
/// SetParametersAsync 方法
89+
/// <inheritdoc/>
7490
/// </summary>
7591
/// <param name="parameters"></param>
7692
/// <returns></returns>

src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -43,16 +43,16 @@ class BootstrapBlazorErrorBoundary : ErrorBoundaryBase
4343
public Func<ILogger, Exception, Task>? OnErrorHandleAsync { get; set; }
4444

4545
/// <summary>
46-
/// 获得/设置 是否显示弹窗 默认 true 显示
46+
/// 获得/设置 是否启用日志记录功能 默认 true 启用
4747
/// </summary>
4848
[Parameter]
49-
public bool ShowToast { get; set; } = true;
49+
public bool EnableILogger { get; set; } = true;
5050

5151
/// <summary>
52-
/// 获得/设置 是否启用日志记录功能 默认 true 启用
52+
/// 获得/设置 是否显示弹窗 默认 true 显示
5353
/// </summary>
5454
[Parameter]
55-
public bool EnableILogger { get; set; } = true;
55+
public bool ShowToast { get; set; } = true;
5656

5757
/// <summary>
5858
/// 获得/设置 Toast 弹窗标题
@@ -164,7 +164,7 @@ public async Task RenderException(Exception exception, IHandlerException? handle
164164
if (HostEnvironment.IsDevelopment())
165165
{
166166
// IHandlerException 处理异常逻辑
167-
await handler.HandlerException(exception, ExceptionContent);
167+
await handler.HandlerExceptionAsync(exception, ExceptionContent);
168168
}
169169
else
170170
{

src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public class ErrorLogger : ComponentBase, IErrorLogger
2828
/// <inheritdoc/>
2929
/// </summary>
3030
[Parameter]
31-
public bool ShowToast { get; set; } = true;
31+
public bool EnableILogger { get; set; } = true;
3232

3333
/// <summary>
3434
/// <inheritdoc/>
3535
/// </summary>
3636
[Parameter]
37-
public bool EnableILogger { get; set; } = true;
37+
public bool ShowToast { get; set; } = true;
3838

3939
/// <summary>
4040
/// <inheritdoc/>
@@ -44,7 +44,7 @@ public class ErrorLogger : ComponentBase, IErrorLogger
4444
public string? ToastTitle { get; set; }
4545

4646
/// <summary>
47-
/// <inheritdoc/>
47+
/// 获得/设置 自定义错误处理回调方法
4848
/// </summary>
4949
[Parameter]
5050
public Func<ILogger, Exception, Task>? OnErrorHandleAsync { get; set; }

src/BootstrapBlazor/Components/ErrorLogger/IErrorLogger.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -16,27 +16,26 @@ public interface IErrorLogger
1616
bool EnableErrorLogger { get; set; }
1717

1818
/// <summary>
19-
/// 获得/设置 自定义 Error 处理方法 默认 null
19+
/// 获得/设置 是否启用日志记录功能 默认 true 启用
20+
/// <para>设置 false 后关闭记录日志功能</para>
2021
/// </summary>
21-
/// <param name="ex"></param>
22-
/// <returns></returns>
23-
Task HandlerExceptionAsync(Exception ex);
22+
bool EnableILogger { get; }
2423

2524
/// <summary>
2625
/// 获得 是否显示 Error 提示弹窗 默认 true
2726
/// </summary>
2827
bool ShowToast { get; }
2928

3029
/// <summary>
31-
/// 获得/设置 是否启用日志记录功能 默认 true 启用
32-
/// <para>设置 false 后关闭记录日志功能</para>
30+
/// 获得 Error Toast 弹窗标题 默认读取资源文件内容
3331
/// </summary>
34-
bool EnableILogger { get; }
32+
string? ToastTitle { get; }
3533

3634
/// <summary>
37-
/// 获得 Error Toast 弹窗标题 默认读取资源文件内容
35+
/// 获得/设置 自定义 Error 处理方法 默认 null
3836
/// </summary>
39-
string? ToastTitle { get; }
37+
/// <param name="ex"></param>
38+
Task HandlerExceptionAsync(Exception ex);
4039

4140
/// <summary>
4241
/// 注册方法
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
55

66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
/// IHandlerException
9+
/// IHandlerException 接口
1010
/// </summary>
1111
public interface IHandlerException
1212
{
1313
/// <summary>
14-
///
14+
/// 处理异常方法
1515
/// </summary>
1616
/// <param name="ex"></param>
1717
/// <param name="errorContent"></param>
18-
Task HandlerException(Exception ex, RenderFragment<Exception> errorContent);
18+
Task HandlerExceptionAsync(Exception ex, RenderFragment<Exception> errorContent);
1919
}

src/BootstrapBlazor/Components/Layout/Layout.razor

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@namespace BootstrapBlazor.Components
1+
@namespace BootstrapBlazor.Components
22
@inherits BootstrapModuleComponentBase
33
@attribute [BootstrapModuleAutoLoader(JSObjectReference = true)]
44

@@ -126,8 +126,9 @@
126126
}
127127
else
128128
{
129-
<ErrorLogger EnableErrorLogger="@EnableLogger" ShowToast="@ShowToast" ToastTitle="@ErrorLoggerToastTitle"
130-
EnableILogger="@EnableILogger" OnErrorHandleAsync="OnErrorHandleAsync" OnInitializedCallback="OnErrorLoggerInitialized">
129+
<ErrorLogger EnableErrorLogger="@EnableLogger" EnableILogger="@EnableILogger"
130+
ShowToast="@ShowToast" ToastTitle="@ErrorLoggerToastTitle"
131+
OnErrorHandleAsync="OnErrorHandleAsync" OnInitializedCallback="OnErrorLoggerInitialized">
131132
@HandlerMain()
132133
</ErrorLogger>
133134
}

src/BootstrapBlazor/Components/Layout/Layout.razor.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -473,22 +473,22 @@ public partial class Layout : IHandlerException, ITabHeader
473473
public object? Resource { get; set; }
474474

475475
/// <summary>
476-
/// 获得/设置 是否开启全局异常捕获 默认 null 读取配置文件 EnableErrorLogger
476+
/// 获得/设置 是否开启全局异常捕获 默认 null 使用 <see cref="BootstrapBlazorOptions.EnableErrorLogger"/> 设置值
477477
/// </summary>
478478
[Parameter]
479479
public bool? EnableErrorLogger { get; set; }
480480

481481
/// <summary>
482-
/// 获得/设置 是否显示 Error 提示弹窗 默认 null 使用 <see cref="BootstrapBlazorOptions.ShowErrorLoggerToast"/> 设置值
482+
/// 获得/设置 是否记录异常到 <see cref="ILogger"/> 默认 null 使用 <see cref="BootstrapBlazorOptions.EnableErrorLoggerILogger"/> 设置值
483483
/// </summary>
484484
[Parameter]
485-
public bool? ShowErrorLoggerToast { get; set; }
485+
public bool? EnableErrorLoggerILogger { get; set; }
486486

487487
/// <summary>
488-
/// 获得/设置 是否启用日志记录功能 默认 null 启用 使用 <see cref="BootstrapBlazorOptions.EnableErrorLoggerILogger"/> 设置值
488+
/// 获得/设置 是否显示 Error 提示弹窗 默认 null 使用 <see cref="BootstrapBlazorOptions.ShowErrorLoggerToast"/> 设置值
489489
/// </summary>
490490
[Parameter]
491-
public bool? EnableErrorLoggerILogger { get; set; }
491+
public bool? ShowErrorLoggerToast { get; set; }
492492

493493
/// <summary>
494494
/// 获得/设置 错误日志 <see cref="Toast"/> 弹窗标题 默认 null
@@ -526,10 +526,10 @@ public partial class Layout : IHandlerException, ITabHeader
526526

527527
private bool EnableLogger => EnableErrorLogger ?? Options.CurrentValue.EnableErrorLogger;
528528

529-
private bool ShowToast => ShowErrorLoggerToast ?? Options.CurrentValue.ShowErrorLoggerToast;
530-
531529
private bool EnableILogger => EnableErrorLoggerILogger ?? Options.CurrentValue.EnableErrorLoggerILogger;
532530

531+
private bool ShowToast => ShowErrorLoggerToast ?? Options.CurrentValue.ShowErrorLoggerToast;
532+
533533
/// <summary>
534534
/// <inheritdoc/>
535535
/// </summary>
@@ -702,7 +702,7 @@ private Task OnErrorLoggerInitialized(ErrorLogger logger)
702702
/// </summary>
703703
/// <param name="ex"></param>
704704
/// <param name="errorContent"></param>
705-
public virtual Task HandlerException(Exception ex, RenderFragment<Exception> errorContent)
705+
public virtual Task HandlerExceptionAsync(Exception ex, RenderFragment<Exception> errorContent)
706706
{
707707
_errorContent = errorContent(ex);
708708
StateHasChanged();

src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -453,7 +453,7 @@ private RenderFragment RenderBodyTemplate() => builder =>
453453
/// </summary>
454454
/// <param name="ex"></param>
455455
/// <param name="errorContent"></param>
456-
public virtual Task HandlerException(Exception ex, RenderFragment<Exception> errorContent)
456+
public virtual Task HandlerExceptionAsync(Exception ex, RenderFragment<Exception> errorContent)
457457
{
458458
_errorContent = errorContent(ex);
459459
StateHasChanged();

src/BootstrapBlazor/Components/Tab/TabItemContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void Render()
8888
/// </summary>
8989
/// <param name="ex"></param>
9090
/// <param name="errorContent"></param>
91-
public Task HandlerException(Exception ex, RenderFragment<Exception> errorContent) => DialogService.ShowErrorHandlerDialog(errorContent(ex));
91+
public Task HandlerExceptionAsync(Exception ex, RenderFragment<Exception> errorContent) => DialogService.ShowErrorHandlerDialog(errorContent(ex));
9292

9393
/// <summary>
9494
/// IDispose 方法用于释放资源

0 commit comments

Comments
 (0)