fix: reset save context issue on delete collection or folder of team (#2971)

This commit is contained in:
Anwarul Islam
2023-04-07 03:36:30 +06:00
committed by GitHub
parent b88f496f4e
commit 55e3dd3c18
3 changed files with 3537 additions and 3247 deletions

View File

@@ -1,6 +1,9 @@
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
import { getTabsRefTo } from "../rest/tab"
import { getAffectedIndexes } from "./affectedIndex"
import { GetSingleRequestDocument } from "../backend/graphql"
import { runGQLQuery } from "../backend/GQLClient"
import * as E from "fp-ts/Either"
/**
* Resolve save context on reorder
@@ -115,6 +118,33 @@ function resetSaveContextForAffectedRequests(folderPath: string) {
}
}
/**
* Reset save context to null if requests are deleted from the team collection or its folder
* only runs when collection or folder is deleted
*/
export async function resetTeamRequestsContext() {
const tabs = getTabsRefTo((tab) => {
return tab.document.saveContext?.originLocation === "team-collection"
})
for (const tab of tabs) {
if (tab.value.document.saveContext?.originLocation === "team-collection") {
const data = await runGQLQuery({
query: GetSingleRequestDocument,
variables: {
requestID: tab.value.document.saveContext?.requestID,
},
})
if (E.isRight(data) && data.right.request === null) {
tab.value.document.saveContext = null
tab.value.document.isDirty = true
}
}
}
}
export function getFoldersByPath(
collections: HoppCollection<HoppRESTRequest>[],
path: string