Skip to content

Conversation

ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Sep 30, 2025

Link issues

fixes #6808

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

Ensure auto-fit column width on double-click triggers the resizeColumnCallback and centralize tooltip update logic for column width tooltips

Bug Fixes:

  • Invoke the user-defined resizeColumnCallback after auto-fitting a column on double-click

Enhancements:

  • Extract tooltip update logic into resetColumnWidthTips and update getColumnTooltipTitle to use the actual th.offsetWidth for accurate width tooltips

@Copilot Copilot AI review requested due to automatic review settings September 30, 2025 03:04
@bb-auto bb-auto bot added the enhancement New feature or request label Sep 30, 2025
@bb-auto bb-auto bot added this to the 9.11.0 milestone Sep 30, 2025
Copy link
Contributor

sourcery-ai bot commented Sep 30, 2025

Reviewer's Guide

This PR refactors column width tooltip handling by extracting shared logic into a helper, adjusts the tooltip title generator to use the header element’s width, and triggers the user-provided resizeColumnCallback when a column is autofitted via double click.

Sequence diagram for double-click column autofit triggering resizeColumnCallback

sequenceDiagram
    participant User as actor User
    participant Table as Table Component
    participant JS as Table.razor.js
    participant Callback as resizeColumnCallback
    User->>Table: Double-click column header
    Table->>JS: autoFitColumnWidth(table, col)
    JS->>JS: Calculate maxWidth
    JS->>Callback: invokeMethodAsync(resizeColumnCallback, index, maxWidth)
    JS->>JS: resetColumnWidthTips(table, col)
Loading

Class diagram for refactored tooltip logic and callback integration

classDiagram
    class Table {
        options
        columns
        invoke
    }
    class Tooltip {
        tip
        _config
        update()
        _isShown()
    }
    class EventHandler {
        on()
    }
    class JS {
        setResizeListener(table)
        setColumnResizingListen(table, col)
        autoFitColumnWidth(table, col)
        resetColumnWidthTips(table, col)
        getColumnTooltipTitle(options, th)
    }
    Table --> JS : uses
    JS --> Tooltip : uses
    JS --> EventHandler : uses
    JS --> Table : calls invokeMethodAsync
    JS --> "resizeColumnCallback" : invokes
    JS --> Tooltip : calls getInstance/getOrCreateInstance
    JS --> Tooltip : calls update
    JS --> Tooltip : calls _isShown
Loading

File-Level Changes

Change Details Files
Extracted tooltip reset logic into a reusable helper
  • Moved inline tooltip update code into resetColumnWidthTips()
  • Replaced in-place tooltip update in setResizeListener with resetColumnWidthTips()
  • Added resetColumnWidthTips() call at the end of autoFitColumnWidth()
src/BootstrapBlazor/Components/Table/Table.razor.js
Changed tooltip title generator to accept the TH element
  • Modified getColumnTooltipTitle signature to take a TH and compute its offsetWidth
  • Updated calls in setColumnResizingListen() and resetColumnWidthTips() to pass the TH element
src/BootstrapBlazor/Components/Table/Table.razor.js
Invoke resizeColumnCallback on auto-fit (double click)
  • Added await table.invoke.invokeMethodAsync(...) for resizeColumnCallback in autoFitColumnWidth()
  • Ensured callback runs before resetting the tooltip
src/BootstrapBlazor/Components/Table/Table.razor.js
Updated project file to include changes
  • Adjusted BootstrapBlazor.csproj (likely to register new JavaScript changes or bump version)
src/BootstrapBlazor/BootstrapBlazor.csproj

Assessment against linked issues

Issue Objective Addressed Explanation
#6808 Add a callback that is triggered after the Table component automatically adjusts column width (e.g., after double-clicking the header to auto-fit).
#6808 Ensure the callback provides relevant information (such as column index and new width) after the auto-fit operation.
#6808 Integrate the callback with the existing OnResizeColumnAsync mechanism or provide a similar API.

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

@ArgoZhang ArgoZhang merged commit 51b9ca6 into main Sep 30, 2025
4 of 5 checks passed
@ArgoZhang ArgoZhang deleted the doc-table branch September 30, 2025 03:04
Copy link
Contributor

