From 316dc8f759c4cf6aa89b18b15ef5f861030248d7 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 16 Feb 2024 19:09:06 +0530 Subject: [PATCH] refactor: persist IDs under tab save context --- .../components/collections/SaveRequest.vue | 23 ++-- .../src/components/http/Request.vue | 14 ++- .../src/components/http/TabHead.vue | 63 ++-------- .../components/new-collections/rest/index.vue | 111 +++++++----------- .../src/helpers/collection/collection.ts | 32 +---- .../src/helpers/rest/document.ts | 21 +++- .../src/newstore/collections.ts | 1 - .../persistence/validation-schemas/index.ts | 6 +- .../src/services/tab/rest.ts | 21 +--- 9 files changed, 110 insertions(+), 182 deletions(-) diff --git a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue index afcd56c8f..c0ce9765c 100644 --- a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue +++ b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue @@ -228,30 +228,30 @@ const saveRequestAs = async () => { if (!isHoppRESTRequest(updatedRequest)) throw new Error("requestUpdated is not a REST Request") - const collPathIndex = + const collectionPathIndex = picked.value.pickedType === "my-collection" ? picked.value.collectionIndex.toString() : picked.value.folderPath - const collHandleResult = await workspaceService.getCollectionHandle( + const collectionHandleResult = await workspaceService.getCollectionHandle( workspaceService.activeWorkspaceHandle.value, - collPathIndex + collectionPathIndex ) - if (E.isLeft(collHandleResult)) { + if (E.isLeft(collectionHandleResult)) { // INVALID_WORKSPACE_HANDLE | INVALID_COLLECTION_ID | INVALID_PATH return } - const collHandle = collHandleResult.right + const collectionHandle = collectionHandleResult.right - if (collHandle.value.type === "invalid") { + if (collectionHandle.value.type === "invalid") { // WORKSPACE_INVALIDATED return } const requestHandleResult = await workspaceService.createRESTRequest( - collHandle, + collectionHandle, updatedRequest ) @@ -299,13 +299,18 @@ const saveRequestAs = async () => { return } - // These remain here in the component + const { collectionID, providerID, requestID, workspaceID } = + requestHandle.value.data + RESTTabs.currentActiveTab.value.document = { request: updatedRequest, isDirty: false, saveContext: { originLocation: "workspace-user-collection", - requestHandle, + workspaceID, + providerID, + collectionID, + requestID, }, } diff --git a/packages/hoppscotch-common/src/components/http/Request.vue b/packages/hoppscotch-common/src/components/http/Request.vue index bc7650738..ef4dfa1c5 100644 --- a/packages/hoppscotch-common/src/components/http/Request.vue +++ b/packages/hoppscotch-common/src/components/http/Request.vue @@ -525,7 +525,19 @@ const saveRequest = async () => { return } - const { requestHandle } = saveContext + const { requestID } = saveContext + + const requestHandleResult = await newWorkspaceService.getRequestHandle( + newWorkspaceService.activeWorkspaceHandle.value, + requestID + ) + + if (E.isLeft(requestHandleResult)) { + // INVALID_COLLECTION_HANDLE | INVALID_REQUEST_ID | REQUEST_NOT_FOUND + return + } + + const requestHandle = requestHandleResult.right if (!requestHandle.value) { return diff --git a/packages/hoppscotch-common/src/components/http/TabHead.vue b/packages/hoppscotch-common/src/components/http/TabHead.vue index 65af794da..97a6dbc7e 100644 --- a/packages/hoppscotch-common/src/components/http/TabHead.vue +++ b/packages/hoppscotch-common/src/components/http/TabHead.vue @@ -1,7 +1,7 @@