Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented May 17, 2025

Link issues

fixes #6021

Summary By Copilot

This pull request introduces enhancements to the sortable list functionality, improves performance in the Table component, and updates the project version. Key changes include adding an event handler for updating sortable lists, ensuring efficient rendering in the Table component, and incrementing the version number.

Enhancements to Sortable Lists:

Performance Improvements in the Table Component:

Project Version Update:

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

Enable SortableList to handle item reordering with full item rendering and line numbers, optimize Table rendering with @key, and update project version

Bug Fixes:

  • Fix SortableList integration by supporting full item list and line numbers in Table components

Enhancements:

  • Add OnUpdate event handler to SortableList for drag-and-drop reordering
  • Add @key directive to Table row elements to improve rendering performance

Build:

  • Bump project version from 9.6.4-beta01 to 9.6.4-beta02

Tests:

  • Update Table pagination tests to re-query checkbox states before assertions

@ArgoZhang ArgoZhang requested a review from Copilot May 17, 2025 10:50
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 17, 2025

Reviewer's Guide

This PR implements drag-and-drop reordering support in the SortableList sample by adding an OnUpdateTable handler and enabling line numbering for all items; optimizes Table component rendering efficiency by applying @key directives to row elements; corrects unit tests by refreshing checkbox component retrieval between pagination steps; and updates the project version to 9.6.4-beta02.

Sequence Diagram: Item Reordering in SortableList Table

sequenceDiagram
    actor User
    participant SL as SortableList Component
    participant Page as SortableLists.razor.cs (Page Logic)
    participant Data as Items Collection

    User->>SL: Drags and drops an item in the table
    SL->>Page: Triggers OnUpdate event (with SortableEvent)
    activate Page
    Page->>Page: Executes OnUpdateTable(SortableEvent)
    Page->>Data: Removes item from oldIndex
    Page->>Data: Inserts item at newIndex
    Page->>Page: Calls StateHasChanged() to refresh UI
    deactivate Page
    Page->>SL: (Blazor rendering) Re-renders with updated items
Loading

Class Diagram: Updates to SortableLists Sample and Components

classDiagram
    class SortableLists_Page {
        -List~Foo~ Items
        +OnUpdateTable(SortableEvent event) Task
    }
    note for SortableLists_Page "Represents SortableLists.razor.cs. Handles item reordering logic triggered by the SortableList component."

    class SortableList_Component {
      +SortableListOption Option
      +EventCallback~SortableEvent~ OnUpdate
    }
    note for SortableList_Component "OnUpdate event handler now utilized to callback SortableLists_Page.OnUpdateTable for item reordering."

    class Table_Component {
      +IEnumerable~Foo~ Items
      +bool IsStriped
      +bool ShowLineNo
    }
    note for Table_Component "ShowLineNo parameter now set to true in the sample. Diff also shows @key directive added to rows for rendering optimization (not a new class member)."

    SortableLists_Page "1" ..> "1" SortableList_Component : uses
    SortableList_Component "1" ..> "1" Table_Component : contains
    SortableList_Component --|> SortableLists_Page : OnUpdate event
Loading

File-Level Changes

Change Details Files
Add drag-and-drop reordering support in SortableList sample
  • Implement OnUpdateTable method to reorder Items list and trigger StateHasChanged
  • Add OnUpdate attribute to SortableList referencing OnUpdateTable
  • Switch Table Items binding to use full Items list and enable ShowLineNo
src/BootstrapBlazor.Server/Components/Samples/SortableLists.razor.cs
src/BootstrapBlazor.Server/Components/Samples/SortableLists.razor
Optimize Table row rendering by tracking elements with @key
  • Insert @key attribute on DynamicElement in main table rows render block
  • Insert @key attribute on DynamicElement in RenderRow fragment
src/BootstrapBlazor/Components/Table/Table.razor
Refresh checkbox list in pagination tests before each assertion
  • Re-fetch checkbox components (cut.FindComponents<Checkbox>) prior to each assertion block
