Browse Source

fix(nc-gui): handle base move edge cases

pull/7528/head
Ramesh Mane 9 months ago
parent
commit
6fa4d7a6e3
  1. 15
      packages/nc-gui/components/dashboard/TreeView/index.vue

15
packages/nc-gui/components/dashboard/TreeView/index.vue

@ -195,19 +195,20 @@ const onMove = async (_event: { moved: { newIndex: number; oldIndex: number; ele
if (!element?.id) return
// set default order value as 0 if item not found
const previousItem = basesList.value[newIndex - 1]?.order ? { order: basesList.value[newIndex - 1].order } : { order: 0 }
const nextItem = basesList.value[newIndex + 1]?.order ? { order: basesList.value[newIndex + 1].order } : { order: 0 }
let nextOrder: number
// set new order value based on the new order of the items
if (basesList.value.length - 1 === newIndex) {
nextOrder = parseFloat(String(previousItem.order)) + 1
// If moving to the end, set nextOrder greater than the maximum order in the list
nextOrder = Math.max(...basesList.value.map((item) => item?.order ?? 0)) + 1
} else if (newIndex === 0) {
nextOrder = parseFloat(String(nextItem.order)) / 2
// If moving to the beginning, set nextOrder smaller than the minimum order in the list
nextOrder = Math.min(...basesList.value.map((item) => item?.order ?? 0)) / 2
} else {
nextOrder = (parseFloat(String(previousItem.order)) + parseFloat(String(nextItem.order))) / 2
nextOrder =
(parseFloat(String(basesList.value[newIndex - 1]?.order ?? 0)) +
parseFloat(String(basesList.value[newIndex + 1]?.order ?? 0))) /
2
}
const _nextOrder = !isNaN(Number(nextOrder)) ? nextOrder : oldIndex

Loading…
Cancel
Save