@Copilot 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 fixes an issue where double-clicking a table column should trigger the ResizeColumnCallback, ensuring proper callback invocation and tooltip updates during column auto-fit operations.

  • Refactored tooltip handling logic into a reusable resetColumnWidthTips function
  • Added missing ResizeColumnCallback invocation in the autoFitColumnWidth function
  • Updated tooltip title generation to accept table header element instead of width value

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/BootstrapBlazor/Components/Table/Table.razor.js Added callback invocation for double-click column resize and refactored tooltip handling
src/BootstrapBlazor/BootstrapBlazor.csproj Version bump to 9.11.1-beta01

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

setTableDefaultWidth(table);

if (table.options.resizeColumnCallback) {
await table.invoke.invokeMethodAsync(table.options.resizeColumnCallback, index, maxWidth)
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

Missing semicolon at the end of the statement. JavaScript statements should end with semicolons for consistency and to avoid potential issues with automatic semicolon insertion.

Suggested change
await table.invoke.invokeMethodAsync(table.options.resizeColumnCallback, index, maxWidth)
await table.invoke.invokeMethodAsync(table.options.resizeColumnCallback, index, maxWidth);

Copilot uses AI. Check for mistakes.

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 there - I've reviewed your changes - here's some feedback:

  • Consider also invoking resizeColumnCallback after manual drag-resize completes (in addition to double‐click auto‐fit) to keep the API consistent for consumers.
  • The resetColumnWidthTips helper sometimes takes a <th> element and sometimes the resize handle; renaming its parameter or normalizing the input would improve clarity.
  • Previously the tooltip title calculation included marginX in the width—verify that the refactored getColumnTooltipTitle still reflects any needed margin adjustments.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider also invoking `resizeColumnCallback` after manual drag-resize completes (in addition to double‐click auto‐fit) to keep the API consistent for consumers.
- The `resetColumnWidthTips` helper sometimes takes a `<th>` element and sometimes the resize handle; renaming its parameter or normalizing the input would improve clarity.
- Previously the tooltip title calculation included `marginX` in the width—verify that the refactored `getColumnTooltipTitle` still reflects any needed margin adjustments.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor.js:748-752` </location>
<code_context>

         setTableDefaultWidth(table);
+
+        if (table.options.resizeColumnCallback) {
+            await table.invoke.invokeMethodAsync(table.options.resizeColumnCallback, index, maxWidth)
+        }
+
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Consider error handling for async callback invocation.

Wrapping the async call in a try/catch block will help prevent unhandled promise rejections, particularly if the callback is user-defined.

```suggestion
        setTableDefaultWidth(table);

        if (table.options.resizeColumnCallback) {
            try {
                await table.invoke.invokeMethodAsync(table.options.resizeColumnCallback, index, maxWidth);
            } catch (error) {
                console.error("Error invoking resizeColumnCallback:", error);
            }
        }
```
</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.

Comment on lines 748 to +752
setTableDefaultWidth(table);

if (table.options.resizeColumnCallback) {
await table.invoke.invokeMethodAsync(table.options.resizeColumnCallback, index, maxWidth)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider error handling for async callback invocation.

Wrapping the async call in a try/catch block will help prevent unhandled promise rejections, particularly if the callback is user-defined.

Suggested change
setTableDefaultWidth(table);
if (table.options.resizeColumnCallback) {
await table.invoke.invokeMethodAsync(table.options.resizeColumnCallback, index, maxWidth)
}
setTableDefaultWidth(table);
if (table.options.resizeColumnCallback) {
try {
await table.invoke.invokeMethodAsync(table.options.resizeColumnCallback, index, maxWidth);
} catch (error) {
console.error("Error invoking resizeColumnCallback:", error);
}
}

Copy link

codecov bot commented Sep 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (73f133a) to head (775aa86).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6809   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31751     31751           
  Branches      4465      4465           
=========================================
  Hits         31751     31751           
Flag Coverage Δ
BB 100.00% <ø> (?)

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.

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(Table): 双击表头自动调整列宽后,建议新增一个回调

1 participant