fix: address review feedback on TabSubgraphInputs drag-and-drop

- Fix stale index closures after reorder: watch promotionEntries and
  re-register drag handlers via nextTick so consecutive drags pass
  correct fromIndex/toIndex to movePromotion
- Replace `as number` type assertion with typeof guard per project guidelines
- Tighten cleanup test assertion to toHaveBeenCalledTimes(2) to verify
  both registered handlers are disposed on unmount
This commit is contained in:
Kelly Yang
2026-04-20 21:12:22 -07:00
parent c3ef748119
commit 22d32fee8c
2 changed files with 5 additions and 3 deletions

View File

@@ -138,8 +138,8 @@ describe('TabSubgraphInputs drag-and-drop', () => {
unmount()
expect(mockDraggableCleanup).toHaveBeenCalled()
expect(mockDropTargetCleanup).toHaveBeenCalled()
expect(mockDraggableCleanup).toHaveBeenCalledTimes(2)
expect(mockDropTargetCleanup).toHaveBeenCalledTimes(2)
})
it('calls movePromotion with correct indices when an item is dropped', () => {

View File

@@ -177,7 +177,8 @@ function setDraggableState() {
dropTargetForElements({
element: item,
onDrop: ({ source }) => {
const fromIndex = source.data.index as number
const fromIndex = source.data.index
if (typeof fromIndex !== 'number') return
if (fromIndex === index) return
promotionStore.movePromotion(
node.rootGraph.id,
@@ -197,6 +198,7 @@ function setDraggableState() {
watchDebounced(searchedWidgetsList, () => setDraggableState(), {
debounce: 100
})
watch(promotionEntries, () => nextTick(setDraggableState))
onMounted(() => setDraggableState())
onBeforeUnmount(() => cleanupDragAndDrop())