diff --git a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts index 138c5e91f..97545d27a 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts @@ -948,6 +948,11 @@ export class PersonalWorkspaceProviderService .slice(0, draggedCollectionIDStrLength) .join("/") + const destinationParentCollectionIDSubset = destinationCollectionID + .split("/") + .slice(0, -1) + .join("/") + // Reduce `1` from the index position to account for the dragged collection // Dragged collection doesn't exist anymore at the previous level const collectionIDSubsetIndexPos = Number( @@ -957,10 +962,7 @@ export class PersonalWorkspaceProviderService // Replace the destination collection ID with `1` reduced from the index position const replacedDestinationCollectionID = destinationCollectionID.replace( destinationCollectionIDSubset, - `${destinationCollectionIDSubset - .split("/") - .slice(0, -1) - .join("/")}/${collectionIDSubsetIndexPos}` + `${destinationParentCollectionIDSubset}/${collectionIDSubsetIndexPos}` ) const resolvedDestinationCollectionIDPrefix = this.isAlreadyInRoot( @@ -1023,6 +1025,11 @@ export class PersonalWorkspaceProviderService 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 const newAffectedCollectionID = `${draggedParentCollectionID}/${ affectedCollectionIndexPos - 1