chore: keep existing implementation for save context resolution
This commit is contained in:
@@ -497,9 +497,14 @@ import { WorkspaceRESTCollectionTreeAdapter } from "~/helpers/adapters/Workspace
|
|||||||
import { TeamCollection } from "~/helpers/backend/graphql"
|
import { TeamCollection } from "~/helpers/backend/graphql"
|
||||||
import {
|
import {
|
||||||
getFoldersByPath,
|
getFoldersByPath,
|
||||||
|
resolveSaveContextOnCollectionReorder,
|
||||||
updateInheritedPropertiesForAffectedRequests,
|
updateInheritedPropertiesForAffectedRequests,
|
||||||
|
updateSaveContextForAffectedRequests,
|
||||||
} from "~/helpers/collection/collection"
|
} from "~/helpers/collection/collection"
|
||||||
import { getRequestsByPath } from "~/helpers/collection/request"
|
import {
|
||||||
|
getRequestsByPath,
|
||||||
|
resolveSaveContextOnRequestReorder,
|
||||||
|
} from "~/helpers/collection/request"
|
||||||
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||||
import { Picked } from "~/helpers/types/HoppPicked"
|
import { Picked } from "~/helpers/types/HoppPicked"
|
||||||
import {
|
import {
|
||||||
@@ -1780,6 +1785,17 @@ const dropRequest = async (payload: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
@@ -1808,21 +1824,22 @@ const dropCollection = async (payload: {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if the collection is being moved to its own parent
|
// Check if the collection is being moved to its own parent
|
||||||
if (
|
if (
|
||||||
isMoveToSameLocation(draggedCollectionIndex, destinationCollectionIndex)
|
isMoveToSameLocation(draggedCollectionIndex, destinationCollectionIndex)
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const draggedParentCollection = draggedCollectionIndex
|
const draggedParentCollectionIndex = draggedCollectionIndex
|
||||||
.split("/")
|
.split("/")
|
||||||
.slice(0, -1)
|
.slice(0, -1)
|
||||||
.join("/") // remove last folder to get parent folder
|
.join("/") // Remove the last child-collection index to get the parent collection index
|
||||||
|
|
||||||
const totalChildCollectionsInDestinationCollection =
|
const totalChildCollectionsInDestinationCollection =
|
||||||
getFoldersByPath(restCollectionState.value, destinationCollectionIndex)
|
getFoldersByPath(restCollectionState.value, destinationCollectionIndex)
|
||||||
.length - (draggedParentCollection === destinationCollectionIndex ? 1 : 0)
|
.length -
|
||||||
|
(draggedParentCollectionIndex === destinationCollectionIndex ? 1 : 0)
|
||||||
|
|
||||||
const draggedCollectionHandleResult =
|
const draggedCollectionHandleResult =
|
||||||
await workspaceService.getCollectionHandle(
|
await workspaceService.getCollectionHandle(
|
||||||
@@ -1879,6 +1896,19 @@ const dropCollection = async (payload: {
|
|||||||
: resolvedDestinationCollectionIndex
|
: resolvedDestinationCollectionIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolveSaveContextOnCollectionReorder(
|
||||||
|
{
|
||||||
|
lastIndex: pathToLastIndex(draggedCollectionIndex),
|
||||||
|
newIndex: -1,
|
||||||
|
folderPath: draggedParentCollectionIndex,
|
||||||
|
length: getFoldersByPath(
|
||||||
|
restCollectionState.value,
|
||||||
|
draggedParentCollectionIndex
|
||||||
|
).length,
|
||||||
|
},
|
||||||
|
"drop"
|
||||||
|
)
|
||||||
|
|
||||||
updateSaveContextForAffectedRequests(
|
updateSaveContextForAffectedRequests(
|
||||||
draggedCollectionIndex,
|
draggedCollectionIndex,
|
||||||
`${resolvedDestinationCollectionIndex}/${totalChildCollectionsInDestinationCollection}`
|
`${resolvedDestinationCollectionIndex}/${totalChildCollectionsInDestinationCollection}`
|
||||||
@@ -2075,20 +2105,15 @@ const updateCollectionOrder = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveSaveContextOnCollectionReorder({
|
resolveSaveContextOnCollectionReorder({
|
||||||
// lastIndex: pathToLastIndex(draggedCollectionIndex),
|
lastIndex: pathToLastIndex(draggedCollectionIndex),
|
||||||
// newIndex: pathToLastIndex(
|
newIndex: pathToLastIndex(
|
||||||
// destinationCollectionIndex
|
destinationCollectionIndex
|
||||||
// ? destinationCollectionIndex
|
? destinationCollectionIndex
|
||||||
// : newDestinationCollectionIndex.toString()
|
: newDestinationCollectionIndex.toString()
|
||||||
// ),
|
),
|
||||||
// folderPath: draggedCollectionIndex.split("/").slice(0, -1).join("/"),
|
folderPath: draggedCollectionIndex.split("/").slice(0, -1).join("/"),
|
||||||
// })
|
})
|
||||||
|
|
||||||
updateSaveContextForAffectedRequests(
|
|
||||||
draggedCollectionIndex,
|
|
||||||
destinationCollectionIndex ?? newDestinationCollectionIndex.toString()
|
|
||||||
)
|
|
||||||
|
|
||||||
toast.success(`${t("collection.order_changed")}`)
|
toast.success(`${t("collection.order_changed")}`)
|
||||||
}
|
}
|
||||||
@@ -2261,6 +2286,16 @@ const pathToIndex = (path: string) => {
|
|||||||
return pathArr
|
return pathArr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to get the index of the request from the path
|
||||||
|
* @param path The path of the request
|
||||||
|
* @returns The index of the request
|
||||||
|
*/
|
||||||
|
const pathToLastIndex = (path: string) => {
|
||||||
|
const pathArr = path.split("/")
|
||||||
|
return parseInt(pathArr[pathArr.length - 1])
|
||||||
|
}
|
||||||
|
|
||||||
const resolveConfirmModal = (title: string | null) => {
|
const resolveConfirmModal = (title: string | null) => {
|
||||||
if (title === `${t("confirm.remove_collection")}`) {
|
if (title === `${t("confirm.remove_collection")}`) {
|
||||||
onRemoveRootCollection()
|
onRemoveRootCollection()
|
||||||
@@ -2284,35 +2319,4 @@ const resetSelectedData = () => {
|
|||||||
editingRequestName.value = ""
|
editingRequestName.value = ""
|
||||||
editingRequestIndexPath.value = ""
|
editingRequestIndexPath.value = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateSaveContextForAffectedRequests = (
|
|
||||||
draggedCollectionIndex: string,
|
|
||||||
destinationCollectionIndex: string
|
|
||||||
) => {
|
|
||||||
const activeTabs = tabs.getActiveTabs()
|
|
||||||
|
|
||||||
for (const tab of activeTabs.value) {
|
|
||||||
if (
|
|
||||||
tab.document.saveContext?.originLocation === "workspace-user-collection"
|
|
||||||
) {
|
|
||||||
const { requestID } = tab.document.saveContext
|
|
||||||
|
|
||||||
const collectionID = requestID.split("/").slice(0, -1).join("/")
|
|
||||||
const requestIndex = requestID.split("/").slice(-1)[0]
|
|
||||||
|
|
||||||
if (collectionID.startsWith(draggedCollectionIndex)) {
|
|
||||||
const newCollectionID = collectionID.replace(
|
|
||||||
draggedCollectionIndex,
|
|
||||||
destinationCollectionIndex
|
|
||||||
)
|
|
||||||
const newRequestID = `${newCollectionID}/${requestIndex}`
|
|
||||||
|
|
||||||
tab.document.saveContext = {
|
|
||||||
...tab.document.saveContext,
|
|
||||||
requestID: newRequestID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -117,57 +117,51 @@ export function resolveSaveContextOnCollectionReorder(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function updateSaveContextForAffectedRequests(
|
export function updateSaveContextForAffectedRequests(
|
||||||
oldFolderPath: string,
|
draggedCollectionIndex: string,
|
||||||
newFolderPath: string
|
destinationCollectionIndex: string
|
||||||
) {
|
) {
|
||||||
const tabService = getService(RESTTabService)
|
const tabService = getService(RESTTabService)
|
||||||
const tabs = tabService.getTabsRefTo((tab) => {
|
|
||||||
|
const activeTabs = tabService.getActiveTabs()
|
||||||
|
|
||||||
|
for (const tab of activeTabs.value) {
|
||||||
if (tab.document.saveContext?.originLocation === "user-collection") {
|
if (tab.document.saveContext?.originLocation === "user-collection") {
|
||||||
return tab.document.saveContext.folderPath.startsWith(oldFolderPath)
|
const { folderPath } = tab.document.saveContext
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (folderPath.startsWith(draggedCollectionIndex)) {
|
||||||
tab.document.saveContext?.originLocation !== "workspace-user-collection"
|
const newFolderPath = folderPath.replace(
|
||||||
) {
|
draggedCollectionIndex,
|
||||||
return false
|
destinationCollectionIndex
|
||||||
}
|
)
|
||||||
|
|
||||||
const collectionID = tab.document.saveContext.requestID
|
tab.document.saveContext = {
|
||||||
.split("/")
|
...tab.document.saveContext,
|
||||||
.slice(0, -1)
|
folderPath: newFolderPath,
|
||||||
.join("/")
|
}
|
||||||
|
|
||||||
return collectionID.startsWith(oldFolderPath)
|
|
||||||
})
|
|
||||||
|
|
||||||
for (const tab of tabs) {
|
|
||||||
if (tab.value.document.saveContext?.originLocation === "user-collection") {
|
|
||||||
tab.value.document.saveContext = {
|
|
||||||
...tab.value.document.saveContext,
|
|
||||||
folderPath: tab.value.document.saveContext.folderPath.replace(
|
|
||||||
oldFolderPath,
|
|
||||||
newFolderPath
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
tab.value.document.saveContext?.originLocation ===
|
tab.document.saveContext?.originLocation === "workspace-user-collection"
|
||||||
"workspace-user-collection"
|
|
||||||
) {
|
) {
|
||||||
const collectionID = tab.value.document.saveContext.requestID
|
const { requestID } = tab.document.saveContext
|
||||||
.split("/")
|
|
||||||
.slice(0, -1)
|
|
||||||
.join("/")
|
|
||||||
|
|
||||||
const newCollectionID = collectionID.replace(oldFolderPath, newFolderPath)
|
const collectionID = requestID.split("/").slice(0, -1).join("/")
|
||||||
const newRequestID = `${newCollectionID}/${
|
const requestIndex = requestID.split("/").slice(-1)[0]
|
||||||
tab.value.document.saveContext.requestID.split("/").slice(-1)[0]
|
|
||||||
}`
|
|
||||||
|
|
||||||
tab.value.document.saveContext = {
|
if (collectionID.startsWith(draggedCollectionIndex)) {
|
||||||
...tab.value.document.saveContext,
|
const newCollectionID = collectionID.replace(
|
||||||
requestID: newRequestID,
|
draggedCollectionIndex,
|
||||||
|
destinationCollectionIndex
|
||||||
|
)
|
||||||
|
const newRequestID = `${newCollectionID}/${requestIndex}`
|
||||||
|
|
||||||
|
tab.document.saveContext = {
|
||||||
|
...tab.document.saveContext,
|
||||||
|
requestID: newRequestID,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user