refactor: move to handle based updates with request move action
This commit is contained in:
@@ -59,6 +59,7 @@ import {
|
|||||||
WorkspaceRequest,
|
WorkspaceRequest,
|
||||||
} from "~/services/new-workspace/workspace"
|
} from "~/services/new-workspace/workspace"
|
||||||
|
|
||||||
|
import { getAffectedIndexes } from "~/helpers/collection/affectedIndex"
|
||||||
import {
|
import {
|
||||||
getFoldersByPath,
|
getFoldersByPath,
|
||||||
resolveSaveContextOnCollectionReorder,
|
resolveSaveContextOnCollectionReorder,
|
||||||
@@ -635,29 +636,56 @@ export class PersonalWorkspaceProviderService
|
|||||||
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestIndex = requestHandle.value.data.requestID
|
const { requestID } = requestHandle.value.data
|
||||||
const parentCollectionIndexPath = requestIndex
|
const draggedRequestParentCollectionID = requestID
|
||||||
.split("/")
|
.split("/")
|
||||||
.slice(0, -1)
|
.slice(0, -1)
|
||||||
.join("/")
|
.join("/")
|
||||||
|
|
||||||
// When it's drop it's basically getting deleted from last folder, reordering last folder accordingly
|
const draggedRequestIndexPos = this.pathToLastIndex(requestID)
|
||||||
resolveSaveContextOnRequestReorder({
|
|
||||||
lastIndex: this.pathToLastIndex(requestIndex),
|
// `-1` indicates the incoming request in the last position for the destination collection
|
||||||
newIndex: -1, // being deleted from last folder
|
const destinationRequestIndexPos = -1
|
||||||
folderPath: parentCollectionIndexPath,
|
|
||||||
length: getRequestsByPath(
|
const affectedRequestIndices = getAffectedIndexes(
|
||||||
restCollectionStore.value.state,
|
draggedRequestIndexPos,
|
||||||
parentCollectionIndexPath
|
destinationRequestIndexPos
|
||||||
).length,
|
)
|
||||||
})
|
|
||||||
|
// Remove deleted request from the map
|
||||||
|
if (destinationRequestIndexPos === -1) {
|
||||||
|
affectedRequestIndices.delete(draggedRequestIndexPos)
|
||||||
|
}
|
||||||
|
|
||||||
moveRESTRequest(
|
moveRESTRequest(
|
||||||
parentCollectionIndexPath,
|
draggedRequestParentCollectionID,
|
||||||
this.pathToLastIndex(requestIndex),
|
draggedRequestIndexPos,
|
||||||
destinationCollectionID
|
destinationCollectionID
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for (const [key, value] of affectedRequestIndices) {
|
||||||
|
const handle = this.issuedHandles.find((handle) => {
|
||||||
|
if (handle.value.type === "invalid") return
|
||||||
|
|
||||||
|
if (!("requestID" in handle.value.data)) return
|
||||||
|
|
||||||
|
return (
|
||||||
|
handle.value.data.requestID ===
|
||||||
|
`${draggedRequestParentCollectionID}/${key}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
if (
|
||||||
|
!handle ||
|
||||||
|
handle.value.type === "invalid" ||
|
||||||
|
!("requestID" in handle.value.data)
|
||||||
|
) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.value.data.requestID = `${destinationCollectionID}/${value}`
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve(E.right(undefined))
|
return Promise.resolve(E.right(undefined))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user