From 7549e456c8e6a86938745888894f8a0ee4c6fab4 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 14 Feb 2024 13:13:56 +0530 Subject: [PATCH] fix: specify correct request index with update action --- .../components/new-collections/rest/index.vue | 21 +++++++++++-------- .../providers/personal.workspace.ts | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) 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 2cc89efea..4e744cf83 100644 --- a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue +++ b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue @@ -71,7 +71,7 @@ { return } - // If there is a request with this save context, switch into it - let possibleTab = null - const cascadingAuthHeadersHandleResult = await workspaceService.getRESTCollectionLevelAuthHeadersView( collectionHandle @@ -771,16 +769,18 @@ const selectRequest = async (requestIndexPath: string) => { const { auth, headers } = cascadingAuthHeadersHandle.value.data - possibleTab = tabs.getTabRefWithSaveContext({ + // If there is a request with this save context, switch into it + const possibleTab = tabs.getTabRefWithSaveContext({ originLocation: "workspace-user-collection", requestHandle, }) + if (possibleTab) { tabs.setActiveTab(possibleTab.value.id) } else { // If not, open the request in a new tab tabs.createNewTab({ - request: cloneDeep(requestHandle.value.data.request), + request: requestHandle.value.data.request, isDirty: false, saveContext: { originLocation: "workspace-user-collection", @@ -1075,7 +1075,7 @@ const isAlreadyInRoot = (id: string) => { return indexPath.length === 1 } -const isActiveRequest = (requestID: string) => { +const isActiveRequest = (requestView: RESTCollectionViewRequest) => { if ( tabs.currentActiveTab.value.document.saveContext?.originLocation !== "workspace-user-collection" @@ -1090,7 +1090,10 @@ const isActiveRequest = (requestID: string) => { if (requestHandle.value.type === "invalid") { return false } - return requestHandle.value.data.request.id === requestID + return ( + requestHandle.value.data.requestID === requestView.requestID && + requestHandle.value.data.request.id === requestView.request.id + ) } const onSelectPick = (payload: Picked | null) => { 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 0ccae4096..a6902b004 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 @@ -378,7 +378,7 @@ export class PersonalWorkspaceProviderService const { collectionID, requestID, request } = requestHandle.value.data const newRequest: HoppRESTRequest = merge(request, updatedRequest) - const requestIndex = parseInt(requestID) + const requestIndex = parseInt(requestID.split("/").slice(-1)[0]) editRESTRequest(collectionID, requestIndex, newRequest) platform.analytics?.logEvent({