From 088ea9f4dc834392bd8fd5b76107b2b09c25f7b5 Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Fri, 27 Mar 2026 18:52:31 +0600 Subject: [PATCH] feat(common): remove functions to utilize ref_id when IDs are not provided (#5898) Co-authored-by: nivedin --- .../components/collections/SaveRequest.vue | 2 ++ .../src/newstore/collections.ts | 34 +++++++++++++++++++ .../src/services/tab/rest.ts | 4 ++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue index 8931046e..cc41478b 100644 --- a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue +++ b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue @@ -358,6 +358,7 @@ const saveRequestAs = async () => { folderPath: `${picked.value.collectionIndex}`, requestIndex: insertionIndex, exampleID: undefined, + requestRefID: requestUpdated._ref_id, }, } @@ -392,6 +393,7 @@ const saveRequestAs = async () => { originLocation: "user-collection", folderPath: picked.value.folderPath, requestIndex: insertionIndex, + requestRefID: requestUpdated._ref_id, }, } diff --git a/packages/hoppscotch-common/src/newstore/collections.ts b/packages/hoppscotch-common/src/newstore/collections.ts index c8053c72..ddbf795a 100644 --- a/packages/hoppscotch-common/src/newstore/collections.ts +++ b/packages/hoppscotch-common/src/newstore/collections.ts @@ -1351,6 +1351,9 @@ export function removeRESTCollection( collectionIndex: number, collectionID?: string ) { + if (!collectionID) { + collectionID = restCollectionStore.value.state[collectionIndex]?._ref_id + } restCollectionStore.dispatch({ dispatcher: "removeCollection", payload: { @@ -1518,6 +1521,13 @@ export function editRESTFolder(path: string, folder: Partial) { } export function removeRESTFolder(path: string, folderID?: string) { + if (!folderID) { + const folder = navigateToFolderWithIndexPath( + restCollectionStore.value.state, + path.split("/").map((index) => parseInt(index)) + ) + folderID = folder?._ref_id + } restCollectionStore.dispatch({ dispatcher: "removeFolder", payload: { @@ -1621,6 +1631,13 @@ export function removeRESTRequest( requestIndex: number, requestID?: string ) { + if (!requestID) { + const request = navigateToFolderWithIndexPath( + restCollectionStore.value.state, + path.split("/").map((index) => parseInt(index)) + )?.requests[requestIndex] + requestID = request?.id || (request as HoppRESTRequest)?._ref_id + } restCollectionStore.dispatch({ dispatcher: "removeRequest", payload: { @@ -1705,6 +1722,9 @@ export function removeGraphqlCollection( collectionIndex: number, collectionID?: string ) { + if (!collectionID) { + collectionID = graphqlCollectionStore.value.state[collectionIndex]?._ref_id + } graphqlCollectionStore.dispatch({ dispatcher: "removeCollection", payload: { @@ -1751,6 +1771,13 @@ export function editGraphqlFolder( } export function removeGraphqlFolder(path: string, folderID?: string) { + if (!folderID) { + const folder = navigateToFolderWithIndexPath( + graphqlCollectionStore.value.state, + path.split("/").map((index) => parseInt(index)) + ) + folderID = folder?._ref_id + } graphqlCollectionStore.dispatch({ dispatcher: "removeFolder", payload: { @@ -1828,6 +1855,13 @@ export function removeGraphqlRequest( requestIndex: number, requestID?: string ) { + if (!requestID) { + const request = navigateToFolderWithIndexPath( + graphqlCollectionStore.value.state, + path.split("/").map((index) => parseInt(index)) + )?.requests[requestIndex] + requestID = request?.id || `${path}/${requestIndex}` + } graphqlCollectionStore.dispatch({ dispatcher: "removeRequest", payload: { diff --git a/packages/hoppscotch-common/src/services/tab/rest.ts b/packages/hoppscotch-common/src/services/tab/rest.ts index 9a0ad0b3..35e50d20 100644 --- a/packages/hoppscotch-common/src/services/tab/rest.ts +++ b/packages/hoppscotch-common/src/services/tab/rest.ts @@ -88,7 +88,9 @@ export class RESTTabService extends TabService { tab.document.saveContext.folderPath === ctx?.folderPath && tab.document.saveContext.requestIndex === ctx?.requestIndex && tab.document.saveContext.exampleID === ctx?.exampleID && - tab.document.saveContext.requestRefID === ctx?.requestRefID + (ctx?.requestRefID != null + ? tab.document.saveContext.requestRefID === ctx.requestRefID + : true) ) { return this.getTabRef(tab.id) }