feat: save request context

This commit is contained in:
Andrew Bastin
2021-08-19 12:06:56 +05:30
parent 51142e5c77
commit 1fdb6488fd
7 changed files with 169 additions and 10 deletions

View File

@@ -62,7 +62,11 @@ import {
saveGraphqlRequestAs,
} from "~/newstore/collections"
import { getGQLSession, useGQLRequestName } from "~/newstore/GQLSession"
import { getRESTRequest, useRESTRequestName } from "~/newstore/RESTSession"
import {
getRESTRequest,
useRESTRequestName,
setRESTSaveContext,
} from "~/newstore/RESTSession"
export default defineComponent({
props: {
@@ -142,10 +146,32 @@ export default defineComponent({
this.picked.requestIndex,
requestUpdated
)
setRESTSaveContext({
originLocation: "user-collection",
folderPath: this.picked.folderPath,
requestIndex: this.picked.requestIndex,
})
} else if (this.picked.pickedType === "my-folder") {
saveRESTRequestAs(this.picked.folderPath, requestUpdated)
const insertionIndex = saveRESTRequestAs(
this.picked.folderPath,
requestUpdated
)
setRESTSaveContext({
originLocation: "user-collection",
folderPath: this.picked.folderPath,
requestIndex: insertionIndex,
})
} else if (this.picked.pickedType === "my-collection") {
saveRESTRequestAs(`${this.picked.collectionIndex}`, requestUpdated)
debugger
const insertionIndex = saveRESTRequestAs(
`${this.picked.collectionIndex}`,
requestUpdated
)
setRESTSaveContext({
originLocation: "user-collection",
folderPath: `${this.picked.collectionIndex}`,
requestIndex: insertionIndex,
})
} else if (this.picked.pickedType === "teams-request") {
teamUtils.overwriteRequestTeams(
this.$apollo,
@@ -153,6 +179,10 @@ export default defineComponent({
requestUpdated.name,
this.picked.requestID
)
setRESTSaveContext({
originLocation: "teams-collection",
requestID: this.picked.requestID,
})
} else if (this.picked.pickedType === "teams-folder") {
teamUtils.saveRequestAsTeams(
this.$apollo,
@@ -161,6 +191,10 @@ export default defineComponent({
this.collectionsType.selectedTeam.id,
this.picked.folderID
)
setRESTSaveContext({
originLocation: "teams-collection",
requestID: this.picked.requestID,
})
} else if (this.picked.pickedType === "teams-collection") {
teamUtils.saveRequestAsTeams(
this.$apollo,
@@ -169,6 +203,10 @@ export default defineComponent({
this.collectionsType.selectedTeam.id,
this.picked.collectionID
)
setRESTSaveContext({
originLocation: "teams-collection",
requestID: this.picked.requestID,
})
} else if (this.picked.pickedType === "gql-my-request") {
editGraphqlRequest(
this.picked.folderPath,
@@ -183,6 +221,7 @@ export default defineComponent({
this.$toast.success("Requested added", {
icon: "done",
})
this.hideModal()
},
hideModal() {

View File

@@ -160,7 +160,13 @@ export default {
requestIndex: this.requestIndex,
},
})
else setRESTRequest(translateToNewRequest(this.request))
else {
setRESTRequest(translateToNewRequest(this.request), {
originLocation: "user-collection",
folderPath: this.folderPath,
requestIndex: this.requestIndex,
})
}
},
dragStart({ dataTransfer }) {
this.dragging = !this.dragging

View File

@@ -147,7 +147,11 @@ export default {
requestID: this.requestIndex,
},
})
else setRESTRequest(translateToNewRequest(this.request))
else
setRESTRequest(translateToNewRequest(this.request), {
originLocation: "team-collection",
requestIndex: this.requestIndex,
})
},
removeRequest() {
this.$emit("remove-request", {

View File

@@ -219,7 +219,10 @@ import {
updateRESTMethod,
resetRESTRequest,
useRESTRequestName,
getRESTSaveContext,
getRESTRequest,
} from "~/newstore/RESTSession"
import { editRESTRequest } from "~/newstore/collections"
import { getPlatformSpecialKey } from "~/helpers/platformutils"
import { runRESTRequest$ } from "~/helpers/RequestRunner"
import {
@@ -230,6 +233,8 @@ import {
import { defineActionHandler } from "~/helpers/actions"
import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useSetting } from "~/newstore/settings"
import { saveRequestAsTeams } from "~/helpers/teams/utils"
import { apolloClient } from "~/helpers/apollo"
const methods = [
"GET",
@@ -366,6 +371,32 @@ export default defineComponent({
}
}
const saveRequest = () => {
const saveCtx = getRESTSaveContext()
if (!saveCtx) {
showSaveRequestModal.value = true
return
}
if (saveCtx.originLocation === "user-collection") {
editRESTRequest(
saveCtx.folderPath,
saveCtx.requestIndex,
getRESTRequest()
)
} else if (saveCtx.originLocation === "team-collection") {
const req = getRESTRequest()
// TODO: handle error case (NOTE: saveRequestAsTeams is async)
saveRequestAsTeams(
apolloClient,
JSON.stringify(req),
req.name,
saveCtx.requestID
)
}
}
defineActionHandler("request.send-cancel", () => {
if (!loading.value) newSendRequest()
else cancelRequest()
@@ -374,10 +405,7 @@ export default defineComponent({
defineActionHandler("request.copy-link", copyRequest)
defineActionHandler("request.method.next", cycleDownMethod)
defineActionHandler("request.method.prev", cycleUpMethod)
defineActionHandler(
"request.save",
() => (showSaveRequestModal.value = true)
)
defineActionHandler("request.save", saveRequest)
defineActionHandler("request.method.get", () => updateMethod("GET"))
defineActionHandler("request.method.post", () => updateMethod("POST"))
defineActionHandler("request.method.put", () => updateMethod("PUT"))