From 0abdc63f0eaa3ed3624f4e801237d76a19e19aec Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 1 May 2024 18:37:32 +0530 Subject: [PATCH] refactor: better tab dirty check Mark the tab (saved request under a collection) as not dirty if the request contents are reset to the value since previous save. --- .../components/collections/SaveRequest.vue | 11 +----- .../src/components/http/Request.vue | 19 +-------- .../src/components/http/RequestTab.vue | 39 ++++++++++++++++--- .../src/services/tab/rest.ts | 2 +- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue index 6abc98bb6..47c53be9c 100644 --- a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue +++ b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue @@ -267,16 +267,11 @@ const saveRequestAs = async () => { return } - const { providerID, requestID, workspaceID } = requestHandle.value.data - RESTTabs.currentActiveTab.value.document = { request: updatedRequest, isDirty: false, saveContext: { originLocation: "workspace-user-collection", - workspaceID, - providerID, - requestID, requestHandle, }, } @@ -313,16 +308,12 @@ const saveRequestAs = async () => { return } - const { providerID, requestID, workspaceID } = requestHandle.value.data - RESTTabs.currentActiveTab.value.document = { request: updatedRequest, isDirty: false, saveContext: { originLocation: "workspace-user-collection", - workspaceID, - providerID, - requestID, + requestHandle, }, } diff --git a/packages/hoppscotch-common/src/components/http/Request.vue b/packages/hoppscotch-common/src/components/http/Request.vue index a9d2363cb..9449d1f74 100644 --- a/packages/hoppscotch-common/src/components/http/Request.vue +++ b/packages/hoppscotch-common/src/components/http/Request.vue @@ -525,24 +525,7 @@ const saveRequest = async () => { return } - 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 - showSaveRequestModal.value = true - - if (!tab.value.document.isDirty) { - tab.value.document.isDirty = true - } - return - } - - const requestHandle = requestHandleResult.right + const requestHandle = ref(saveContext.requestHandle) if (!requestHandle.value) { return diff --git a/packages/hoppscotch-common/src/components/http/RequestTab.vue b/packages/hoppscotch-common/src/components/http/RequestTab.vue index f009f96d8..4427a04d3 100644 --- a/packages/hoppscotch-common/src/components/http/RequestTab.vue +++ b/packages/hoppscotch-common/src/components/http/RequestTab.vue @@ -17,10 +17,11 @@