feat(Region): add SelectProvince component #608
Conversation
Reviewer's GuideThis 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 componentsclassDiagram
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
Class diagram for DefaultRegionService cache and lock refactorclassDiagram
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
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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.
Link issues
fixes #607
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add a new SelectProvince component and refactor region selection components and services for improved code reuse and consistency.
New Features:
Enhancements: