refactor: handle based updates post collection move

This commit is contained in:
jamesgeorge007
2024-05-09 21:03:56 +05:30
parent 141652ffb6
commit e342e53db1
4 changed files with 213 additions and 38 deletions

View File

@@ -1569,10 +1569,10 @@ const dropToRoot = async ({ dataTransfer }: DragEvent) => {
restCollectionState.value.length - 1
).toString()
updateSaveContextForAffectedRequests(
draggedCollectionIndex,
destinationRootCollectionIndex
)
// updateSaveContextForAffectedRequests(
// draggedCollectionIndex,
// destinationRootCollectionIndex
// )
const destinationRootCollectionHandleResult =
await workspaceService.getCollectionHandle(
@@ -1808,43 +1808,43 @@ const dropCollection = async (payload: {
// Hence, we need to reduce the destination root collection index by 1
// This only applies to the case when the destination collection lies below the dragged collection
let resolvedDestinationCollectionIndex = destinationCollectionIndex
// let resolvedDestinationCollectionIndex = destinationCollectionIndex
const draggedRootCollectionIndex = parseInt(
pathToIndex(draggedCollectionIndex)[0]
)
const destinationRootCollectionIndex = parseInt(
pathToIndex(destinationCollectionIndex)[0]
)
// const draggedRootCollectionIndex = parseInt(
// pathToIndex(draggedCollectionIndex)[0]
// )
// const destinationRootCollectionIndex = parseInt(
// pathToIndex(destinationCollectionIndex)[0]
// )
if (
isAlreadyInRoot(draggedCollectionIndex) &&
destinationRootCollectionIndex > draggedRootCollectionIndex
) {
resolvedDestinationCollectionIndex = `${
destinationRootCollectionIndex - 1
}/${pathToIndex(destinationCollectionIndex).slice(1).join("/")}`
// if (
// isAlreadyInRoot(draggedCollectionIndex) &&
// destinationRootCollectionIndex > draggedRootCollectionIndex
// ) {
// resolvedDestinationCollectionIndex = `${
// destinationRootCollectionIndex - 1
// }/${pathToIndex(destinationCollectionIndex).slice(1).join("/")}`
resolvedDestinationCollectionIndex =
resolvedDestinationCollectionIndex.endsWith("/")
? resolvedDestinationCollectionIndex.slice(0, -1)
: resolvedDestinationCollectionIndex
}
// resolvedDestinationCollectionIndex =
// resolvedDestinationCollectionIndex.endsWith("/")
// ? resolvedDestinationCollectionIndex.slice(0, -1)
// : resolvedDestinationCollectionIndex
// }
resolveSaveContextOnCollectionReorder({
lastIndex: pathToLastIndex(draggedCollectionIndex),
newIndex: -1,
folderPath: draggedParentCollectionIndex,
length: getFoldersByPath(
restCollectionState.value,
draggedParentCollectionIndex
).length,
})
// resolveSaveContextOnCollectionReorder({
// lastIndex: pathToLastIndex(draggedCollectionIndex),
// newIndex: -1,
// folderPath: draggedParentCollectionIndex,
// length: getFoldersByPath(
// restCollectionState.value,
// draggedParentCollectionIndex
// ).length,
// })
updateSaveContextForAffectedRequests(
draggedCollectionIndex,
`${resolvedDestinationCollectionIndex}/${totalChildCollectionsInDestinationCollection}`
)
// updateSaveContextForAffectedRequests(
// draggedCollectionIndex,
// `${resolvedDestinationCollectionIndex}/${totalChildCollectionsInDestinationCollection}`
// )
const destinationCollectionHandleResult =
await workspaceService.getCollectionHandle(