Enable multiDrag only when a selection class is configured - #16
Conversation
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes multi-selection configuration for the SortableJS integration by ensuring MultiDrag is only enabled when a selection CSS class is actually configured, and by hardening event handling for cases where MultiDrag-specific event properties are absent.
Changes:
- Compute
multiDragvia a truthiness check oncssForSelection(sonull/''correctly disable MultiDrag). - Pass
undefined(notnull) forselectedClasswhen no selection class is configured. - Guard
event.newIndiciesusage inonUpdate/onRemoveto avoidArray.from(undefined)when MultiDrag is off.
Comments suppressed due to low confidence (1)
BlazorSortableList.Lib/SortableList.razor.js:129
- Same issue as
onUpdate: if MultiDrag is off,oldDraggableIndex/newDraggableIndexmay be missing and JS interop will attempt to passundefinedintoOnRemoveJS(int, int, ...). Falling back tooldIndex/newIndexmakes the handler robust across Sortable configurations/versions.
let oldIndex = event.oldDraggableIndex;
let newIndex = event.newDraggableIndex;
// in multi selection mode we have newIndicies only
// Only the MultiDrag plugin adds these, so they are undefined when multiDrag is off.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let oldIndex = event.oldDraggableIndex; | ||
| let newIndex = event.newDraggableIndex; | ||
| // in multi selection mode we have newIndicies only | ||
| let newIndicies = Array.from(event.newIndicies); | ||
| // Only the MultiDrag plugin adds these, so they are undefined when multiDrag is off. | ||
| let newIndicies = event.newIndicies ? Array.from(event.newIndicies) : []; |
There was a problem hiding this comment.
I do not think this one holds. oldDraggableIndex/newDraggableIndex are core SortableJS state, not MultiDrag additions - they are module-level variables in src/Sortable.js, assigned in _prepareDragStart, _onDragOver and _onDrop, and included in every dispatched event regardless of which plugins are mounted.
The genuinely MultiDrag-only properties are oldIndicies/newIndicies, which come from the plugin's eventProperties() - and those are exactly what this PR guards. Leaving the draggable indices as they are.
Problem
_cssForSelectionis an uninitialisedstringfield and is only assigned whensettings.MultiSelectionis set. .NET marshals an unset string as JSONnull, neverundefined, andtypeof null === 'object'— so this expression is always true. Every list is constructed withmultiDrag: trueandselectedClass: null, whether or not multi-selection was requested.The
Array.from(event.newIndicies)calls inonUpdate/onRemovecurrently only survive because of this:oldIndicies/newIndiciesare added exclusively by the MultiDrag plugin'seventProperties(), so with multiDrag correctly off they areundefinedandArray.fromwould throw.Implementation
multiDragis now a truthiness check oncssForSelection, sonulland''both correctly disable it.selectedClasspassesundefinedinstead ofnullwhen unset, so SortableJS applies its own default rather than a null class.newIndiciesis guarded in bothonUpdateandonRemove, falling back to[]— required now that multiDrag can actually be off.