Skip to content

Conversation

@densen2014
Copy link
Member

@densen2014 densen2014 commented Dec 28, 2024

按当前输入语言小数点分隔符格式自动渲染组件类型

多语言: 数字类型字段在编辑对话框渲染为数字输入框格式问题
一个自动的机制, 非点号(.) 数字格式区域, 数字类型编辑自动渲染为文本框, 而不是数字框

close #4987

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:

  • Automatically render numeric type fields as text input boxes in locales with non-period decimal separators.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 28, 2024

Reviewer's Guide by Sourcery

This pull request implements automatic rendering of component types based on the current input language's decimal separator. When the decimal separator is not a period (.), numeric type edits are rendered as text boxes instead of number boxes. It also refactors the CreateDisplayByFieldType and CreateComponentByFieldType methods to streamline attribute assignments and removes redundant code.

Sequence diagram for numeric field type rendering

sequenceDiagram
    participant User
    participant Component
    participant Utility
    participant CultureInfo

    User->>Component: Edit numeric field
    Component->>Utility: GenerateComponentType()
    Utility->>CultureInfo: Get CurrentCulture
    CultureInfo-->>Utility: Return NumberFormat
    Note over Utility: Check NumberDecimalSeparator
    alt NumberDecimalSeparator is '.'
        Utility-->>Component: Return BootstrapInputNumber
    else NumberDecimalSeparator is not '.'
        Utility-->>Component: Return default text input
    end
    Component-->>User: Display appropriate input field
Loading

Class diagram showing Utility class changes

classDiagram
    class Utility {
        +GetPropertyValue<TModel, TResult>(model: TModel, fieldName: string): TResult
        -NumberDecimalSeparator: string
        +CreateDisplayByFieldType(builder: RenderTreeBuilder, item: IEditorItem)
        +CreateComponentByFieldType(builder: RenderTreeBuilder, item: IEditorItem)
        -GenerateComponentType(item: IEditorItem): Type
    }
    note for Utility "Added NumberDecimalSeparator property
Modified GenerateComponentType to check decimal separator"
Loading

State diagram for numeric input type decision

stateDiagram-v2
    [*] --> CheckFieldType
    CheckFieldType --> IsNumber: Field is numeric
    CheckFieldType --> OtherTypes: Field is not numeric
    IsNumber --> CheckSeparator
    CheckSeparator --> NumberInput: Separator is '.'
    CheckSeparator --> TextInput: Separator is not '.'
    OtherTypes --> [*]
    NumberInput --> [*]
    TextInput --> [*]
Loading

File-Level Changes

Change Details Files
Added a mechanism to automatically render numeric types as text boxes when the decimal separator is not a period.
  • Added a new property NumberDecimalSeparator to get the current culture's number decimal separator.
  • Modified the conditional rendering logic in GenerateComponentType to use the NumberDecimalSeparator property. Numeric types are now rendered as text boxes when the separator is not ".".
src/BootstrapBlazor/Utils/Utility.cs
Refactored component attribute assignments in CreateDisplayByFieldType and CreateComponentByFieldType methods.
  • Removed redundant attribute assignments for Lookup in CreateDisplayByFieldType.
  • Removed redundant attribute assignments for Items and Lookup in CreateComponentByFieldType.
  • Reordered and streamlined remaining attribute assignments in both methods for better readability.
src/BootstrapBlazor/Utils/Utility.cs

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 28, 2024

Thanks for your PR, @densen2014. 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 28, 2024 17:17
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Dec 28, 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 @densen2014 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The current approach of checking NumberDecimalSeparator == "." is too simplistic for proper culture handling. Consider using .NET's built-in number formatting and parsing capabilities to handle numeric input consistently across all cultures.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 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.

@codecov
Copy link

codecov bot commented Dec 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (cc675fc) to head (a4cc93f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #4983   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          630       630           
  Lines        28073     28077    +4     
  Branches      4025      4026    +1     
=========================================
+ Hits         28073     28077    +4     

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

@ArgoZhang ArgoZhang changed the title feat(GenerateComponentType)#4982-Numeric-type-rendered feat(BootstrapInputNumber): support NumberDecimalSeparator setting Dec 29, 2024
@bb-auto bb-auto bot added the enhancement New feature or request label Dec 29, 2024
@bb-auto bb-auto bot added this to the v9.0.0 milestone Dec 29, 2024
ArgoZhang
ArgoZhang previously approved these changes Dec 29, 2024
@ArgoZhang ArgoZhang merged commit da5fde6 into main Dec 29, 2024
5 checks passed
@ArgoZhang ArgoZhang deleted the alex/feat(GenerateComponentType)#4982-Numeric-type-rendered branch December 29, 2024 04: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(BootstrapInputNumber): support check NumberDecimalSeparator setting

3 participants