fix: handle based updates post collection move to a sibling level collection below it

This commit is contained in:
jamesgeorge007
2024-05-16 13:25:12 +05:30
parent 25b0818016
commit e0083aa70d

View File

@@ -948,6 +948,11 @@ export class PersonalWorkspaceProviderService
.slice(0, draggedCollectionIDStrLength) .slice(0, draggedCollectionIDStrLength)
.join("/") .join("/")
const destinationParentCollectionIDSubset = destinationCollectionID
.split("/")
.slice(0, -1)
.join("/")
// Reduce `1` from the index position to account for the dragged collection // Reduce `1` from the index position to account for the dragged collection
// Dragged collection doesn't exist anymore at the previous level // Dragged collection doesn't exist anymore at the previous level
const collectionIDSubsetIndexPos = Number( const collectionIDSubsetIndexPos = Number(
@@ -957,10 +962,7 @@ export class PersonalWorkspaceProviderService
// Replace the destination collection ID with `1` reduced from the index position // Replace the destination collection ID with `1` reduced from the index position
const replacedDestinationCollectionID = destinationCollectionID.replace( const replacedDestinationCollectionID = destinationCollectionID.replace(
destinationCollectionIDSubset, destinationCollectionIDSubset,
`${destinationCollectionIDSubset `${destinationParentCollectionIDSubset}/${collectionIDSubsetIndexPos}`
.split("/")
.slice(0, -1)
.join("/")}/${collectionIDSubsetIndexPos}`
) )
const resolvedDestinationCollectionIDPrefix = this.isAlreadyInRoot( const resolvedDestinationCollectionIDPrefix = this.isAlreadyInRoot(
@@ -1023,6 +1025,11 @@ export class PersonalWorkspaceProviderService
const affectedCollectionID = `${draggedParentCollectionID}/${affectedCollectionIndexPos}` const affectedCollectionID = `${draggedParentCollectionID}/${affectedCollectionIndexPos}`
// Return early for the case when a collection is moved to a sibling collection below it where the destination collection becomes one among the affected collections
if (resolvedDestinationCollectionID.startsWith(affectedCollectionID)) {
return
}
// The index position will be reduced by `1` for the affected collections // The index position will be reduced by `1` for the affected collections
const newAffectedCollectionID = `${draggedParentCollectionID}/${ const newAffectedCollectionID = `${draggedParentCollectionID}/${
affectedCollectionIndexPos - 1 affectedCollectionIndexPos - 1