Conversation
Reviewer's GuideThis PR refactors the toggle logic for multi-select items by introducing a dedicated ToggleItem method, overloading ToggleRow to accept an index string for JS interop, and updating the component markup to pass item indices via data attributes, thereby restoring close-button functionality. Sequence diagram for close button click interaction in MultiSelectGenericsequenceDiagram
participant User as actor User
participant UI as "MultiSelectGeneric UI"
participant Component as "MultiSelectGeneric Component"
User->>UI: Click close button on item
UI->>Component: ToggleRow(item index as string)
Component->>Component: ToggleRow(SelectedItem) (internal)
Component->>Component: Remove item from SelectedItems
Component->>Component: SetValue()
Component->>UI: StateHasChanged()
Class diagram for updated MultiSelectGeneric component toggle logicclassDiagram
class MultiSelectGeneric {
+Task ConfirmSelectedItem(int index)
+Task ToggleRow(string val)
-Task ToggleRow(SelectedItem<TValue> item)
-string? GetValueString(SelectedItem<TValue> item)
-Task ToggleItem(SelectedItem<TValue> val)
-int _min
-List<SelectedItem<TValue>> SelectedItems
-List<SelectedItem<TValue>> Rows
-bool _isToggle
-bool IsPopover
-bool IsDisabled
+Task SetValue()
}
MultiSelectGeneric o-- SelectedItem
class SelectedItem {
+TValue Value
}
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.
Pull Request Overview
This PR fixes an issue where the close button in the MultiSelectGeneric component was not working properly. The fix introduces a new overloaded ToggleRow method that accepts a string parameter for JavaScript invocation and separates the toggle functionality for different use cases.
- Introduces a new
ToggleRow(string val)method that can be called from JavaScript - Separates row toggling logic into
ToggleRowandToggleItemmethods for different contexts - Adds
GetValueStringmethod to provide string representation of item indices for popover scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| MultiSelectGeneric.razor.cs | Refactors toggle functionality with new overloaded methods and fixes close button behavior |
| MultiSelectGeneric.razor | Updates template to use correct toggle methods and adds data attribute for close button |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| await ToggleRow(item); | ||
| } | ||
| } | ||
|
|
||
| private async Task ToggleRow(SelectedItem<TValue> item) |
There was a problem hiding this comment.
This creates infinite recursion. The method ToggleRow(string val) calls ToggleRow(item) which should be calling the private ToggleRow(SelectedItem<TValue> item) method instead.
| await ToggleRow(item); | |
| } | |
| } | |
| private async Task ToggleRow(SelectedItem<TValue> item) | |
| await ToggleRowInternal(item); | |
| } | |
| } | |
| private async Task ToggleRowInternal(SelectedItem<TValue> item) |
| private async Task ToggleRow(SelectedItem<TValue> item) | ||
| { | ||
| SelectedItems.Remove(item); | ||
|
|
||
| _isToggle = true; | ||
| // 更新选中值 | ||
| await SetValue(); | ||
| } |
There was a problem hiding this comment.
This method only removes items and doesn't check the IsDisabled state, unlike the original ToggleRow implementation. Consider adding the disabled check for consistency.
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Components/SelectGeneric/MultiSelectGeneric.razor.cs:400` </location>
<code_context>
+ public async Task ToggleRow(string val)
{
- if (!IsDisabled)
+ if (int.TryParse(val, out var index) && index >= 0 && index < SelectedItems.Count)
{
- var item = SelectedItems.FirstOrDefault(i => Equals(i.Value, val.Value));
</code_context>
<issue_to_address>
**suggestion:** Handle non-integer or out-of-range values more explicitly.
Consider adding error handling or logging for invalid or out-of-range values to prevent silent failures and aid debugging.
</issue_to_address>
### Comment 2
<location> `src/BootstrapBlazor/Components/SelectGeneric/MultiSelectGeneric.razor.cs:416` </location>
<code_context>
+ await SetValue();
+ }
+
+ private string? GetValueString(SelectedItem<TValue> item) => IsPopover ? SelectedItems.IndexOf(item).ToString() : null;
+
+ private async Task ToggleItem(SelectedItem<TValue> val)
</code_context>
<issue_to_address>
**suggestion:** Consider handling case where item is not in SelectedItems.
IndexOf returns -1 if the item is not found, which may not be appropriate for GetValueString. Consider returning null or a different sentinel value instead.
```suggestion
private string? GetValueString(SelectedItem<TValue> item)
{
if (!IsPopover)
{
return null;
}
var index = SelectedItems.IndexOf(item);
return index >= 0 ? index.ToString() : null;
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| await SetValue(); | ||
| } | ||
|
|
||
| private string? GetValueString(SelectedItem<TValue> item) => IsPopover ? SelectedItems.IndexOf(item).ToString() : null; |
There was a problem hiding this comment.
suggestion: Consider handling case where item is not in SelectedItems.
IndexOf returns -1 if the item is not found, which may not be appropriate for GetValueString. Consider returning null or a different sentinel value instead.
| private string? GetValueString(SelectedItem<TValue> item) => IsPopover ? SelectedItems.IndexOf(item).ToString() : null; | |
| private string? GetValueString(SelectedItem<TValue> item) | |
| { | |
| if (!IsPopover) | |
| { | |
| return null; | |
| } | |
| var index = SelectedItems.IndexOf(item); | |
| return index >= 0 ? index.ToString() : null; | |
| } |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6754 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 739 739
Lines 31713 31713
Branches 4462 4462
=========================================
Hits 31713 31713
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6751
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Fix the close button in MultiSelectGeneric by refactoring and unifying the toggle logic, and correctly wiring JS-invokable handlers to update the selected items.
Bug Fixes:
Enhancements: