refactor: tab saveContext resolution post collection remove action
This commit is contained in:
@@ -1812,18 +1812,15 @@ const dropCollection = async (payload: {
|
||||
: resolvedDestinationCollectionIndex
|
||||
}
|
||||
|
||||
resolveSaveContextOnCollectionReorder(
|
||||
{
|
||||
lastIndex: pathToLastIndex(draggedCollectionIndex),
|
||||
newIndex: -1,
|
||||
folderPath: draggedParentCollectionIndex,
|
||||
length: getFoldersByPath(
|
||||
restCollectionState.value,
|
||||
draggedParentCollectionIndex
|
||||
).length,
|
||||
},
|
||||
"drop"
|
||||
)
|
||||
resolveSaveContextOnCollectionReorder({
|
||||
lastIndex: pathToLastIndex(draggedCollectionIndex),
|
||||
newIndex: -1,
|
||||
folderPath: draggedParentCollectionIndex,
|
||||
length: getFoldersByPath(
|
||||
restCollectionState.value,
|
||||
draggedParentCollectionIndex
|
||||
).length,
|
||||
})
|
||||
|
||||
updateSaveContextForAffectedRequests(
|
||||
draggedCollectionIndex,
|
||||
|
||||
@@ -22,15 +22,12 @@ import { HandleRef } from "~/services/new-workspace/handle"
|
||||
* @returns
|
||||
*/
|
||||
|
||||
export function resolveSaveContextOnCollectionReorder(
|
||||
payload: {
|
||||
lastIndex: number
|
||||
newIndex: number
|
||||
folderPath: string
|
||||
length?: number // better way to do this? now it could be undefined
|
||||
},
|
||||
type: "remove" | "drop" = "remove"
|
||||
) {
|
||||
export function resolveSaveContextOnCollectionReorder(payload: {
|
||||
lastIndex: number
|
||||
newIndex: number
|
||||
folderPath: string
|
||||
length?: number // better way to do this? now it could be undefined
|
||||
}) {
|
||||
const { lastIndex, folderPath, length } = payload
|
||||
let { newIndex } = payload
|
||||
|
||||
@@ -45,12 +42,6 @@ export function resolveSaveContextOnCollectionReorder(
|
||||
if (newIndex === -1) {
|
||||
// if (newIndex === -1) remove it from the map because it will be deleted
|
||||
affectedIndexes.delete(lastIndex)
|
||||
// when collection deleted opended requests from that collection be affected
|
||||
if (type === "remove") {
|
||||
resetSaveContextForAffectedRequests(
|
||||
folderPath ? `${folderPath}/${lastIndex}` : lastIndex.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// add folder path as prefix to the affected indexes
|
||||
|
||||
@@ -59,6 +59,10 @@ import {
|
||||
WorkspaceRequest,
|
||||
} from "~/services/new-workspace/workspace"
|
||||
|
||||
import {
|
||||
getFoldersByPath,
|
||||
resolveSaveContextOnCollectionReorder,
|
||||
} from "~/helpers/collection/collection"
|
||||
import {
|
||||
getRequestsByPath,
|
||||
resolveSaveContextOnRequestReorder,
|
||||
@@ -279,10 +283,9 @@ export class PersonalWorkspaceProviderService
|
||||
const { collectionID } = collectionHandle.value.data
|
||||
|
||||
const isRootCollection = collectionID.split("/").length === 1
|
||||
const collectionIndex = parseInt(collectionID)
|
||||
|
||||
if (isRootCollection) {
|
||||
const collectionIndex = parseInt(collectionID)
|
||||
|
||||
const collectionToRemove = navigateToFolderWithIndexPath(
|
||||
restCollectionStore.value.state,
|
||||
[collectionIndex]
|
||||
@@ -322,6 +325,26 @@ export class PersonalWorkspaceProviderService
|
||||
}
|
||||
}
|
||||
|
||||
if (isRootCollection) {
|
||||
resolveSaveContextOnCollectionReorder({
|
||||
lastIndex: collectionIndex,
|
||||
newIndex: -1,
|
||||
folderPath: "", // root folder
|
||||
length: restCollectionStore.value.state.length,
|
||||
})
|
||||
} else {
|
||||
const parentCollectionID = collectionID.split("/").slice(0, -1).join("/") // remove last folder to get parent folder
|
||||
resolveSaveContextOnCollectionReorder({
|
||||
lastIndex: this.pathToLastIndex(collectionID),
|
||||
newIndex: -1,
|
||||
folderPath: parentCollectionID,
|
||||
length: getFoldersByPath(
|
||||
restCollectionStore.value.state,
|
||||
parentCollectionID
|
||||
).length,
|
||||
})
|
||||
}
|
||||
|
||||
return Promise.resolve(E.right(undefined))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user