diff --git a/src/renderer/src/components/DraggableList/__tests__/DraggableList.test.tsx b/src/renderer/src/components/DraggableList/__tests__/DraggableList.test.tsx index a570f58bcf..ed53736ed5 100644 --- a/src/renderer/src/components/DraggableList/__tests__/DraggableList.test.tsx +++ b/src/renderer/src/components/DraggableList/__tests__/DraggableList.test.tsx @@ -157,8 +157,7 @@ describe('DraggableList', () => { // 模拟拖拽到自身 window.triggerOnDragEnd({ source: { index: 1 }, destination: { index: 1 } }, {}) - expect(onUpdate).toHaveBeenCalledTimes(1) - expect(onUpdate.mock.calls[0][0]).toEqual(list) + expect(onUpdate).toHaveBeenCalledTimes(0) }) }) @@ -175,8 +174,7 @@ describe('DraggableList', () => { // 拖拽自身 window.triggerOnDragEnd({ source: { index: 0 }, destination: { index: 0 } }, {}) - expect(onUpdate).toHaveBeenCalledTimes(1) - expect(onUpdate.mock.calls[0][0]).toEqual(list) + expect(onUpdate).toHaveBeenCalledTimes(0) }) it('should not crash if callbacks are undefined', () => { diff --git a/src/renderer/src/components/DraggableList/list.tsx b/src/renderer/src/components/DraggableList/list.tsx index 0f23a69978..18bf7a6d20 100644 --- a/src/renderer/src/components/DraggableList/list.tsx +++ b/src/renderer/src/components/DraggableList/list.tsx @@ -38,8 +38,10 @@ const DraggableList: FC> = ({ if (result.destination) { const sourceIndex = result.source.index const destIndex = result.destination.index - const reorderAgents = droppableReorder(list, sourceIndex, destIndex) - onUpdate(reorderAgents) + if (sourceIndex !== destIndex) { + const reorderAgents = droppableReorder(list, sourceIndex, destIndex) + onUpdate(reorderAgents) + } } } diff --git a/src/renderer/src/components/DraggableList/virtual-list.tsx b/src/renderer/src/components/DraggableList/virtual-list.tsx index b8020aa051..69b0ced667 100644 --- a/src/renderer/src/components/DraggableList/virtual-list.tsx +++ b/src/renderer/src/components/DraggableList/virtual-list.tsx @@ -82,8 +82,10 @@ function DraggableVirtualList({ if (onUpdate && result.destination) { const sourceIndex = result.source.index const destIndex = result.destination.index - const reorderAgents = droppableReorder(list, sourceIndex, destIndex) - onUpdate(reorderAgents) + if (sourceIndex !== destIndex) { + const reorderAgents = droppableReorder(list, sourceIndex, destIndex) + onUpdate(reorderAgents) + } } }