-
-
Notifications
You must be signed in to change notification settings - Fork 362
refactor(Table): revert add async keyword for ResetDynamicContext #7022
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
Conversation
# Conflicts: # src/BootstrapBlazor/Components/Table/Table.razor.Checkbox.cs
Reviewer's GuideThis PR enhances the Table component by introducing localStorage-backed persistence for column visibility, refines JSON deserialization for ColumnVisibleItem, and generalizes OnValueChanged parameter handling in edit templates, with a minor import addition. Sequence diagram for Table column visibility persistence with localStoragesequenceDiagram
participant TableComponent
participant JSRuntime
participant JsonSerializer
TableComponent->>JSRuntime: Invoke localStorage.getItem("bb-table-column-visiable-<ClientTableName>")
JSRuntime-->>TableComponent: Return jsonData
alt jsonData is not empty
TableComponent->>JsonSerializer: Deserialize jsonData to List<ColumnVisibleItem>
JsonSerializer-->>TableComponent: Return List<ColumnVisibleItem>
loop For each item in deserialized list
TableComponent->>TableComponent: Update column visibility
end
end
Entity relationship diagram for persisted column visibilityerDiagram
TABLE {
string ClientTableName
bool ShowColumnList
}
COLUMN_VISIBLE_ITEM {
string Name
bool Visible
string DisplayName
}
TABLE ||--o{ COLUMN_VISIBLE_ITEM : has
LOCAL_STORAGE {
string key
string value
}
TABLE ||--o{ LOCAL_STORAGE : persists visibility
LOCAL_STORAGE ||--o{ COLUMN_VISIBLE_ITEM : stores list
Class diagram for updated ColumnVisibleItemConverter and Table componentclassDiagram
class ColumnVisibleItemConverter {
+Read(ref Utf8JsonReader, Type, JsonSerializerOptions) : ColumnVisibleItem
+Write(Utf8JsonWriter, ColumnVisibleItem, JsonSerializerOptions) : void
}
class ColumnVisibleItem {
+Name : string
+Visible : bool
+DisplayName : string
}
ColumnVisibleItemConverter --> ColumnVisibleItem : uses
class Table_TItem {
-InternalResetVisibleColumns(columns, items)
-SetDynamicEditTemplate()
-SetEditTemplate()
}
Table_TItem --> ColumnVisibleItem : uses
Table_TItem --> ColumnVisibleItemConverter : uses
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The invocations of nameof(ValidateBase<>.OnValueChanged) won’t compile since open generics aren’t allowed in nameof; please restore a concrete type argument or use a valid type name.
- The localStorage key is spelled "bb-table-column-visiable-" with a typo; correcting it to "bb-table-column-visible-" will prevent mismatches.
- Silently catching all exceptions during JSON deserialization can hide issues—consider narrowing the catch clause or logging errors for easier debugging.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The invocations of nameof(ValidateBase<>.OnValueChanged) won’t compile since open generics aren’t allowed in nameof; please restore a concrete type argument or use a valid type name.
- The localStorage key is spelled "bb-table-column-visiable-" with a typo; correcting it to "bb-table-column-visible-" will prevent mismatches.
- Silently catching all exceptions during JSON deserialization can hide issues—consider narrowing the catch clause or logging errors for easier debugging.
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Converter/ColumnVisibleItemConverter.cs:51` </location>
<code_context>
}
}
- return new ColumnVisibleItem(name, visible);
+ return new ColumnVisibleItem(name ?? "", visible);
}
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Defaulting name to empty string may mask data issues.
Consider logging or explicitly handling cases where 'name' is missing or null to prevent silent data inconsistencies.
Suggested implementation:
```csharp
if (name == null)
{
// Log a warning about missing column name
System.Diagnostics.Debug.WriteLine("Warning: ColumnVisibleItemConverter encountered a null 'name' value during deserialization.");
// Optionally, you could throw an exception instead:
// throw new JsonException("ColumnVisibleItem 'name' property is missing or null.");
}
return new ColumnVisibleItem(name ?? "", visible);
```
If you have a preferred logging framework (e.g., ILogger), replace `System.Diagnostics.Debug.WriteLine` with your logger's warning method. If you want stricter handling, uncomment the exception line and remove the log statement.
</issue_to_address>
### Comment 2
<location> `src/BootstrapBlazor/Components/Table/Table.razor.cs:1281` </location>
<code_context>
private async Task InternalResetVisibleColumns(List<ITableColumn> columns, IEnumerable<ColumnVisibleItem>? items = null)
{
var cols = columns.Select(i => new ColumnVisibleItem(i.GetFieldName(), i.GetVisible()) { DisplayName = i.GetDisplayName() }).ToList();
</code_context>
<issue_to_address>
**issue (complexity):** Consider extracting local storage access and visibility merging logic into helper methods to simplify InternalResetVisibleColumns.
Extract the local-storage lookup, deserialization and merge into two small helpers. That collapses the nested `if`/`try`/`foreach` into a straight-line call, preserves everything and makes testing/logging easier.
```csharp
private async Task<List<ColumnVisibleItem>?> FetchStoredVisibilityAsync(string tableName)
{
var key = $"bb-table-column-visibility-{tableName}";
var json = await JSRuntime.InvokeAsync<string>("localStorage.getItem", key);
if (string.IsNullOrWhiteSpace(json))
return null;
try
{
return JsonSerializer.Deserialize<List<ColumnVisibleItem>>(json, _serializerOption);
}
catch (JsonException ex)
{
// optional: log.Warning(...) or remove if you truly want silent failures
return null;
}
}
private static void ApplyStoredVisibility(
List<ColumnVisibleItem> current,
IEnumerable<ColumnVisibleItem> stored)
{
foreach (var s in stored)
{
var c = current.FirstOrDefault(x =>
x.Name == s.Name && x.DisplayName == s.DisplayName);
if (c != null)
c.Visible = s.Visible;
}
}
```
Then simplify `InternalResetVisibleColumns` to:
```csharp
private async Task InternalResetVisibleColumns(
List<ITableColumn> columns,
IEnumerable<ColumnVisibleItem>? items = null)
{
var cols = columns
.Select(i => new ColumnVisibleItem(i.GetFieldName(), i.GetVisible())
{
DisplayName = i.GetDisplayName()
})
.ToList();
if (ClientTableName != null && ShowColumnList)
{
var stored = await FetchStoredVisibilityAsync(ClientTableName);
if (stored != null)
ApplyStoredVisibility(cols, stored);
}
if (items != null)
{
foreach (var col in cols)
{
var overrideItem = items.FirstOrDefault(i => i.Name == col.Name);
if (overrideItem != null)
{
col.Visible = overrideItem.Visible;
col.DisplayName = string.IsNullOrEmpty(overrideItem.DisplayName)
? col.DisplayName
: overrideItem.DisplayName;
}
}
}
// ... rest of method
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This reverts commit cb0f351. # Conflicts: # src/BootstrapBlazor/Components/Table/Table.razor.Checkbox.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds functionality to persist table column visibility settings to browser localStorage and makes minor improvements to code documentation and type references.
- Added localStorage persistence for column visibility settings in Table component
- Added XML documentation for
ColumnVisibleItemConverterclass - Updated generic type references from
ValidateBase<string>toValidateBase<>for better type flexibility
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/BootstrapBlazor/Converter/ColumnVisibleItemConverter.cs | Added XML documentation and null-coalescing for name parameter |
| src/BootstrapBlazor/Components/Table/Table.razor.cs | Implemented localStorage retrieval of column visibility settings and updated ValidateBase generic type references |
| src/BootstrapBlazor/Components/Table/Table.razor.Checkbox.cs | Added System.Text.Json using directive |
Comments suppressed due to low confidence (5)
src/BootstrapBlazor/Components/Table/Table.razor.cs:1287
- Corrected spelling of 'visiable' to 'visible' in localStorage key name.
{
src/BootstrapBlazor/Components/Table/Table.razor.cs:1295
- Missing space after 'if' keyword. Should be 'if (ret != null)' to follow C# coding conventions.
}
src/BootstrapBlazor/Components/Table/Table.razor.cs:1294
- The new localStorage column visibility persistence feature lacks test coverage. Consider adding tests to verify that column visibility is correctly loaded from localStorage and applied to the columns.
{
var item = items.FirstOrDefault(i => i.Name == column.Name);
if (item != null)
{
column.Visible = item.Visible;
if (!string.IsNullOrEmpty(item.DisplayName))
{
column.DisplayName = item.DisplayName;
src/BootstrapBlazor/Components/Table/Table.razor.cs:1294
- Poor error handling: empty catch block.
column.DisplayName = item.DisplayName;
src/BootstrapBlazor/Components/Table/Table.razor.cs:1294
- Generic catch clause.
column.DisplayName = item.DisplayName;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7022 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 741 743 +2
Lines 32397 32452 +55
Branches 4485 4498 +13
=========================================
+ Hits 32397 32452 +55
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #7021
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Persist and restore table column visibility settings via localStorage and improve dynamic template event bindings
New Features:
Bug Fixes:
Enhancements: