Skip to content
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

fix(Table): add IsAutoInitializeModelProperty parameter control create instance logic #5530

Merged
merged 7 commits into from
Mar 5, 2025

Conversation

ArgoZhang
Copy link
Collaborator

Link issues

[请在下方 # 后面填写相关 Issue 编号,如 #42]
fixes #5529

Summary By Copilot

This pull request includes several changes to the BootstrapBlazor project, focusing on version updates, enhancements to model property initialization, and improvements to unit tests. The most important changes include updating the project version, adding a new parameter for automatic model property initialization, and modifying the CreateInstance method to support this new parameter.

Version Update:

Enhancements to Model Property Initialization:

Unit Test Improvements:

Regression?

  • Yes
  • No

[If yes, specify the version the behavior has regressed from]

[是否影响老版本]

Risk

  • High
  • Medium
  • Low

[Justify the selection above]

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

@bb-auto bb-auto bot added documentation Improvements or additions to documentation Welcome PR Extra attention is needed labels Mar 5, 2025
@bb-auto bb-auto bot added this to the V7.0.0 milestone Mar 5, 2025
Copy link

sourcery-ai bot commented Mar 5, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new IsAutoInitializeModelProperty parameter to the Table component, allowing users to control whether model properties are automatically initialized. The CreateInstance method in ObjectExtensions was modified to support this parameter. Unit tests were added to verify the new functionality. The project version was also updated.

Sequence diagram for CreateInstance with auto-initialization

sequenceDiagram
    participant Table Component
    participant ObjectExtensions
    participant Activator

    Table Component->>ObjectExtensions: CreateInstance<TItem>(isAutoInitializeModelProperty)
    activate ObjectExtensions
    ObjectExtensions->>Activator: CreateInstance<TItem>()
    activate Activator
    Activator-->>ObjectExtensions: instance
    deactivate Activator
    alt isAutoInitializeModelProperty is true
        ObjectExtensions->>ObjectExtensions: EnsureInitialized(instance, isAutoInitializeModelProperty)
        activate ObjectExtensions
        ObjectExtensions->>ObjectExtensions: GetProperties()
        ObjectExtensions->>ObjectExtensions: CreateInstance(type, isAutoInitializeModelProperty)
        activate ObjectExtensions
        ObjectExtensions->>Activator: CreateInstance(type)
        activate Activator
        Activator-->>ObjectExtensions: propertyInstance
        deactivate Activator
        ObjectExtensions->>ObjectExtensions: SetValue(propertyInstance)
        deactivate ObjectExtensions
        ObjectExtensions-->>ObjectExtensions: 
        deactivate ObjectExtensions
    end
    ObjectExtensions-->>Table Component: instance
    deactivate ObjectExtensions
Loading

File-Level Changes

Change Details Files
Updated the project version in the .csproj file.
  • Incremented the version number from 9.4.5 to 9.4.6.
src/BootstrapBlazor/BootstrapBlazor.csproj
Introduced a new parameter to control automatic initialization of model properties in the Table component and ObjectExtensions.
  • Added IsAutoInitializeModelProperty parameter to the Table component.
  • Modified the CreateInstance method in ObjectExtensions to accept an isAutoInitializeModelProperty parameter.
  • Updated the EnsureInitialized method to use the isAutoInitializeModelProperty parameter.
  • Modified the CreateInstance method in Table.razor.Edit.cs to use the IsAutoInitializeModelProperty parameter.
src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs
src/BootstrapBlazor/Extensions/ObjectExtensions.cs
Added unit tests to verify the functionality of the IsAutoInitializeModelProperty parameter and the CreateInstance method.
  • Added a test case in TableTest.cs to verify the IsAutoInitializeModelProperty parameter.
  • Added a test case in ObjectExtensionsTest.cs for the CreateInstance method with the isAutoInitializeModelProperty parameter.
test/UnitTest/Components/TableTest.cs
test/UnitTest/Extensions/ObjectExtensionsTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#5529 Fix the exception thrown when adding a model to the Table component.

Possibly linked issues

  • bug(Table): throw exception when add model #5529: The PR fixes the issue by ensuring that class-type properties are initialized based on the IsAutoInitializeModelProperty parameter, addressing the problem of table columns not rendering correctly.

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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 added enhancement New feature or request and removed documentation Improvements or additions to documentation Welcome PR Extra attention is needed labels Mar 5, 2025
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Mar 5, 2025
Copy link

@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:

Overall Comments:

  • Consider adding a non-nullable TItem constraint to the CreateInstance method signature to avoid the need for null-forgiving operators.
  • The added unit test for CreateInstance_Ok throws an exception, which is unusual for a test that's supposed to verify functionality.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

Copy link

codecov bot commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (ab8e288) to head (9adb648).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5530   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          649       649           
  Lines        29583     29599   +16     
  Branches      4167      4171    +4     
=========================================
+ Hits         29583     29599   +16     

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

@ArgoZhang
Copy link
Collaborator Author

@sourcery-ai review

@ArgoZhang ArgoZhang merged commit 5ddb33d into main Mar 5, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the fix-table branch March 5, 2025 11:40
@ArgoZhang ArgoZhang modified the milestones: V7.0.0, v9.4.0 Mar 6, 2025
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.

bug(Table): throw exception when add model
1 participant