Browse Source

fix(gui-v2): view sorting not persisting correctly

pull/2837/head
braks 2 years ago
parent
commit
1c2651bbe9
  1. 12
      packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue

12
packages/nc-gui-v2/components/smartsheet/sidebar/MenuTop.vue

@ -78,21 +78,21 @@ function initializeSortable(el: HTMLElement) {
const currentItem: Record<string, any> = views.value[oldIndex]
// get items meta of before and after the moved item
const itemBefore: Record<string, any> = views.value[newIndex]
const itemAfter: Record<string, any> = views.value[newIndex + 1]
const nextItem: Record<string, any> = views.value[newIndex]
const previousItem: Record<string, any> = views.value[newIndex + 1]
let nextOrder: number
// set new order value based on the new order of the items
if (views.value.length - 1 === newIndex) {
nextOrder = itemBefore.order + 1
nextOrder = parseFloat(nextItem.order) + 1
} else if (newIndex === 0) {
nextOrder = itemAfter.order / 2
nextOrder = parseFloat(nextItem.order) / 2
} else {
nextOrder = (itemBefore.order + itemAfter.order) / 2
nextOrder = (parseFloat(nextItem.order) + parseFloat(previousItem.order)) / 2
}
await api.dbView.update(currentItem.id, { order: nextOrder.toString() })
await api.dbView.update(currentItem.id, { order: !isNaN(Number(nextOrder)) ? nextOrder.toString() : oldIndex.toString() })
},
animation: 150,
})

Loading…
Cancel
Save