-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bitfoundation:develop' into 7761-dotnet9-rc2
- Loading branch information
Showing
42 changed files
with
433 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
} | ||
</BitStack> | ||
|
||
<BitSpacer /> | ||
<DiagnosticSpacer /> | ||
|
||
<UserMenu /> | ||
</BitStack> | ||
|
55 changes: 55 additions & 0 deletions
55
...it.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/DiagnosticModal.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@inherits AppComponentBase | ||
|
||
<div> | ||
<BitModal @bind-IsOpen="isOpen" FullSize> | ||
<BitStack FillContent Class="container"> | ||
<BitStack Horizontal AutoHeight VerticalAlign="BitAlignment.Center"> | ||
<BitText Typography="BitTypography.H3">Diagnostic</BitText> | ||
<BitSpacer /> | ||
<BitButton IconOnly | ||
Color="BitColor.Info" | ||
Variant="BitVariant.Text" | ||
OnClick="() => isOpen = false" | ||
IconName="@BitIconName.ChromeClose" /> | ||
</BitStack> | ||
|
||
<BitStack Horizontal FitHeight Wrap> | ||
<BitSearchBox Immediate DebounceTime="500" OnChange="HandleOnSearchChange" /> | ||
<BitDropdown FitWidth IsMultiSelect | ||
Items="logLevelItems" | ||
DefaultValues="defaultFilterLogLevels" | ||
OnValuesChange="HandleOnLogLevelFilter" | ||
TItem="BitDropdownItem<LogLevel>" TValue="LogLevel" /> | ||
<BitButton IconOnly Color="BitColor.SecondaryBackground" Style="height:32px;" | ||
OnClick="HandleOnSortClick" | ||
IconName="@(isDescendingSort ? BitIconName.SortDown : BitIconName.SortUp)" /> | ||
</BitStack> | ||
|
||
<BitBasicList @ref="logStackRef" | ||
Style="height:unset" | ||
EnableVirtualization | ||
Items="filteredLogs.Indexed().ToArray()"> | ||
<EmptyContent>Nothing to show!</EmptyContent> | ||
<RowTemplate Context="logIndex"> | ||
<BitStack @key="logIndex.item.CreatedOn" Horizontal AutoHeight Gap="0"> | ||
<BitText Style="min-width:7rem">@($"{logIndex.index + 1}. [{logIndex.item.CreatedOn.ToString("HH:mm:ss")}]")</BitText> | ||
<BitButton IconOnly | ||
Title="Copy" | ||
Color="BitColor.Info" | ||
Variant="BitVariant.Text" | ||
IconName="@BitIconName.Copy" | ||
OnClick="() => CopyException(logIndex.item)" /> | ||
<BitText Style="white-space:nowrap" Color="GetColor(logIndex.item.Level)">@logIndex.item.Message</BitText> | ||
</BitStack> | ||
</RowTemplate> | ||
</BitBasicList> | ||
</BitStack> | ||
|
||
<BitButton IconOnly | ||
OnClick="GoTop" | ||
Color="BitColor.Info" | ||
Class="go-top-button" | ||
Variant="BitVariant.Text" | ||
IconName="@BitIconName.Up" /> | ||
</BitModal> | ||
</div> |
111 changes: 111 additions & 0 deletions
111
...Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/DiagnosticModal.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Boilerplate.Client.Core.Services.DiagnosticLog; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Boilerplate.Client.Core.Components.Layout; | ||
|
||
/// <summary> | ||
/// This modal can be opened by clicking 7 times on the spacer of the header or by pressing Ctrl+Shift+X. | ||
/// Also by calling `App.showDiagnostic` function using the dev-tools console. | ||
/// </summary> | ||
public partial class DiagnosticModal : IDisposable | ||
{ | ||
private bool isOpen; | ||
private string? searchText; | ||
private bool isDescendingSort; | ||
private Action unsubscribe = default!; | ||
private IEnumerable<LogLevel> filterLogLevels = []; | ||
private IEnumerable<DiagnosticLog> allLogs = default!; | ||
private IEnumerable<DiagnosticLog> filteredLogs = default!; | ||
private BitBasicList<(DiagnosticLog, int)> logStackRef = default!; | ||
private readonly LogLevel[] defaultFilterLogLevels = [LogLevel.Warning, LogLevel.Error, LogLevel.Critical]; | ||
private readonly BitDropdownItem<LogLevel>[] logLevelItems = Enum.GetValues<LogLevel>().Select(v => new BitDropdownItem<LogLevel>() { Value = v, Text = v.ToString() }).ToArray(); | ||
|
||
|
||
[AutoInject] private Clipboard clipboard = default!; | ||
|
||
|
||
protected override Task OnInitAsync() | ||
{ | ||
unsubscribe = PubSubService.Subscribe(PubSubMessages.SHOW_DIAGNOSTIC_MODAL, async _ => | ||
{ | ||
isOpen = true; | ||
allLogs = [.. DiagnosticLogger.Store]; | ||
HandleOnLogLevelFilter(defaultFilterLogLevels); | ||
await InvokeAsync(StateHasChanged); | ||
}); | ||
|
||
return base.OnInitAsync(); | ||
} | ||
|
||
|
||
private void HandleOnSearchChange(string? text) | ||
{ | ||
searchText = text; | ||
FilterLogs(); | ||
} | ||
|
||
private void HandleOnLogLevelFilter(BitDropdownItem<LogLevel>[] items) | ||
{ | ||
HandleOnLogLevelFilter(items.Select(i => i.Value)); | ||
} | ||
|
||
private void HandleOnLogLevelFilter(IEnumerable<LogLevel> logLevels) | ||
{ | ||
filterLogLevels = logLevels; | ||
FilterLogs(); | ||
} | ||
|
||
private void HandleOnSortClick() | ||
{ | ||
isDescendingSort = !isDescendingSort; | ||
FilterLogs(); | ||
} | ||
|
||
private void FilterLogs() | ||
{ | ||
filteredLogs = allLogs.WhereIf(string.IsNullOrEmpty(searchText) is false, l => l.Message?.Contains(searchText!, StringComparison.InvariantCultureIgnoreCase) is true) | ||
.Where(l => filterLogLevels.Contains(l.Level)); | ||
if (isDescendingSort) | ||
{ | ||
filteredLogs = filteredLogs.OrderByDescending(l => l.CreatedOn); | ||
} | ||
else | ||
{ | ||
filteredLogs = filteredLogs.OrderBy(l => l.CreatedOn); | ||
} | ||
} | ||
|
||
private async Task CopyException(DiagnosticLog log) | ||
{ | ||
var stateToCopy = string.Join(Environment.NewLine, log.State?.Select(i => $"{i.Key}: {i.Value}") ?? []); | ||
|
||
await clipboard.WriteText($"{log.Message}{Environment.NewLine}{log.Exception?.ToString()}{Environment.NewLine}{stateToCopy}"); | ||
} | ||
|
||
private async Task GoTop() | ||
{ | ||
await logStackRef.RootElement.Scroll(0, 0); | ||
} | ||
|
||
|
||
private static BitColor GetColor(LogLevel level) | ||
{ | ||
return level switch | ||
{ | ||
LogLevel.Trace => BitColor.PrimaryForeground, | ||
LogLevel.Debug => BitColor.PrimaryForeground, | ||
LogLevel.Information => BitColor.Primary, | ||
LogLevel.Warning => BitColor.Warning, | ||
LogLevel.Error => BitColor.Error, | ||
LogLevel.Critical => BitColor.Error, | ||
LogLevel.None => BitColor.SecondaryForeground, | ||
_ => BitColor.TertiaryForeground | ||
}; | ||
} | ||
|
||
|
||
public void Dispose() | ||
{ | ||
unsubscribe?.Invoke(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/DiagnosticModal.razor.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@import '../../Styles/abstracts/_media-queries.scss'; | ||
|
||
section { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
::deep { | ||
.container { | ||
padding: 1rem; | ||
} | ||
|
||
.stack { | ||
overflow: auto; | ||
} | ||
|
||
.go-top-button { | ||
left: 50%; | ||
position: fixed; | ||
transform: translateX(-50%); | ||
bottom: calc(var(--app-inset-bottom) + 1rem); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...t.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/DiagnosticSpacer.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@inherits AppComponentBase | ||
|
||
<BitSpacer @onclick="HandleOnClick" Style="height:100%" /> | ||
|
||
@code { | ||
private int clickCount = 0; | ||
private async Task HandleOnClick() | ||
{ | ||
if (++clickCount == 7) | ||
{ | ||
clickCount = 0; | ||
PubSubService.Publish(PubSubMessages.SHOW_DIAGNOSTIC_MODAL); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
</BitLink> | ||
} | ||
|
||
<BitSpacer /> | ||
<DiagnosticSpacer /> | ||
|
||
<BitButton IconOnly | ||
FixedColor | ||
|
4 changes: 4 additions & 0 deletions
4
...plate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/JsBridge.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@inherits AppComponentBase | ||
|
||
@* this component creates a bridge between the js code (app.ts) and the .net code | ||
that can easily be used to call any .net code from js without any hassle. *@ |
34 changes: 34 additions & 0 deletions
34
...te/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Layout/JsBridge.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Boilerplate.Client.Core.Components.Layout; | ||
|
||
public partial class JsBridge : IDisposable | ||
{ | ||
private DotNetObjectReference<JsBridge>? dotnetObj; | ||
/// <summary> | ||
/// at the rendering time of this component (the component is added to the `RootLayout`) | ||
/// it registers an instance of the `DotNetObjectReference` into the js code (look at the `app.ts` file), | ||
/// so we can later use it to call .net methods. | ||
/// </summary> | ||
protected override async Task OnAfterFirstRenderAsync() | ||
{ | ||
dotnetObj = DotNetObjectReference.Create(this); | ||
|
||
await JSRuntime.InvokeVoidAsync("App.registerJsBridge", dotnetObj); | ||
|
||
await base.OnAfterFirstRenderAsync(); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// you can add any other method like this to utilize the bridge between js and .net code. | ||
/// </summary> | ||
[JSInvokable(nameof(ShowDiagnostic))] | ||
public async Task ShowDiagnostic() | ||
{ | ||
PubSubService.Publish(PubSubMessages.SHOW_DIAGNOSTIC_MODAL); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
dotnetObj?.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,6 @@ | |
|
||
<SnackBar /> | ||
<MessageBox /> | ||
<DiagnosticModal /> | ||
|
||
<JsBridge /> |
Oops, something went wrong.