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 b158b89fa..b0834a65a 100644 --- a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue +++ b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue @@ -1452,18 +1452,10 @@ const exportCollection = async (collectionIndexPath: string) => { return } - const collection = navigateToFolderWithIndexPath( - restCollectionState.value, - collectionIndexPath.split("/").map((id) => parseInt(id)) - ) as HoppCollection - - const result = await workspaceService.exportRESTCollection( - collectionHandle, - collection - ) + const result = await workspaceService.exportRESTCollection(collectionHandle) if (E.isLeft(result)) { - // INVALID_COLLECTION_HANDLE + // INVALID_COLLECTION_HANDLE | COLLECTION_NOT_FOUND return } } @@ -1912,7 +1904,6 @@ const updateRequestOrder = async ( const result = await workspaceService.reorderRESTRequest( requestHandle, - destinationCollectionIndex, destinationRequestIndex ) diff --git a/packages/hoppscotch-common/src/services/new-workspace/index.ts b/packages/hoppscotch-common/src/services/new-workspace/index.ts index 6c04d3e5f..fe6f8b548 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/index.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/index.ts @@ -467,8 +467,7 @@ export class NewWorkspaceService extends Service { } public async exportRESTCollection( - collectionHandle: Handle, - collection: HoppCollection + collectionHandle: Handle ): Promise< E.Either, void> > { @@ -486,10 +485,7 @@ export class NewWorkspaceService extends Service { return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" }) } - const result = await provider.exportRESTCollection( - collectionHandle, - collection - ) + const result = await provider.exportRESTCollection(collectionHandle) if (E.isLeft(result)) { return E.left({ type: "PROVIDER_ERROR", error: result.left }) @@ -564,7 +560,6 @@ export class NewWorkspaceService extends Service { public async reorderRESTRequest( requestHandle: Handle, - destinationCollectionID: string, destinationRequestID: string | null ): Promise< E.Either, void> @@ -585,7 +580,6 @@ export class NewWorkspaceService extends Service { const result = await provider.reorderRESTRequest( requestHandle, - destinationCollectionID, destinationRequestID ) diff --git a/packages/hoppscotch-common/src/services/new-workspace/provider.ts b/packages/hoppscotch-common/src/services/new-workspace/provider.ts index 53684b5e3..e018f758d 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/provider.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/provider.ts @@ -86,8 +86,7 @@ export interface WorkspaceProvider { workspaceHandle: Handle ): Promise> exportRESTCollection( - collectionHandle: Handle, - collection: HoppCollection + collectionHandle: Handle ): Promise> reorderRESTCollection( @@ -100,7 +99,6 @@ export interface WorkspaceProvider { ): Promise> reorderRESTRequest( requestHandle: Handle, - destinationCollectionID: string, destinationRequestID: string | null ): Promise> moveRESTRequest( diff --git a/packages/hoppscotch-common/src/services/new-workspace/providers/__tests__/personal.workspace.spec.ts b/packages/hoppscotch-common/src/services/new-workspace/providers/__tests__/personal.workspace.spec.ts index fac6b18bc..2ce0b1a55 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/providers/__tests__/personal.workspace.spec.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/providers/__tests__/personal.workspace.spec.ts @@ -225,13 +225,11 @@ describe("PersonalWorkspaceProviderService", () => { }), } - const destinationCollectionID = "1" const destinationRequestID = "1/1" const moveRequestResult = await personalWorkspaceProviderService.reorderRESTRequest( requestHandle, - destinationCollectionID, destinationRequestID ) @@ -262,7 +260,7 @@ describe("PersonalWorkspaceProviderService", () => { // Request (req-0/0/0/7) dragged from `0/0/0/7` to `0/0/0/2` const draggedRequestID = "0/0/0/7" - const destinationCollectionID = "0/0/0" + const destinationRequestID = "0/0/0/2" const draggedRequestHandle = @@ -277,7 +275,6 @@ describe("PersonalWorkspaceProviderService", () => { await personalWorkspaceProviderService.reorderRESTRequest( draggedRequestHandle.right, - destinationCollectionID, destinationRequestID ) @@ -328,7 +325,7 @@ describe("PersonalWorkspaceProviderService", () => { // Request (req-0/0/0/5) dragged from `0/0/0/5` to `0/0/0/0` const draggedRequestID = "0/0/0/5" - const destinationCollectionID = "0/0/0" + const destinationRequestID = "0/0/0/0" const draggedRequestHandle = @@ -343,7 +340,6 @@ describe("PersonalWorkspaceProviderService", () => { await personalWorkspaceProviderService.reorderRESTRequest( draggedRequestHandle.right, - destinationCollectionID, destinationRequestID ) @@ -411,7 +407,7 @@ describe("PersonalWorkspaceProviderService", () => { // Request (req-0/0/0/3) dragged from `0/0/0/3` to `0/0/0/8` const draggedRequestID = "0/0/0/3" - const destinationCollectionID = "0/0/0" + const destinationRequestID = "0/0/0/8" const draggedRequestHandle = @@ -426,7 +422,6 @@ describe("PersonalWorkspaceProviderService", () => { await personalWorkspaceProviderService.reorderRESTRequest( draggedRequestHandle.right, - destinationCollectionID, destinationRequestID ) @@ -478,7 +473,7 @@ describe("PersonalWorkspaceProviderService", () => { // Request (req-0/0/0/5) dragged from `0/0/0/5` to `0/0/0/9` const draggedRequestID = "0/0/0/5" - const destinationCollectionID = "0/0/0" + // Indicates move to the last position `0/0/0/9` const destinationRequestID = null @@ -494,7 +489,6 @@ describe("PersonalWorkspaceProviderService", () => { await personalWorkspaceProviderService.reorderRESTRequest( draggedRequestHandle.right, - destinationCollectionID, destinationRequestID ) 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 45ccb9fc5..b8af910a7 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 @@ -738,8 +738,7 @@ export class PersonalWorkspaceProviderService } public exportRESTCollection( - collectionHandle: Handle, - collection: HoppCollection + collectionHandle: Handle ): Promise> { const collectionHandleRef = collectionHandle.get() @@ -749,6 +748,17 @@ export class PersonalWorkspaceProviderService return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const)) } + const collection = navigateToFolderWithIndexPath( + this.restCollectionState.value.state, + collectionHandleRef.value.data.collectionID + .split("/") + .map((id) => parseInt(id)) + ) + + if (!collection) { + return Promise.resolve(E.left("COLLECTION_NOT_FOUND" as const)) + } + initializeDownloadFile(JSON.stringify(collection, null, 2), collection.name) return Promise.resolve(E.right(undefined)) @@ -1098,7 +1108,6 @@ export class PersonalWorkspaceProviderService public reorderRESTRequest( requestHandle: Handle, - destinationCollectionID: string, destinationRequestID: string | null ): Promise> { const requestHandleRef = requestHandle.get() @@ -1131,7 +1140,7 @@ export class PersonalWorkspaceProviderService const resolvedDestinationRequestID = destinationRequestIndexPos > draggedRequestIndexPos - ? `${destinationCollectionID}/${resolvedDestinationRequestIDPostfix}` + ? `${collectionID}/${resolvedDestinationRequestIDPostfix}` : destinationRequestID const resolvedDestinationRequestIndexPos = @@ -1175,7 +1184,7 @@ export class PersonalWorkspaceProviderService updateRESTRequestOrder( this.pathToLastIndex(draggedRequestID), destinationRequestID ? destinationRequestIndexPos : null, - destinationCollectionID + collectionID ) affectedRequestHandleUpdateInfo.forEach(