test/UnitTest/Components/TableTest.cs
Bump project version
  • Update version in BootstrapBlazor.csproj from 9.6.4-beta01 to 9.6.4-beta02
src/BootstrapBlazor/BootstrapBlazor.csproj

Assessment against linked issues

Issue Objective Addressed Explanation
#6021 When IsExcel is true, the row number style should be horizontally centered. The PR does not address the horizontal alignment of row numbers when IsExcel is true.
#6021 When dragging rows, the row numbers should automatically refresh.
#6021 Optimize rendering of table rows during updates.

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 the bug Something isn't working label May 17, 2025
@bb-auto bb-auto bot added this to the v9.6.0 milestone May 17, 2025
Copy link
Contributor

Copilot AI left a 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 enhances sortable list functionality and improves the Table component’s rendering performance while updating the project version.

  • Enhanced sortable lists with an event handler for reordering.
  • Improved Table rendering by adding @key to row elements.
  • Updated project version from 9.6.4-beta01 to 9.6.4-beta02.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/BootstrapBlazor/Components/Table/Table.razor Added @key to DynamicElement for improved row tracking.
src/BootstrapBlazor/BootstrapBlazor.csproj Bumped version number to 9.6.4-beta02.
src/BootstrapBlazor.Server/Components/Samples/SortableLists.razor.cs Introduced OnUpdateTable method for sortable list reordering.
src/BootstrapBlazor.Server/Components/Samples/SortableLists.razor Updated SortableList to use OnUpdateTable and show all items with line numbers.

@ArgoZhang ArgoZhang merged commit cd681ef into main May 17, 2025
3 checks passed
@ArgoZhang ArgoZhang deleted the fix-table branch May 17, 2025 12:13
@ArgoZhang
Copy link
Member Author

@sourcery-ai review

@codecov
Copy link

codecov bot commented May 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (61769ed) to head (e551c2e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6045   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          701       701           
  Lines        30958     30958           
  Branches      4378      4378           
=========================================
  Hits         30958     30958           

☔ 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.

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:

  • In the OnUpdateTable handler, consider using InvokeAsync(() => StateHasChanged()) to ensure the state change is scheduled on the correct rendering context.
  • For the @key directive on rows, prefer using a unique identifier property (e.g. item.Id) instead of the item object itself to guarantee stable keys when item values change.
  • The repeated cut.FindComponents<Checkbox>() calls in TableTest could be pulled into a small helper method to reduce duplication and improve test clarity.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

private Task OnUpdateTable(SortableEvent @event)
{
var oldItem = Items[@event.OldIndex];
Items.Remove(oldItem);
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Validate indices before reordering

Add range checks for @event.OldIndex and @event.NewIndex before calling Remove or Insert to prevent out-of-range exceptions.

Comment on lines +139 to +147
private Task OnUpdateTable(SortableEvent @event)
{
var oldItem = Items[@event.OldIndex];
Items.Remove(oldItem);
Items.Insert(@event.NewIndex, oldItem);

StateHasChanged();
return Task.CompletedTask;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Favor InvokeAsync(StateHasChanged) in event handlers

Await InvokeAsync(StateHasChanged) to ensure the UI update runs on the proper synchronization context in sortable event callbacks.

Suggested change
private Task OnUpdateTable(SortableEvent @event)
{
var oldItem = Items[@event.OldIndex];
Items.Remove(oldItem);
Items.Insert(@event.NewIndex, oldItem);
StateHasChanged();
return Task.CompletedTask;
}
private async Task OnUpdateTable(SortableEvent @event)
{
var oldItem = Items[@event.OldIndex];
Items.Remove(oldItem);
Items.Insert(@event.NewIndex, oldItem);
await InvokeAsync(StateHasChanged);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Table): 拖拽组件行号无法自动更新

2 participants