From e0083aa70daebcee321672b96a7fd417d11f57e0 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 16 May 2024 13:25:12 +0530 Subject: [PATCH] fix: handle based updates post collection move to a sibling level collection below it --- .../new-workspace/providers/personal.workspace.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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