Skip to content

feat(Region): add SelectProvince component #608

Merged
ArgoZhang merged 8 commits intomasterfrom
feat-region
Oct 17, 2025
Merged

feat(Region): add SelectProvince component #608
ArgoZhang merged 8 commits intomasterfrom
feat-region

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Oct 17, 2025

Link issues

fixes #607

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

Add a new SelectProvince component and refactor region selection components and services for improved code reuse and consistency.

New Features:

  • Add SelectProvince component for single and multiple province selection.

Enhancements:

  • Extract InputId property into SelectRegionBase and remove duplicate definitions.
  • Rename DefaultRegionService cache fields to follow PascalCase conventions and unify lock usage.
  • Streamline OnSelectProvince logic in SelectCity using switch expression and LINQ.
  • Update dark theme CSS variables for SelectCity and SelectRegion dropdown menus.

Copilot AI review requested due to automatic review settings October 17, 2025 01:10
@bb-auto bb-auto Bot added the enhancement New feature or request label Oct 17, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Oct 17, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Oct 17, 2025

Reviewer's Guide

This PR introduces a new SelectProvince component for single/multiple province selection, refactors SelectCity and SelectRegion to consolidate common logic in SelectRegionBase, simplifies city selection logic with pattern matching, standardizes caching and locking in DefaultRegionService, and updates dark theme CSS across components.

Class diagram for new and refactored region selection components

classDiagram
    class SelectRegionBase {
        <<abstract>>
        +string InputId
    }
    class SelectProvince {
        +bool IsMultiple
        -HashSet<string> _values
        +string? GetActiveClass(string item)
        +Task OnClearValue()
        +void OnSelectProvince(string item)
        +HashSet<string> GetProvinces()
    }
    class SelectCity {
        +bool IsMultiple
        -void OnSelectProvince(string province)
    }
    class SelectRegion {
    }
    SelectProvince --|> SelectRegionBase
    SelectCity --|> SelectRegionBase
    SelectRegion --|> SelectRegionBase
Loading

Class diagram for DefaultRegionService cache and lock refactor

classDiagram
    class DefaultRegionService {
        -static ConcurrentDictionary<string, HashSet<string>> CitiesCache
        -static ConcurrentDictionary<string, HashSet<CountyItem>> CountiesCache
        -static ConcurrentDictionary<string, HashSet<string>> DetailCache
        -static bool _initialized
        -static Lock Lock
        +HashSet<string> GetProvinces()
        +HashSet<string> GetCities(string province)
        +HashSet<CountyItem> GetCounties(string city)
        +HashSet<string> GetDetails(string countyCode)
    }
    class CountyItem {
        +string Name
        +string Code
    }
    DefaultRegionService "1" o-- "*" CountyItem
Loading

File-Level Changes

Change Details Files
Add new SelectProvince component
  • Created .razor markup inheriting SelectRegionBase with dropdown and clear behavior
  • Implemented code-behind for multi/single selection and value management
  • Added dedicated CSS for province dropdown styling and theming
Components/SelectProvince.razor
Components/SelectProvince.razor.cs
Components/SelectProvince.razor.css
Simplify OnSelectProvince logic in SelectCity
  • Guard against non-multiple selection with early return
  • Replaced if/else chain with switch expression for city sets
  • Moved CurrentValue assignment outside loop and cleaned up removal logic
Components/SelectCity.razor.cs
Consolidate InputId in SelectRegionBase
  • Added protected InputId property to SelectRegionBase
  • Removed duplicate InputId declarations from SelectCity and SelectRegion
Components/SelectRegionBase.cs
Components/SelectCity.razor.cs
Components/SelectRegion.razor.cs
Standardize caching and locking in DefaultRegionService
  • Renamed cache and lock fields to PascalCase
  • Unified lock objects under a single static field
  • Fixed span slicing syntax and empty set fallbacks
