mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 15:44:28 +00:00
fix(webui): persist field order on drag and drop
The handleDragEnd handlers in the Manage Fields dialog and Fields dropdown guarded reordering on source.id !== target.id. With dnd-kit react's OptimisticSortingPlugin (enabled by default), the drop target always resolves to the dragged item itself, so the guard was never true and the order API was never called. Detect moves via the sortable-specific index/initialIndex properties on the source instead, and reorder the rendered (grouped/search-filtered) subset before merging back into the full field list. All field groups are now reorderable in the dialog.
This commit is contained in:
@@ -4,6 +4,23 @@ export function arrayMove<T>(array: T[], from: number, to: number): T[] {
|
||||
return newArray
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders a subset of fields (a grouped/filtered view) within the full list.
|
||||
* `subset` must appear in `full` in the same relative order (filtering preserves order).
|
||||
*/
|
||||
export function reorderFieldSubset<T extends { id?: string | null }>(
|
||||
full: T[],
|
||||
subset: T[],
|
||||
from: number,
|
||||
to: number,
|
||||
): T[] {
|
||||
if (from === to) return full
|
||||
const reordered = arrayMove(subset, from, to)
|
||||
const subsetIds = new Set(subset.map((f) => f.id))
|
||||
let i = 0
|
||||
return full.map((f) => (subsetIds.has(f.id) ? reordered[i++] : f))
|
||||
}
|
||||
|
||||
interface SafeFileSystemEntry {
|
||||
name: string
|
||||
isFile: boolean
|
||||
|
||||
Reference in New Issue
Block a user