Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat(common): remove functions to utilize ref_id when IDs are not provided (#5898)

Anwarul Islam088ea9f4dc83
diff --git a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue
index 8931046e4..cc41478b8 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 c8053c728..ddbf795a3 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<HoppCollection>) {
}
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 9a0ad0b35..35e50d204 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<HoppTabDocument> {
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)
}