mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-28 13:31:32 +08:00
perf(DraggableList): skip update if dnd to the same position (#9255)
This commit is contained in:
parent
e652c1d783
commit
0b8c6ee536
@ -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', () => {
|
||||
|
||||
@ -38,8 +38,10 @@ const DraggableList: FC<Props<any>> = ({
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -82,8 +82,10 @@ function DraggableVirtualList<T>({
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user