feat: rest revamp (#2918)

Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
Co-authored-by: Nivedin <53208152+nivedin@users.noreply.github.com>
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Anwarul Islam
2023-03-31 01:15:42 +06:00
committed by GitHub
parent dbb45e7253
commit defece95fc
63 changed files with 2262 additions and 1924 deletions

View File

@@ -6,8 +6,8 @@ import {
makeCollection,
} from "@hoppscotch/data"
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
import { getRESTSaveContext, setRESTSaveContext } from "./RESTSession"
import { cloneDeep } from "lodash-es"
import { getTabRefWithSaveContext } from "~/helpers/rest/tab"
const defaultRESTCollectionState = {
state: [
@@ -400,14 +400,17 @@ const restCollectionDispatchers = defineDispatchers({
targetLocation.requests.splice(requestIndex, 1)
// If the save context is set and is set to the same source, we invalidate it
const saveCtx = getRESTSaveContext()
if (
saveCtx?.originLocation === "user-collection" &&
saveCtx.folderPath === path &&
saveCtx.requestIndex === requestIndex
) {
setRESTSaveContext(null)
// Deal with situations where a tab with the given thing is deleted
// We are just going to dissociate the save context of the tab and mark it dirty
const tab = getTabRefWithSaveContext({
originLocation: "user-collection",
folderPath: path,
requestIndex: requestIndex,
})
if (tab) {
tab.value.document.saveContext = undefined
tab.value.document.isDirty = true
}
return {
@@ -457,6 +460,20 @@ const restCollectionDispatchers = defineDispatchers({
destLocation.requests.push(req)
targetLocation.requests.splice(requestIndex, 1)
const possibleTab = getTabRefWithSaveContext({
originLocation: "user-collection",
folderPath: path,
requestIndex,
})
if (possibleTab) {
possibleTab.value.document.saveContext = {
originLocation: "user-collection",
folderPath: destinationPath,
requestIndex: destLocation.requests.length - 1,
}
}
return {
state: newState,
}
@@ -719,16 +736,6 @@ const gqlCollectionDispatchers = defineDispatchers({
targetLocation.requests.splice(requestIndex, 1)
// If the save context is set and is set to the same source, we invalidate it
const saveCtx = getRESTSaveContext()
if (
saveCtx?.originLocation === "user-collection" &&
saveCtx.folderPath === path &&
saveCtx.requestIndex === requestIndex
) {
setRESTSaveContext(null)
}
return {
state: newState,
}