refactor: update inherited properties for affected requests flow updates
This commit is contained in:
@@ -1703,27 +1703,28 @@ const dropRequest = async (payload: {
|
|||||||
|
|
||||||
const { auth, headers } = cascadingAuthHeadersHandle.value.data
|
const { auth, headers } = cascadingAuthHeadersHandle.value.data
|
||||||
|
|
||||||
const possibleTab = tabs.getTabRefWithSaveContext({
|
const requestHandleRef = requestHandle.get()
|
||||||
originLocation: "workspace-user-collection",
|
|
||||||
requestHandle,
|
|
||||||
})
|
|
||||||
|
|
||||||
// If there is a tab attached to this request, update the document `inheritedProperties`
|
if (requestHandleRef.value.type === "ok") {
|
||||||
if (possibleTab) {
|
const newRequestIndexPos = (
|
||||||
// @ts-expect-error - Updating the handle
|
getRequestsByPath(restCollectionState.value, destinationCollectionIndex)
|
||||||
possibleTab.value.document.saveContext.requestHandle.data = {
|
.length - 1
|
||||||
// @ts-expect-error - Updating the handle
|
).toString()
|
||||||
...possibleTab.value.document.saveContext.requestHandle.data,
|
|
||||||
collectionID: destinationCollectionIndex,
|
|
||||||
requestID: `${destinationCollectionIndex}/${(
|
|
||||||
getRequestsByPath(restCollectionState.value, destinationCollectionIndex)
|
|
||||||
.length - 1
|
|
||||||
).toString()}`,
|
|
||||||
}
|
|
||||||
|
|
||||||
possibleTab.value.document.inheritedProperties = {
|
requestHandleRef.value.data.collectionID = destinationCollectionIndex
|
||||||
auth,
|
requestHandleRef.value.data.requestID = `${destinationCollectionIndex}/${newRequestIndexPos}`
|
||||||
headers,
|
|
||||||
|
const possibleTab = tabs.getTabRefWithSaveContext({
|
||||||
|
originLocation: "workspace-user-collection",
|
||||||
|
requestHandle: { get: () => requestHandleRef },
|
||||||
|
})
|
||||||
|
|
||||||
|
// If there is a tab attached to this request, update the document `inheritedProperties`
|
||||||
|
if (possibleTab) {
|
||||||
|
possibleTab.value.document.inheritedProperties = {
|
||||||
|
auth,
|
||||||
|
headers,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { HoppCollection } from "@hoppscotch/data"
|
import { HoppCollection } from "@hoppscotch/data"
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
import { ref } from "vue"
|
|
||||||
|
|
||||||
import { getService } from "~/modules/dioc"
|
import { getService } from "~/modules/dioc"
|
||||||
import { GQLTabService } from "~/services/tab/graphql"
|
import { GQLTabService } from "~/services/tab/graphql"
|
||||||
import { RESTTabService } from "~/services/tab/rest"
|
import { RESTTabService } from "~/services/tab/rest"
|
||||||
import { runGQLQuery } from "../backend/GQLClient"
|
import { runGQLQuery } from "../backend/GQLClient"
|
||||||
import { GetSingleRequestDocument } from "../backend/graphql"
|
import { GetSingleRequestDocument } from "../backend/graphql"
|
||||||
|
import { HoppGQLSaveContext } from "../graphql/document"
|
||||||
|
import { HoppRESTSaveContext } from "../rest/document"
|
||||||
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
|
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
|
||||||
import { getAffectedIndexes } from "./affectedIndex"
|
import { getAffectedIndexes } from "./affectedIndex"
|
||||||
|
|
||||||
@@ -242,6 +243,33 @@ function removeDuplicatesAndKeepLast(arr: HoppInheritedProperty["headers"]) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSaveContextCollectionID(
|
||||||
|
saveContext: HoppRESTSaveContext | HoppGQLSaveContext | undefined
|
||||||
|
): string | undefined {
|
||||||
|
if (!saveContext) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { originLocation } = saveContext
|
||||||
|
|
||||||
|
if (originLocation === "team-collection") {
|
||||||
|
return saveContext.collectionID
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originLocation === "user-collection") {
|
||||||
|
return saveContext.folderPath
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestHandleRef = saveContext.requestHandle?.get()
|
||||||
|
|
||||||
|
if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove `collectionID` and obtain it from `requestID`
|
||||||
|
return requestHandleRef.value.data.collectionID
|
||||||
|
}
|
||||||
|
|
||||||
export function updateInheritedPropertiesForAffectedRequests(
|
export function updateInheritedPropertiesForAffectedRequests(
|
||||||
path: string,
|
path: string,
|
||||||
inheritedProperties: HoppInheritedProperty,
|
inheritedProperties: HoppInheritedProperty,
|
||||||
@@ -250,73 +278,20 @@ export function updateInheritedPropertiesForAffectedRequests(
|
|||||||
const tabService =
|
const tabService =
|
||||||
type === "rest" ? getService(RESTTabService) : getService(GQLTabService)
|
type === "rest" ? getService(RESTTabService) : getService(GQLTabService)
|
||||||
|
|
||||||
const tabs = tabService.getTabsRefTo((tab) => {
|
const effectedTabs = tabService.getTabsRefTo((tab) => {
|
||||||
if (tab.document.saveContext?.originLocation === "user-collection") {
|
const saveContext = tab.document.saveContext
|
||||||
return tab.document.saveContext.folderPath.startsWith(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tab.document.saveContext?.originLocation === "team-collection") {
|
const collectionID = getSaveContextCollectionID(saveContext)
|
||||||
return Boolean(tab.document.saveContext.collectionID?.startsWith(path))
|
return collectionID?.startsWith(path) ?? false
|
||||||
}
|
|
||||||
|
|
||||||
const collectionID = tab.document.saveContext?.requestID
|
|
||||||
?.split("/")
|
|
||||||
.slice(0, -1)
|
|
||||||
.join("/")
|
|
||||||
|
|
||||||
return Boolean(collectionID?.startsWith(path))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const tabsEffectedByAuth = tabs.filter((tab) => {
|
effectedTabs.map((tab) => {
|
||||||
if (tab.value.document.saveContext?.originLocation === "user-collection") {
|
|
||||||
return (
|
|
||||||
tab.value.document.saveContext.folderPath.startsWith(path) &&
|
|
||||||
path ===
|
|
||||||
folderPathCloseToSaveContext(
|
|
||||||
tab.value.document.inheritedProperties?.auth.parentID,
|
|
||||||
path,
|
|
||||||
tab.value.document.saveContext.folderPath
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
tab.value.document.saveContext?.originLocation !==
|
|
||||||
"workspace-user-collection"
|
|
||||||
) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
tab.value.document.saveContext.folderPath.startsWith(path) &&
|
|
||||||
path ===
|
|
||||||
folderPathCloseToSaveContext(
|
|
||||||
tab.value.document.inheritedProperties?.auth.parentID,
|
|
||||||
path,
|
|
||||||
tab.value.document.saveContext.folderPath
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
tabsEffectedByAuth.map((tab) => {
|
|
||||||
const inheritedParentID =
|
const inheritedParentID =
|
||||||
tab.value.document.inheritedProperties?.auth.parentID
|
tab.value.document.inheritedProperties?.auth.parentID
|
||||||
|
|
||||||
let contextPath = ""
|
const contextPath = getSaveContextCollectionID(
|
||||||
|
tab.value.document.saveContext
|
||||||
if (tab.value.document.saveContext?.originLocation === "user-collection") {
|
)
|
||||||
contextPath = tab.value.document.saveContext.folderPath
|
|
||||||
} else if (
|
|
||||||
tab.value.document.saveContext?.originLocation ===
|
|
||||||
"workspace-user-collection"
|
|
||||||
) {
|
|
||||||
const requestHandle = ref(tab.value.document.saveContext.requestHandle)
|
|
||||||
if (requestHandle.value?.type === "ok") {
|
|
||||||
contextPath = requestHandle.value.data.collectionID
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contextPath = tab.value.document.saveContext?.collectionID ?? ""
|
|
||||||
}
|
|
||||||
|
|
||||||
const effectedPath = folderPathCloseToSaveContext(
|
const effectedPath = folderPathCloseToSaveContext(
|
||||||
inheritedParentID,
|
inheritedParentID,
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
HoppCollection,
|
HoppCollection,
|
||||||
HoppRESTAuth,
|
|
||||||
HoppRESTHeaders,
|
|
||||||
HoppRESTRequest,
|
HoppRESTRequest,
|
||||||
makeCollection,
|
makeCollection,
|
||||||
} from "@hoppscotch/data"
|
} from "@hoppscotch/data"
|
||||||
@@ -369,7 +367,8 @@ export class PersonalWorkspaceProviderService
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle.value.data.requestID.startsWith(removedCollectionID)) {
|
// TODO: Obtain collection ID from request ID instead
|
||||||
|
if (handle.value.data.collectionID.startsWith(removedCollectionID)) {
|
||||||
handle.value = {
|
handle.value = {
|
||||||
type: "invalid",
|
type: "invalid",
|
||||||
reason: "REQUEST_INVALIDATED",
|
reason: "REQUEST_INVALIDATED",
|
||||||
@@ -1623,8 +1622,8 @@ export class PersonalWorkspaceProviderService
|
|||||||
return { type: "ok", data: { auth, headers } }
|
return { type: "ok", data: { auth, headers } }
|
||||||
}
|
}
|
||||||
|
|
||||||
const parentFolderAuth: HoppRESTAuth = parentFolder.auth
|
const { auth: parentFolderAuth, headers: parentFolderHeaders } =
|
||||||
const parentFolderHeaders: HoppRESTHeaders = parentFolder.headers
|
parentFolder
|
||||||
|
|
||||||
// check if the parent folder has authType 'inherit' and if it is the root folder
|
// check if the parent folder has authType 'inherit' and if it is the root folder
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user