fix: Folder and Resource Selection Interaction Abnormality#4260
fix: Folder and Resource Selection Interaction Abnormality#4260shaohuzhang1 merged 1 commit intov2from
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
||
| multipleSelection.value = multipleTableRef.value.getSelectionRows() | ||
| } else { | ||
| multipleSelection.value = val |
There was a problem hiding this comment.
The code you've provided is mostly correct with some minor optimizations and improvements:
- Simplified Condition: The condition inside the
ifstatement can be simplified to directly check if an item exists inmultipleSelection. This avoids iterating over the entire array twice.
Here's your updated code with this optimization:
const select = (val: any[], active: any) => {
TreeToFlatten([active])
.filter((item: any) => item.id !== active.id)
.forEach((item: any) => {
const isSelected = multipleSelection.value.some(s => s.id === item.id);
// Toggle row selection only if it is not already selected
if (!isSelected && multipleTableRef.value)
multipleTableRef.value.toggleRowSelection(item, true);
});
multipleSelection.value = multipleTableRef.value.getSelectionRows();
};Key Improvements:
- Single Iteration Check: Reduced the need for filtering out items that cannot exist in
multipleSelection. - Direct Selection Check: Use
some()to check if an item is already selected without needing to iterate further throughmultipleSelection.
These changes make the function more efficient while maintaining its functionality.
fix: Folder and Resource Selection Interaction Abnormality