fix: prevent duplicate request creation and invalidate tabs with request deletion
This commit is contained in:
@@ -128,9 +128,20 @@ import * as E from "fp-ts/lib/Either"
|
|||||||
import { useService } from "dioc/vue"
|
import { useService } from "dioc/vue"
|
||||||
import { markRaw, nextTick, ref } from "vue"
|
import { markRaw, nextTick, ref } from "vue"
|
||||||
|
|
||||||
|
import { HoppCollection, HoppRESTAuth, HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
import { cloneDeep } from "lodash-es"
|
||||||
import { useI18n } from "~/composables/i18n"
|
import { useI18n } from "~/composables/i18n"
|
||||||
|
import { useReadonlyStream } from "~/composables/stream"
|
||||||
import { useToast } from "~/composables/toast"
|
import { useToast } from "~/composables/toast"
|
||||||
import { WorkspaceRESTCollectionTreeAdapter } from "~/helpers/adapters/WorkspaceRESTCollectionTreeAdapter"
|
import { WorkspaceRESTCollectionTreeAdapter } from "~/helpers/adapters/WorkspaceRESTCollectionTreeAdapter"
|
||||||
|
import { TeamCollection } from "~/helpers/backend/graphql"
|
||||||
|
import { updateInheritedPropertiesForAffectedRequests } from "~/helpers/collection/collection"
|
||||||
|
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||||
|
import {
|
||||||
|
navigateToFolderWithIndexPath,
|
||||||
|
restCollections$,
|
||||||
|
saveRESTRequestAs,
|
||||||
|
} from "~/newstore/collections"
|
||||||
import { NewWorkspaceService } from "~/services/new-workspace"
|
import { NewWorkspaceService } from "~/services/new-workspace"
|
||||||
import { HandleRef } from "~/services/new-workspace/handle"
|
import { HandleRef } from "~/services/new-workspace/handle"
|
||||||
import { Workspace } from "~/services/new-workspace/workspace"
|
import { Workspace } from "~/services/new-workspace/workspace"
|
||||||
@@ -138,21 +149,6 @@ import { RESTTabService } from "~/services/tab/rest"
|
|||||||
import IconImport from "~icons/lucide/folder-down"
|
import IconImport from "~icons/lucide/folder-down"
|
||||||
import IconHelpCircle from "~icons/lucide/help-circle"
|
import IconHelpCircle from "~icons/lucide/help-circle"
|
||||||
import IconPlus from "~icons/lucide/plus"
|
import IconPlus from "~icons/lucide/plus"
|
||||||
import {
|
|
||||||
navigateToFolderWithIndexPath,
|
|
||||||
restCollections$,
|
|
||||||
saveRESTRequestAs,
|
|
||||||
} from "~/newstore/collections"
|
|
||||||
import { cloneDeep } from "lodash-es"
|
|
||||||
import { HoppCollection, HoppRESTAuth, HoppRESTRequest } from "@hoppscotch/data"
|
|
||||||
import { TeamCollection } from "~/helpers/backend/graphql"
|
|
||||||
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
|
||||||
import { updateInheritedPropertiesForAffectedRequests } from "~/helpers/collection/collection"
|
|
||||||
import {
|
|
||||||
resolveSaveContextOnRequestReorder,
|
|
||||||
getRequestsByPath,
|
|
||||||
} from "~/helpers/collection/request"
|
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -312,8 +308,8 @@ const onRemoveRootCollection = async () => {
|
|||||||
displayConfirmModal(false)
|
displayConfirmModal(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const addRequest = (requestPathIndex: string) => {
|
const addRequest = (parentCollectionIndexPath: string) => {
|
||||||
editingCollectionIndexPath.value = requestPathIndex
|
editingCollectionIndexPath.value = parentCollectionIndexPath
|
||||||
displayModalAddRequest(true)
|
displayModalAddRequest(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,6 +594,11 @@ const onRemoveRequest = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const possibleTab = tabs.getTabRefWithSaveContext({
|
||||||
|
originLocation: "workspace-user-collection",
|
||||||
|
requestHandle,
|
||||||
|
})
|
||||||
|
|
||||||
const result = await workspaceService.removeRESTRequest(requestHandle)
|
const result = await workspaceService.removeRESTRequest(requestHandle)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -605,11 +606,6 @@ const onRemoveRequest = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const possibleTab = tabs.getTabRefWithSaveContext({
|
|
||||||
originLocation: "workspace-user-collection",
|
|
||||||
requestHandle,
|
|
||||||
})
|
|
||||||
|
|
||||||
// If there is a tab attached to this request, dissociate its state and mark it dirty
|
// If there is a tab attached to this request, dissociate its state and mark it dirty
|
||||||
if (possibleTab) {
|
if (possibleTab) {
|
||||||
possibleTab.value.document.saveContext = null
|
possibleTab.value.document.saveContext = null
|
||||||
@@ -715,7 +711,7 @@ const duplicateRequest = async (requestIndexPath: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestHandle = requestHandleResult.right
|
const requestHandle = cloneDeep(requestHandleResult.right)
|
||||||
|
|
||||||
if (requestHandle.value.type === "invalid") {
|
if (requestHandle.value.type === "invalid") {
|
||||||
// COLLECTION_INVALIDATED | INVALID_REQUEST_HANDLE
|
// COLLECTION_INVALIDATED | INVALID_REQUEST_HANDLE
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { isEqual } from "lodash-es"
|
import { isEqual } from "lodash-es"
|
||||||
import { computed } from "vue"
|
import { computed, ref } from "vue"
|
||||||
import { getDefaultRESTRequest } from "~/helpers/rest/default"
|
import { getDefaultRESTRequest } from "~/helpers/rest/default"
|
||||||
import { HoppRESTDocument, HoppRESTSaveContext } from "~/helpers/rest/document"
|
import { HoppRESTDocument, HoppRESTSaveContext } from "~/helpers/rest/document"
|
||||||
import { TabService } from "./tab"
|
import { TabService } from "./tab"
|
||||||
@@ -50,8 +50,32 @@ export class RESTTabService extends TabService<HoppRESTDocument> {
|
|||||||
) {
|
) {
|
||||||
return this.getTabRef(tab.id)
|
return this.getTabRef(tab.id)
|
||||||
}
|
}
|
||||||
} else if (isEqual(ctx, tab.document.saveContext)) {
|
} else if (ctx?.originLocation === "user-collection") {
|
||||||
return this.getTabRef(tab.id)
|
if (isEqual(ctx, tab.document.saveContext)) {
|
||||||
|
return this.getTabRef(tab.id)
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
ctx?.originLocation === "workspace-user-collection" &&
|
||||||
|
tab.document.saveContext?.originLocation === "workspace-user-collection"
|
||||||
|
) {
|
||||||
|
const tabDocumentRequestHandle = ref(
|
||||||
|
tab.document.saveContext?.requestHandle
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
ctx?.requestHandle.value?.type === "invalid" ||
|
||||||
|
tabDocumentRequestHandle?.value.type === "invalid"
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
isEqual(
|
||||||
|
ctx?.requestHandle.value.data.request.id,
|
||||||
|
tabDocumentRequestHandle.value.data.request.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return this.getTabRef(tab.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user