fix: reordering last request bug and its UX (#2967)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Nivedin
2023-04-05 21:35:14 +05:30
committed by GitHub
parent 62058d5dfe
commit 8590a9a110
4 changed files with 134 additions and 92 deletions

View File

@@ -1395,6 +1395,27 @@ const checkIfCollectionIsAParentOfTheChildren = (
return false
}
const isMoveToSameLocation = (
draggedItemPath: string,
destinationPath: string
) => {
const draggedItemPathArr = pathToIndex(draggedItemPath)
const destinationPathArr = pathToIndex(destinationPath)
if (draggedItemPathArr.length > 0) {
const draggedItemParentPathArr = draggedItemPathArr.slice(
0,
draggedItemPathArr.length - 1
)
if (isEqual(draggedItemParentPathArr, destinationPathArr)) {
return true
} else {
return false
}
}
}
/**
* This function is called when the user moves the collection
* to a different collection or folder
@@ -1419,6 +1440,13 @@ const dropCollection = (payload: {
return
}
//check if the collection is being moved to its own parent
if (
isMoveToSameLocation(collectionIndexDragged, destinationCollectionIndex)
) {
return
}
const parentFolder = collectionIndexDragged
.split("/")
.slice(0, -1)
@@ -1556,10 +1584,14 @@ const isSameSameParent = (
draggedItemIndex.length === 1
) {
return draggedItemIndex[0] === destinationCollectionIndex
} else if (destinationItemPath === null && draggedItemIndex.length !== 1) {
} else if (
destinationItemPath === null &&
draggedItemIndex.length !== 1 &&
destinationCollectionIndex !== null
) {
const dragedItemParent = draggedItemIndex.slice(0, -1)
return dragedItemParent[0] === destinationCollectionIndex
return dragedItemParent.join("/") === destinationCollectionIndex
} else {
if (destinationItemPath === null) return false
const destinationItemIndex = pathToIndex(destinationItemPath)