Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Aug 2, 2025

Link issues

fixes #6526

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Allow explicit key assignment on DynamicElement and enable custom row key generation in Table via the new OnGetRowKey callback.

New Features:

  • Add Key parameter to DynamicElement component for explicit render-tree key management
  • Add OnGetRowKey parameter to Table component to compute and assign custom row keys to DynamicElement

@bb-auto bb-auto bot added the documentation Improvements or additions to documentation label Aug 2, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 2, 2025

Reviewer's Guide

This PR enhances the Blazor rendering of dynamic elements and table rows by introducing a customizable Key parameter and row-key callback, enabling fine-grained control over component identity during rendering.

Sequence diagram for rendering a table row with custom key

sequenceDiagram
    participant Table as Table<TItem>
    participant DynamicElement
    participant User as actor
    User->>Table: Triggers table render
    Table->>Table: GetKeyByITem(item)
    Table->>DynamicElement: Passes Key=GetKeyByITem(item)
    DynamicElement->>DynamicElement: Sets component key
    DynamicElement-->>Table: Rendered with custom key
Loading

File-Level Changes

Change Details Files
Extended DynamicElement to accept and apply a dynamic key
  • Added a nullable Key parameter
  • Emitted builder.SetKey when Key is non-null
src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs
Enabled Table component to supply custom row keys
  • Introduced OnGetRowKey Func<TItem,object?> parameter
  • Added helper GetKeyByITem to invoke the callback
src/BootstrapBlazor/Components/Table/Table.razor.cs
Switched table row renders to use the new Key parameter
  • Replaced @key="item" with Key="GetKeyByITem(item)" on DynamicElement in both table templates
src/BootstrapBlazor/Components/Table/Table.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#6526 Document how to disable the TaskService in development mode. The PR only contains code changes related to adding a Key parameter and row key logic to DynamicElement and Table components. There are no documentation changes or instructions about disabling the TaskService in development mode.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added this to the 9.8.0 milestone Aug 2, 2025
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Aug 2, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ArgoZhang - I've reviewed your changes - here's some feedback:

  • Please update the PR title and description to accurately reflect that this change introduces customizable row keys for tables rather than disabling TaskService.
  • To preserve existing behavior, consider defaulting the row key to the item instance when OnGetRowKey is not provided so rows remain keyed by default.
  • Rename the GetKeyByITem method to something like GetRowKey or correct its casing for better clarity and consistency.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Please update the PR title and description to accurately reflect that this change introduces customizable row keys for tables rather than disabling TaskService.
- To preserve existing behavior, consider defaulting the row key to the item instance when OnGetRowKey is not provided so rows remain keyed by default.
- Rename the GetKeyByITem method to something like GetRowKey or correct its casing for better clarity and consistency.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor:246` </location>
<code_context>
                         else
                         {
-                            <DynamicElement class="@GetRowClassString(item, "table-row")" @key="item"
+                            <DynamicElement class="@GetRowClassString(item, "table-row")" Key="GetKeyByITem(item)"
                                             TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
                                             @ontouchstart="e => OnTouchStart(e, item)"
</code_context>

<issue_to_address>
The method name 'GetKeyByITem' appears to have a typo.

Please rename the method to 'GetKeyByItem' for clarity and consistency.

Suggested implementation:

```
                            <DynamicElement class="@GetRowClassString(item, "table-row")" Key="GetKeyByItem(item)"

```

```
    @<DynamicElement TagName="tr" class="@GetRowClassString(item)" Key="GetKeyByItem(item)"

```

If there is a method definition named `GetKeyByITem` elsewhere in the file or codebase, it should also be renamed to `GetKeyByItem` to maintain consistency and avoid runtime errors.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/Table/Table.razor:690` </location>
<code_context>

     RenderFragment<TItem> RenderRow => item =>
-    @<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="item"
+    @<DynamicElement TagName="tr" class="@GetRowClassString(item)" Key="GetKeyByITem(item)"
                      TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
                      @ontouchstart="e => OnTouchStart(e, item)" @ontouchend="OnTouchEnd"
</code_context>

<issue_to_address>
Typo in method name 'GetKeyByITem' used for the Key parameter.

Please correct the method name to 'GetKeyByItem' to avoid confusion and potential errors.

Suggested implementation:

```
<DynamicElement class="@GetRowClassString(item, "table-row")" Key="GetKeyByItem(item)"

```

```
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" Key="GetKeyByItem(item)"

```
</issue_to_address>

### Comment 3
<location> `src/BootstrapBlazor/Components/Table/Table.razor.cs:1690` </location>
<code_context>
         TouchStart = false;
     }

+    private object? GetKeyByITem(TItem item) => OnGetRowKey?.Invoke(item);
+
     /// <summary>
</code_context>

<issue_to_address>
Method name 'GetKeyByITem' contains a capitalization typo.

Please rename to 'GetKeyByItem' for clarity and consistency.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    private object? GetKeyByITem(TItem item) => OnGetRowKey?.Invoke(item);
=======
    private object? GetKeyByItem(TItem item) => OnGetRowKey?.Invoke(item);
>>>>>>> REPLACE

</suggested_fix>

### Comment 4
<location> `src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs:128` </location>
<code_context>

         builder.AddContent(8, ChildContent);

+        if (Key != null)
+        {
+            builder.SetKey(Key);
+        }
+
</code_context>

<issue_to_address>
Setting the key after adding child content may not have the intended effect.

Call SetKey immediately after opening the element and before AddContent to ensure the key is correctly applied.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang changed the title doc(TaskService): disable task service on dev mode fix(Table): fix Table Aug 2, 2025
@ArgoZhang ArgoZhang modified the milestones: 9.8.0, 9.9.0 Aug 2, 2025
@codecov
Copy link

codecov bot commented Aug 2, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.98%. Comparing base (09e200c) to head (4ab3986).

Files with missing lines Patch % Lines
...Blazor/Components/BaseComponents/DynamicElement.cs 20.00% 3 Missing and 1 partial ⚠️
...rc/BootstrapBlazor/Components/Table/Table.razor.cs 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main    #6527      +/-   ##
===========================================
- Coverage   100.00%   99.98%   -0.02%     
===========================================
  Files          714      714              
  Lines        31397    31405       +8     
  Branches      4432     4434       +2     
===========================================
+ Hits         31397    31399       +2     
- Misses           0        4       +4     
- Partials         0        2       +2     
Flag Coverage Δ
BB 99.98% <33.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArgoZhang ArgoZhang changed the title fix(Table): fix Table feat(ISortableList): add ISortableList interface Aug 4, 2025
@ArgoZhang ArgoZhang added enhancement New feature or request and removed documentation Improvements or additions to documentation labels Aug 4, 2025
@ArgoZhang ArgoZhang merged commit 1435764 into main Aug 4, 2025
4 checks passed
@ArgoZhang ArgoZhang deleted the fix-table branch August 4, 2025 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ISortableList): add ISortableList interface

2 participants