refactor: tab saveContext resolution post collection remove action

This commit is contained in:
jamesgeorge007
2024-05-01 21:02:11 +05:30
parent 0abdc63f0e
commit 412daa4d17
3 changed files with 40 additions and 29 deletions

View File

@@ -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