fix: update save context for affected requests with collection move/reorder
This commit is contained in:
@@ -535,6 +535,10 @@ const saveRequest = async () => {
|
|||||||
if (E.isLeft(requestHandleResult)) {
|
if (E.isLeft(requestHandleResult)) {
|
||||||
// INVALID_COLLECTION_HANDLE | INVALID_REQUEST_ID | REQUEST_NOT_FOUND
|
// INVALID_COLLECTION_HANDLE | INVALID_REQUEST_ID | REQUEST_NOT_FOUND
|
||||||
showSaveRequestModal.value = true
|
showSaveRequestModal.value = true
|
||||||
|
|
||||||
|
if (!tab.value.document.isDirty) {
|
||||||
|
tab.value.document.isDirty = true
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,6 +561,10 @@ const saveRequest = async () => {
|
|||||||
if (E.isLeft(updateRequestResult)) {
|
if (E.isLeft(updateRequestResult)) {
|
||||||
// INVALID_REQUEST_HANDLE
|
// INVALID_REQUEST_HANDLE
|
||||||
showSaveRequestModal.value = true
|
showSaveRequestModal.value = true
|
||||||
|
|
||||||
|
if (!tab.value.document.isDirty) {
|
||||||
|
tab.value.document.isDirty = true
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -368,7 +368,6 @@ import {
|
|||||||
getFoldersByPath,
|
getFoldersByPath,
|
||||||
resolveSaveContextOnCollectionReorder,
|
resolveSaveContextOnCollectionReorder,
|
||||||
updateInheritedPropertiesForAffectedRequests,
|
updateInheritedPropertiesForAffectedRequests,
|
||||||
updateSaveContextForAffectedRequests,
|
|
||||||
} from "~/helpers/collection/collection"
|
} from "~/helpers/collection/collection"
|
||||||
import { getRequestsByPath } from "~/helpers/collection/request"
|
import { getRequestsByPath } from "~/helpers/collection/request"
|
||||||
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||||
@@ -1698,7 +1697,8 @@ const dropCollection = async (payload: {
|
|||||||
.split("/")
|
.split("/")
|
||||||
.slice(0, -1)
|
.slice(0, -1)
|
||||||
.join("/") // remove last folder to get parent folder
|
.join("/") // remove last folder to get parent folder
|
||||||
const totalFoldersOfDestinationCollection =
|
|
||||||
|
const totalChildCollectionsInDestinationCollection =
|
||||||
getFoldersByPath(restCollectionState.value, destinationCollectionIndex)
|
getFoldersByPath(restCollectionState.value, destinationCollectionIndex)
|
||||||
.length - (draggedParentCollection === destinationCollectionIndex ? 1 : 0)
|
.length - (draggedParentCollection === destinationCollectionIndex ? 1 : 0)
|
||||||
|
|
||||||
@@ -1730,22 +1730,36 @@ const dropCollection = async (payload: {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveSaveContextOnCollectionReorder(
|
// If a root collection is dragged, the root nodes get reduced by 1
|
||||||
{
|
// Hence, we need to reduce the destination root collection index by 1
|
||||||
lastIndex: pathToLastIndex(draggedCollectionIndex),
|
// This only applies to the case when the destination collection lies below the dragged collection
|
||||||
newIndex: -1,
|
|
||||||
folderPath: draggedParentCollection,
|
let resolvedDestinationCollectionIndex = destinationCollectionIndex
|
||||||
length: getFoldersByPath(
|
|
||||||
restCollectionState.value,
|
const draggedRootCollectionIndex = parseInt(
|
||||||
draggedParentCollection
|
pathToIndex(draggedCollectionIndex)[0]
|
||||||
).length,
|
|
||||||
},
|
|
||||||
"drop"
|
|
||||||
)
|
)
|
||||||
|
const destinationRootCollectionIndex = parseInt(
|
||||||
|
pathToIndex(destinationCollectionIndex)[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
isAlreadyInRoot(draggedCollectionIndex) &&
|
||||||
|
destinationRootCollectionIndex > draggedRootCollectionIndex
|
||||||
|
) {
|
||||||
|
resolvedDestinationCollectionIndex = `${
|
||||||
|
destinationRootCollectionIndex - 1
|
||||||
|
}/${pathToIndex(destinationCollectionIndex).slice(1).join("/")}`
|
||||||
|
|
||||||
|
resolvedDestinationCollectionIndex =
|
||||||
|
resolvedDestinationCollectionIndex.endsWith("/")
|
||||||
|
? resolvedDestinationCollectionIndex.slice(0, -1)
|
||||||
|
: resolvedDestinationCollectionIndex
|
||||||
|
}
|
||||||
|
|
||||||
updateSaveContextForAffectedRequests(
|
updateSaveContextForAffectedRequests(
|
||||||
draggedCollectionIndex,
|
draggedCollectionIndex,
|
||||||
`${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`
|
`${resolvedDestinationCollectionIndex}/${totalChildCollectionsInDestinationCollection}`
|
||||||
)
|
)
|
||||||
|
|
||||||
const destinationCollectionHandleResult =
|
const destinationCollectionHandleResult =
|
||||||
@@ -1791,7 +1805,7 @@ const dropCollection = async (payload: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateInheritedPropertiesForAffectedRequests(
|
updateInheritedPropertiesForAffectedRequests(
|
||||||
`${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`,
|
`${destinationCollectionIndex}/${totalChildCollectionsInDestinationCollection}`,
|
||||||
inheritedProperty,
|
inheritedProperty,
|
||||||
"rest"
|
"rest"
|
||||||
)
|
)
|
||||||
@@ -1868,7 +1882,7 @@ const updateCollectionOrder = async (
|
|||||||
dataTransfer: DataTransfer,
|
dataTransfer: DataTransfer,
|
||||||
destinationCollection: {
|
destinationCollection: {
|
||||||
destinationCollectionIndex: string | null
|
destinationCollectionIndex: string | null
|
||||||
destinationCollectionParentIndex: string
|
destinationCollectionParentIndex: string | null
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const draggedCollectionIndex = dataTransfer.getData("collectionIndex")
|
const draggedCollectionIndex = dataTransfer.getData("collectionIndex")
|
||||||
@@ -1923,27 +1937,36 @@ const updateCollectionOrder = async (
|
|||||||
// Moving to the last position indicated by `destinationCollectionIndex` being `null` requires computing the index path of the new child collection being inserted
|
// Moving to the last position indicated by `destinationCollectionIndex` being `null` requires computing the index path of the new child collection being inserted
|
||||||
let newDestinationCollectionIndex = 0
|
let newDestinationCollectionIndex = 0
|
||||||
if (destinationCollectionIndex === null) {
|
if (destinationCollectionIndex === null) {
|
||||||
const destinationCollectionParent = navigateToFolderWithIndexPath(
|
if (destinationCollectionParentIndex === null) {
|
||||||
restCollectionState.value,
|
newDestinationCollectionIndex = restCollectionState.value.length - 1
|
||||||
destinationCollectionParentIndex.split("/").map((id) => parseInt(id))
|
} else {
|
||||||
)
|
const destinationCollectionParent = navigateToFolderWithIndexPath(
|
||||||
|
restCollectionState.value,
|
||||||
|
destinationCollectionParentIndex.split("/").map((id) => parseInt(id))
|
||||||
|
)
|
||||||
|
|
||||||
if (!destinationCollectionParent) {
|
if (!destinationCollectionParent) {
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newDestinationCollectionIndex = destinationCollectionParent.folders.length
|
||||||
}
|
}
|
||||||
|
|
||||||
newDestinationCollectionIndex = destinationCollectionParent.folders.length
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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")}`)
|
||||||
}
|
}
|
||||||
@@ -2144,4 +2167,38 @@ 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,
|
||||||
|
collectionID: newCollectionID,
|
||||||
|
requestID: newRequestID,
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${t("request.moved")}: ${requestID} -> ${newRequestID}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user