Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: save request context set on teams

Andrew Bastinb08b06c4d491
diff --git a/components/collections/SaveRequest.vue b/components/collections/SaveRequest.vue
index 72fb5f5ec..378544ea4 100644
--- a/components/collections/SaveRequest.vue
+++ b/components/collections/SaveRequest.vue
@@ -116,7 +116,7 @@ export default defineComponent({
onSelect({ picked }) {
this.picked = picked
},
- saveRequestAs() {
+ async saveRequestAs() {
if (!this.requestName) {
this.$toast.error(this.$t("error.empty_req_name"), {
icon: "error_outline",
@@ -180,33 +180,43 @@ export default defineComponent({
this.picked.requestID
)
setRESTSaveContext({
- originLocation: "teams-collection",
+ originLocation: "team-collection",
requestID: this.picked.requestID,
})
} else if (this.picked.pickedType === "teams-folder") {
- teamUtils.saveRequestAsTeams(
+ const req = await teamUtils.saveRequestAsTeams(
this.$apollo,
JSON.stringify(requestUpdated),
requestUpdated.name,
this.collectionsType.selectedTeam.id,
this.picked.folderID
)
- setRESTSaveContext({
- originLocation: "teams-collection",
- requestID: this.picked.requestID,
- })
+
+ if (req && req.id) {
+ setRESTSaveContext({
+ originLocation: "team-collection",
+ requestID: req.id,
+ teamID: this.collectionsType.selectedTeam.id,
+ collectionID: this.picked.folderID,
+ })
+ }
} else if (this.picked.pickedType === "teams-collection") {
- teamUtils.saveRequestAsTeams(
+ const req = await teamUtils.saveRequestAsTeams(
this.$apollo,
JSON.stringify(requestUpdated),
requestUpdated.name,
this.collectionsType.selectedTeam.id,
this.picked.collectionID
)
- setRESTSaveContext({
- originLocation: "teams-collection",
- requestID: this.picked.requestID,
- })
+
+ if (req && req.id) {
+ setRESTSaveContext({
+ originLocation: "team-collection",
+ requestID: req.id,
+ teamID: this.collectionsType.selectedTeam.id,
+ collectionID: this.picked.collectionID,
+ })
+ }
} else if (this.picked.pickedType === "gql-my-request") {
editGraphqlRequest(
this.picked.folderPath,
diff --git a/components/collections/teams/Request.vue b/components/collections/teams/Request.vue
index b132a60d9..b4acdb3f6 100644
--- a/components/collections/teams/Request.vue
+++ b/components/collections/teams/Request.vue
@@ -105,7 +105,7 @@
</div>
</template>
-<script>
+<script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api"
import { translateToNewRequest } from "~/helpers/types/HoppRESTRequest"
import { useReadonlyStream } from "~/helpers/utils/composables"
@@ -143,7 +143,7 @@ export default defineComponent({
}
},
computed: {
- isSelected() {
+ isSelected(): boolean {
return (
this.picked &&
this.picked.pickedType === "teams-request" &&
@@ -163,7 +163,7 @@ export default defineComponent({
else
setRESTRequest(translateToNewRequest(this.request), {
originLocation: "team-collection",
- requestIndex: this.requestIndex,
+ requestID: this.requestIndex as string,
})
},
removeRequest() {
@@ -173,9 +173,9 @@ export default defineComponent({
requestIndex: this.$props.requestIndex,
})
},
- getRequestLabelColor(method) {
+ getRequestLabelColor(method: any) {
return (
- this.requestMethodLabels[method.toLowerCase()] ||
+ (this.requestMethodLabels as any)[method.toLowerCase()] ||
this.requestMethodLabels.default
)
},
diff --git a/components/http/Request.vue b/components/http/Request.vue
index dbddf9b99..ecfd0613d 100644
--- a/components/http/Request.vue
+++ b/components/http/Request.vue
@@ -232,7 +232,7 @@ import {
import { defineActionHandler } from "~/helpers/actions"
import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useSetting } from "~/newstore/settings"
-import { saveRequestAsTeams } from "~/helpers/teams/utils"
+import { overwriteRequestTeams } from "~/helpers/teams/utils"
import { apolloClient } from "~/helpers/apollo"
const methods = [
@@ -386,9 +386,9 @@ export default defineComponent({
} else if (saveCtx.originLocation === "team-collection") {
const req = getRESTRequest()
- // TODO: handle error case (NOTE: saveRequestAsTeams is async)
+ // TODO: handle error case (NOTE: overwriteRequestTeams is async)
try {
- saveRequestAsTeams(
+ overwriteRequestTeams(
apolloClient,
JSON.stringify(req),
req.name,
diff --git a/helpers/teams/utils.js b/helpers/teams/utils.js
index 615bcc094..5d57e2b9d 100644
--- a/helpers/teams/utils.js
+++ b/helpers/teams/utils.js
@@ -457,10 +457,11 @@ export async function saveRequestAsTeams(
teamID,
collectionID
) {
- await apollo.mutate({
+ const x = await apollo.mutate({
mutation: gql`
mutation ($data: CreateTeamRequestInput!, $collectionID: String!) {
createRequestInCollection(data: $data, collectionID: $collectionID) {
+ id
collection {
id
team {
@@ -480,6 +481,7 @@ export async function saveRequestAsTeams(
},
},
})
+ return x.data?.createRequestInCollection
}
export async function overwriteRequestTeams(apollo, request, title, requestID) {