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:
yiling
2026-08-05 15:52:58 +08:00
parent 1104ec36cc
commit d73f7f81a1
3 changed files with 68 additions and 49 deletions
+17
View File
@@ -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