Services/DefaultRegionService.cs
Update dark theme CSS variables
  • Adjusted body color variable in SelectCity and SelectRegion dark themes
  • Verified consistency across dropdown menus
Components/SelectCity.razor.css
Components/SelectRegion.razor.css

Assessment against linked issues

Issue Objective Addressed Explanation
#607 Implement a SelectProvince component in the codebase.
#607 Add corresponding styles for the SelectProvince component.
#607 Integrate SelectProvince with existing region selection infrastructure (inheritance, service usage, etc).

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 dacbe4c into master Oct 17, 2025
1 of 2 checks passed
@ArgoZhang ArgoZhang deleted the feat-region branch October 17, 2025 01:10
Copy link
Copy Markdown

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

  • The two static lock fields in DefaultRegionService now share the same name and scope—rename or consolidate them and reintroduce the separate detail lock if you still need one.
  • Using the literal [] to initialize or return an empty HashSet will not compile—switch to new HashSet() or a target‐typed new() instead.
  • In SelectCity.OnSelectProvince, clicking a province when IsMultiple=false does nothing—consider setting CurrentValue for single‐select mode to improve UX.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The two static lock fields in DefaultRegionService now share the same name and scope—rename or consolidate them and reintroduce the separate detail lock if you still need one.
- Using the literal [] to initialize or return an empty HashSet<T> will not compile—switch to new HashSet<T>() or a target‐typed new() instead.
- In SelectCity.OnSelectProvince, clicking a province when IsMultiple=false does nothing—consider setting CurrentValue for single‐select mode to improve UX.

## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs:54-56` </location>
<code_context>
+            "特别行政区" => SpecialAdministrativeRegions,
+            _ => GetCities(province)
+        };
+        foreach (var city in cities.Where(city => !_values.Remove(city)))
+        {
+            _values.Add(city);
</code_context>

<issue_to_address>
**suggestion:** Use of _values.Remove(city) in Where clause may be confusing.

Mutating _values within the Where clause can cause unintended side effects and obscure the code's intent. Please separate the mutation from the filtering to improve maintainability and prevent subtle bugs.

```suggestion
        var citiesToAdd = cities.Where(city => !_values.Contains(city));
        foreach (var city in citiesToAdd)
        {
            _values.Add(city);
```
</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.

Copy link
Copy Markdown

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

Adds a new SelectProvince component to the Region package, refactors shared behavior into the base class, and makes minor styling and parsing improvements.

  • Introduces SelectProvince (UI, logic, and styles) with optional multi-select support.
  • Centralizes InputId in SelectRegionBase and removes duplication in child components.
  • Refactors DefaultRegionService field names and updates a small parsing slice; tweaks dark theme colors; bumps package version to 9.0.3.

Reviewed Changes

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

Show a summary per file
File Description
src/components/BootstrapBlazor.Region/Services/DefaultRegionService.cs Renames caches/lock fields, uses a single lock field name, and updates a string slice in parsing.
src/components/BootstrapBlazor.Region/Components/SelectRegionBase.cs Adds protected InputId for reuse by region-select components.
src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.cs Removes now-duplicated InputId (moved to base).
src/components/BootstrapBlazor.Region/Components/SelectRegion.razor.css Adjusts dark theme body color.
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.cs Refactors province selection logic for multi-select path.
src/components/BootstrapBlazor.Region/Components/SelectCity.razor.css Aligns dark theme body color with SelectRegion.
src/components/BootstrapBlazor.Region/Components/SelectProvince.razor New component markup for province selection.
src/components/BootstrapBlazor.Region/Components/SelectProvince.razor.cs New component logic including multi-select toggling.
src/components/BootstrapBlazor.Region/Components/SelectProvince.razor.css New component styles leveraging region CSS variables.
src/components/BootstrapBlazor.Region/BootstrapBlazor.Region.csproj Bumps package Version to 9.0.3.

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

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(Region): add SelectProvince component

2 participants