Browse Source

refactor: signify updates via handle reference mutation post request move action

jamesgeorge007 10 months ago
parent
commit
418bf439ca

+ 1 - 26
packages/hoppscotch-common/src/components/new-collections/rest/index.vue

@@ -1701,44 +1701,19 @@ const dropRequest = async (payload: {
 
   const { auth, headers } = cascadingAuthHeadersHandle.value.data
 
-  const { providerID, workspaceID } = requestHandle.value.data
-
   const possibleTab = tabs.getTabRefWithSaveContext({
     originLocation: "workspace-user-collection",
     requestHandle,
   })
 
-  // If there is a tab attached to this request, update its save context
+  // If there is a tab attached to this request, update the document `inheritedProperties`
   if (possibleTab) {
-    const newRequestID = `${destinationCollectionIndex}/${(
-      getRequestsByPath(restCollectionState.value, destinationCollectionIndex)
-        .length - 1
-    ).toString()}`
-
-    possibleTab.value.document.saveContext = {
-      originLocation: "workspace-user-collection",
-      workspaceID,
-      providerID,
-      requestID: newRequestID,
-    }
-
     possibleTab.value.document.inheritedProperties = {
       auth,
       headers,
     }
   }
 
-  // When it's drop it's basically getting deleted from last folder. reordering last folder accordingly
-  resolveSaveContextOnRequestReorder({
-    lastIndex: pathToLastIndex(requestIndex),
-    newIndex: -1, // being deleted from last folder
-    folderPath: parentCollectionIndexPath,
-    length: getRequestsByPath(
-      restCollectionState.value,
-      parentCollectionIndexPath
-    ).length,
-  })
-
   toast.success(`${t("request.moved")}`)
   draggingToRoot.value = false
 }

+ 28 - 4
packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts

@@ -2,16 +2,18 @@ import {
   HoppCollection,
   HoppRESTAuth,
   HoppRESTHeaders,
+  HoppRESTRequest,
   makeCollection,
 } from "@hoppscotch/data"
 import { Service } from "dioc"
 import * as E from "fp-ts/Either"
+import { merge } from "lodash-es"
+import path from "path"
 import {
   Ref,
   computed,
   effectScope,
   markRaw,
-  nextTick,
   ref,
   shallowRef,
   watch,
@@ -57,9 +59,7 @@ import {
   WorkspaceRequest,
 } from "~/services/new-workspace/workspace"
 
-import { HoppRESTRequest } from "@hoppscotch/data"
-import { merge } from "lodash-es"
-import path from "path"
+import { getRequestsByPath } from "~/helpers/collection/request"
 import { initializeDownloadFile } from "~/helpers/import-export/export"
 import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
 import IconUser from "~icons/lucide/user"
@@ -612,6 +612,30 @@ export class PersonalWorkspaceProviderService
       destinationCollectionID
     )
 
+    for (const [idx, handle] of this.issuedHandles.entries()) {
+      if (handle.value.type === "invalid") continue
+
+      if ("requestID" in handle.value.data) {
+        if (
+          handle.value.data.requestID === requestHandle.value.data.requestID
+        ) {
+          const destinationRequestID = `${destinationCollectionID}/${(
+            getRequestsByPath(
+              this.restCollectionState.value.state,
+              destinationCollectionID
+            ).length - 1
+          ).toString()}`
+
+          // @ts-expect-error - We're updating the request handle data
+          this.issuedHandles[idx].value.data.collectionID =
+            destinationCollectionID
+
+          // @ts-expect-error - We're updating the request handle data
+          this.issuedHandles[idx].value.data.requestID = destinationRequestID
+        }
+      }
+    }
+
     return Promise.resolve(E.right(undefined))
   }