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

This commit is contained in:
jamesgeorge007
2024-04-29 13:36:46 +05:30
parent e5e1260632
commit 6cde6200ae
2 changed files with 29 additions and 30 deletions

View File

@@ -1701,44 +1701,19 @@ const dropRequest = async (payload: {
const { auth, headers } = cascadingAuthHeadersHandle.value.data const { auth, headers } = cascadingAuthHeadersHandle.value.data
const { providerID, workspaceID } = requestHandle.value.data
const possibleTab = tabs.getTabRefWithSaveContext({ const possibleTab = tabs.getTabRefWithSaveContext({
originLocation: "workspace-user-collection", originLocation: "workspace-user-collection",
requestHandle, 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) { 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 = { possibleTab.value.document.inheritedProperties = {
auth, auth,
headers, 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")}`) toast.success(`${t("request.moved")}`)
draggingToRoot.value = false draggingToRoot.value = false
} }

View File

@@ -2,16 +2,18 @@ import {
HoppCollection, HoppCollection,
HoppRESTAuth, HoppRESTAuth,
HoppRESTHeaders, HoppRESTHeaders,
HoppRESTRequest,
makeCollection, makeCollection,
} from "@hoppscotch/data" } from "@hoppscotch/data"
import { Service } from "dioc" import { Service } from "dioc"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import { merge } from "lodash-es"
import path from "path"
import { import {
Ref, Ref,
computed, computed,
effectScope, effectScope,
markRaw, markRaw,
nextTick,
ref, ref,
shallowRef, shallowRef,
watch, watch,
@@ -57,9 +59,7 @@ import {
WorkspaceRequest, WorkspaceRequest,
} from "~/services/new-workspace/workspace" } from "~/services/new-workspace/workspace"
import { HoppRESTRequest } from "@hoppscotch/data" import { getRequestsByPath } from "~/helpers/collection/request"
import { merge } from "lodash-es"
import path from "path"
import { initializeDownloadFile } from "~/helpers/import-export/export" import { initializeDownloadFile } from "~/helpers/import-export/export"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties" import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import IconUser from "~icons/lucide/user" import IconUser from "~icons/lucide/user"
@@ -612,6 +612,30 @@ export class PersonalWorkspaceProviderService
destinationCollectionID 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)) return Promise.resolve(E.right(undefined))
} }