From dadad2d95b0242f1a05295a136df96ba3a4e249f Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Mon, 7 Aug 2023 23:32:31 -0400 Subject: [PATCH] Fix handling drag --- .../src/ActionList.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/redux-devtools-inspector-monitor/src/ActionList.tsx b/packages/redux-devtools-inspector-monitor/src/ActionList.tsx index 093741a4..563bb47e 100644 --- a/packages/redux-devtools-inspector-monitor/src/ActionList.tsx +++ b/packages/redux-devtools-inspector-monitor/src/ActionList.tsx @@ -115,10 +115,20 @@ export default function ActionList>({ const handleDragEnd = useCallback( ({ active, over }: DragEndEvent) => { if (over && active.id !== over.id) { - onReorderAction(active.id as number, over.id as number); + const activeIndex = actionIds.indexOf(active.id as number); + const overIndex = actionIds.indexOf(over.id as number); + + const beforeActionId = + overIndex < activeIndex + ? (over.id as number) + : overIndex < actionIds.length - 1 + ? actionIds[overIndex + 1] + : actionIds.length; + + onReorderAction(active.id as number, beforeActionId); } }, - [onReorderAction], + [actionIds, onReorderAction], ); const lowerSearchValue = searchValue && searchValue.toLowerCase();