diff --git a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue index dfdbf57f1..b7b043d3e 100644 --- a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue +++ b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue @@ -1812,18 +1812,15 @@ const dropCollection = async (payload: { : resolvedDestinationCollectionIndex } - resolveSaveContextOnCollectionReorder( - { - lastIndex: pathToLastIndex(draggedCollectionIndex), - newIndex: -1, - folderPath: draggedParentCollectionIndex, - length: getFoldersByPath( - restCollectionState.value, - draggedParentCollectionIndex - ).length, - }, - "drop" - ) + resolveSaveContextOnCollectionReorder({ + lastIndex: pathToLastIndex(draggedCollectionIndex), + newIndex: -1, + folderPath: draggedParentCollectionIndex, + length: getFoldersByPath( + restCollectionState.value, + draggedParentCollectionIndex + ).length, + }) updateSaveContextForAffectedRequests( draggedCollectionIndex, diff --git a/packages/hoppscotch-common/src/helpers/collection/collection.ts b/packages/hoppscotch-common/src/helpers/collection/collection.ts index 21b7035c6..c9cea6913 100644 --- a/packages/hoppscotch-common/src/helpers/collection/collection.ts +++ b/packages/hoppscotch-common/src/helpers/collection/collection.ts @@ -22,15 +22,12 @@ import { HandleRef } from "~/services/new-workspace/handle" * @returns */ -export function resolveSaveContextOnCollectionReorder( - payload: { - lastIndex: number - newIndex: number - folderPath: string - length?: number // better way to do this? now it could be undefined - }, - type: "remove" | "drop" = "remove" -) { +export function resolveSaveContextOnCollectionReorder(payload: { + lastIndex: number + newIndex: number + folderPath: string + length?: number // better way to do this? now it could be undefined +}) { const { lastIndex, folderPath, length } = payload let { newIndex } = payload @@ -45,12 +42,6 @@ export function resolveSaveContextOnCollectionReorder( if (newIndex === -1) { // if (newIndex === -1) remove it from the map because it will be deleted affectedIndexes.delete(lastIndex) - // when collection deleted opended requests from that collection be affected - if (type === "remove") { - resetSaveContextForAffectedRequests( - folderPath ? `${folderPath}/${lastIndex}` : lastIndex.toString() - ) - } } // add folder path as prefix to the affected indexes 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 a1f169909..a20d05025 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 @@ -59,6 +59,10 @@ import { WorkspaceRequest, } from "~/services/new-workspace/workspace" +import { + getFoldersByPath, + resolveSaveContextOnCollectionReorder, +} from "~/helpers/collection/collection" import { getRequestsByPath, resolveSaveContextOnRequestReorder, @@ -279,10 +283,9 @@ export class PersonalWorkspaceProviderService const { collectionID } = collectionHandle.value.data const isRootCollection = collectionID.split("/").length === 1 + const collectionIndex = parseInt(collectionID) if (isRootCollection) { - const collectionIndex = parseInt(collectionID) - const collectionToRemove = navigateToFolderWithIndexPath( restCollectionStore.value.state, [collectionIndex] @@ -322,6 +325,26 @@ export class PersonalWorkspaceProviderService } } + if (isRootCollection) { + resolveSaveContextOnCollectionReorder({ + lastIndex: collectionIndex, + newIndex: -1, + folderPath: "", // root folder + length: restCollectionStore.value.state.length, + }) + } else { + const parentCollectionID = collectionID.split("/").slice(0, -1).join("/") // remove last folder to get parent folder + resolveSaveContextOnCollectionReorder({ + lastIndex: this.pathToLastIndex(collectionID), + newIndex: -1, + folderPath: parentCollectionID, + length: getFoldersByPath( + restCollectionStore.value.state, + parentCollectionID + ).length, + }) + } + return Promise.resolve(E.right(undefined)) }