Skip to content

Conversation

@A5196060
Copy link
Contributor

@A5196060 A5196060 commented Dec 21, 2024

implement RadioListGeneric component

Summary of the changes (Less than 80 chars)

简单描述你更改了什么, 不超过80个字符;如果有关联 Issue 请在下方填写相关编号

Description

fixes #4906

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

Summary by Sourcery

New Features:

  • Introduce the RadioListGeneric component, a new component for rendering a list of radio buttons.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 21, 2024

Reviewer's Guide by Sourcery

This pull request implements the RadioListGeneric component, a new generic radio list component. It introduces new parameters such as ShowBorder, IsVertical, Color, Items, OnSelectedChanged, CustomKeyAttribute, and ModelEqualityComparer to customize the component's appearance and behavior. The component uses the SelectedItem type for its items and supports both button and standard radio list styles. It also includes functionality to handle item clicks, manage checked states, and render custom item templates. Additionally, the component implements the IModelEqualityComparer interface for custom equality comparisons.

Sequence diagram for radio list item selection

sequenceDiagram
    participant User
    participant RadioList as RadioListGeneric
    participant Parent as Parent Component
    User->>RadioList: Click radio item
    RadioList->>RadioList: Check if not disabled
    alt not disabled
        RadioList->>Parent: OnSelectedChanged(Items, Value)
        RadioList->>RadioList: StateHasChanged()
    end
Loading

Class diagram for RadioListGeneric component

classDiagram
    class RadioListGeneric~TValue~ {
        +bool IsAutoAddNullItem
        +string NullItemText
        +bool ShowBorder
        +bool IsVertical
        +Color Color
        +IEnumerable~SelectedItem<TValue>~ Items
        +Func~IEnumerable<SelectedItem<TValue>>, TValue, Task~ OnSelectedChanged
        +Type CustomKeyAttribute
        +Func~TValue, TValue, bool~ ModelEqualityComparer
        -string GroupName
        -string ClassString
        -string ButtonClassString
        +OnParametersSet()
        -Task OnClick(SelectedItem<TValue>)
        -CheckboxState CheckState(SelectedItem<TValue>)
        -RenderFragment GetChildContent(SelectedItem<TValue>)
        +bool Equals(TValue, TValue)
    }
    class IModelEqualityComparer~TValue~ {
        <<interface>>
        +bool Equals(TValue, TValue)
    }
    RadioListGeneric --|> IModelEqualityComparer : implements
    note for RadioListGeneric "Generic radio list component
Supports button and standard styles"
Loading

State diagram for RadioListGeneric item states

stateDiagram-v2
    [*] --> Unchecked
    Unchecked --> Checked: User clicks/selects
    Checked --> Unchecked: User selects different item
    state Disabled {
        [*] --> DisabledUnchecked
        DisabledUnchecked --> DisabledChecked
        DisabledChecked --> DisabledUnchecked
    }
    Unchecked --> DisabledUnchecked: Disable component
    Checked --> DisabledChecked: Disable component
    DisabledUnchecked --> Unchecked: Enable component
    DisabledChecked --> Checked: Enable component
Loading

File-Level Changes

Change Details Files
Implement the RadioListGeneric component.
  • Added new parameters for customization, including ShowBorder, IsVertical, Color, Items, OnSelectedChanged, CustomKeyAttribute, and ModelEqualityComparer.
  • Implemented the IModelEqualityComparer interface for custom equality comparisons.
  • Added logic to handle item clicks and manage checked states.
  • Added support for custom item templates using ItemTemplate.
  • Implemented rendering logic for both button and standard radio list styles.
  • Removed the ExcludeFromCodeCoverage attribute from the RadioListGeneric class.
  • Added logic to automatically populate items when the type is an enum and Items is null.
  • Updated the Razor markup to conditionally render the button style radio list based on the IsButton parameter.
src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs
src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#4906 Implement RadioListGeneric component

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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
Copy link

bb-auto bot commented Dec 21, 2024

Thanks for your PR, @A5196060. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@bb-auto bb-auto bot requested a review from ArgoZhang December 21, 2024 08:33
@bb-auto bb-auto bot added the enhancement New feature or request label Dec 21, 2024
@bb-auto bb-auto bot added this to the v9.0.0 milestone Dec 21, 2024
@A5196060
Copy link
Contributor Author

@microsoft-github-policy-service agree

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Dec 21, 2024
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 @A5196060 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The OnClick handler doesn't update the Value property with the newly selected item's value before calling OnSelectedChanged. This will prevent the radio selection from working properly.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 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.

# Conflicts:
#	src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs
@codecov
Copy link

codecov bot commented Dec 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3c4cc8e) to head (aa14e7e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #4908   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          626       628    +2     
  Lines        27994     28073   +79     
  Branches      4021      4038   +17     
=========================================
+ Hits         27994     28073   +79     

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

ArgoZhang
ArgoZhang previously approved these changes Dec 21, 2024
@ArgoZhang ArgoZhang enabled auto-merge (squash) December 21, 2024 12:07
@ArgoZhang ArgoZhang disabled auto-merge December 21, 2024 12:07
@ArgoZhang ArgoZhang merged commit 72398af into dotnetcore:main Dec 21, 2024
6 checks passed
@A5196060 A5196060 deleted the dev branch December 21, 2024 13:12
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(RadioListGeneric): implement RadioListGeneric component

2 participants