fix: reset save context issue on delete collection or folder of team (#2971)
This commit is contained in:
@@ -234,6 +234,7 @@ import {
|
|||||||
getFoldersByPath,
|
getFoldersByPath,
|
||||||
resolveSaveContextOnCollectionReorder,
|
resolveSaveContextOnCollectionReorder,
|
||||||
updateSaveContextForAffectedRequests,
|
updateSaveContextForAffectedRequests,
|
||||||
|
resetTeamRequestsContext,
|
||||||
} from "~/helpers/collection/collection"
|
} from "~/helpers/collection/collection"
|
||||||
import { currentReorderingStatus$ } from "~/newstore/reordering"
|
import { currentReorderingStatus$ } from "~/newstore/reordering"
|
||||||
|
|
||||||
@@ -990,10 +991,10 @@ const removeCollection = (id: string) => {
|
|||||||
* since folder is treated as collection in the BE.
|
* since folder is treated as collection in the BE.
|
||||||
* @param collectionID - ID of the collection or folder to be deleted.
|
* @param collectionID - ID of the collection or folder to be deleted.
|
||||||
*/
|
*/
|
||||||
const removeTeamCollectionOrFolder = (collectionID: string) => {
|
const removeTeamCollectionOrFolder = async (collectionID: string) => {
|
||||||
modalLoadingState.value = true
|
modalLoadingState.value = true
|
||||||
|
|
||||||
pipe(
|
await pipe(
|
||||||
deleteCollection(collectionID),
|
deleteCollection(collectionID),
|
||||||
TE.match(
|
TE.match(
|
||||||
(err: GQLError<string>) => {
|
(err: GQLError<string>) => {
|
||||||
@@ -1047,7 +1048,9 @@ const onRemoveCollection = () => {
|
|||||||
emit("select", null)
|
emit("select", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTeamCollectionOrFolder(collectionID)
|
removeTeamCollectionOrFolder(collectionID).then(() => {
|
||||||
|
resetTeamRequestsContext()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1099,7 +1102,9 @@ const onRemoveFolder = () => {
|
|||||||
emit("select", null)
|
emit("select", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTeamCollectionOrFolder(collectionID)
|
removeTeamCollectionOrFolder(collectionID).then(() => {
|
||||||
|
resetTeamRequestsContext()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||||
import { getTabsRefTo } from "../rest/tab"
|
import { getTabsRefTo } from "../rest/tab"
|
||||||
import { getAffectedIndexes } from "./affectedIndex"
|
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
|
* 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(
|
export function getFoldersByPath(
|
||||||
collections: HoppCollection<HoppRESTRequest>[],
|
collections: HoppCollection<HoppRESTRequest>[],
|
||||||
path: string
|
path: string
|
||||||
|
|||||||
6741
pnpm-lock.yaml
generated
6741
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user