fix: save request context set on teams

This commit is contained in:
Andrew Bastin
2021-08-20 18:25:34 +05:30
parent 7082eb27db
commit b08b06c4d4
4 changed files with 33 additions and 21 deletions

View File

@@ -116,7 +116,7 @@ export default defineComponent({
onSelect({ picked }) { onSelect({ picked }) {
this.picked = picked this.picked = picked
}, },
saveRequestAs() { async saveRequestAs() {
if (!this.requestName) { if (!this.requestName) {
this.$toast.error(this.$t("error.empty_req_name"), { this.$toast.error(this.$t("error.empty_req_name"), {
icon: "error_outline", icon: "error_outline",
@@ -180,33 +180,43 @@ export default defineComponent({
this.picked.requestID this.picked.requestID
) )
setRESTSaveContext({ setRESTSaveContext({
originLocation: "teams-collection", originLocation: "team-collection",
requestID: this.picked.requestID, requestID: this.picked.requestID,
}) })
} else if (this.picked.pickedType === "teams-folder") { } else if (this.picked.pickedType === "teams-folder") {
teamUtils.saveRequestAsTeams( const req = await teamUtils.saveRequestAsTeams(
this.$apollo, this.$apollo,
JSON.stringify(requestUpdated), JSON.stringify(requestUpdated),
requestUpdated.name, requestUpdated.name,
this.collectionsType.selectedTeam.id, this.collectionsType.selectedTeam.id,
this.picked.folderID this.picked.folderID
) )
setRESTSaveContext({
originLocation: "teams-collection", if (req && req.id) {
requestID: this.picked.requestID, setRESTSaveContext({
}) originLocation: "team-collection",
requestID: req.id,
teamID: this.collectionsType.selectedTeam.id,
collectionID: this.picked.folderID,
})
}
} else if (this.picked.pickedType === "teams-collection") { } else if (this.picked.pickedType === "teams-collection") {
teamUtils.saveRequestAsTeams( const req = await teamUtils.saveRequestAsTeams(
this.$apollo, this.$apollo,
JSON.stringify(requestUpdated), JSON.stringify(requestUpdated),
requestUpdated.name, requestUpdated.name,
this.collectionsType.selectedTeam.id, this.collectionsType.selectedTeam.id,
this.picked.collectionID this.picked.collectionID
) )
setRESTSaveContext({
originLocation: "teams-collection", if (req && req.id) {
requestID: this.picked.requestID, setRESTSaveContext({
}) originLocation: "team-collection",
requestID: req.id,
teamID: this.collectionsType.selectedTeam.id,
collectionID: this.picked.collectionID,
})
}
} else if (this.picked.pickedType === "gql-my-request") { } else if (this.picked.pickedType === "gql-my-request") {
editGraphqlRequest( editGraphqlRequest(
this.picked.folderPath, this.picked.folderPath,

View File

@@ -105,7 +105,7 @@
</div> </div>
</template> </template>
<script> <script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api" import { defineComponent } from "@nuxtjs/composition-api"
import { translateToNewRequest } from "~/helpers/types/HoppRESTRequest" import { translateToNewRequest } from "~/helpers/types/HoppRESTRequest"
import { useReadonlyStream } from "~/helpers/utils/composables" import { useReadonlyStream } from "~/helpers/utils/composables"
@@ -143,7 +143,7 @@ export default defineComponent({
} }
}, },
computed: { computed: {
isSelected() { isSelected(): boolean {
return ( return (
this.picked && this.picked &&
this.picked.pickedType === "teams-request" && this.picked.pickedType === "teams-request" &&
@@ -163,7 +163,7 @@ export default defineComponent({
else else
setRESTRequest(translateToNewRequest(this.request), { setRESTRequest(translateToNewRequest(this.request), {
originLocation: "team-collection", originLocation: "team-collection",
requestIndex: this.requestIndex, requestID: this.requestIndex as string,
}) })
}, },
removeRequest() { removeRequest() {
@@ -173,9 +173,9 @@ export default defineComponent({
requestIndex: this.$props.requestIndex, requestIndex: this.$props.requestIndex,
}) })
}, },
getRequestLabelColor(method) { getRequestLabelColor(method: any) {
return ( return (
this.requestMethodLabels[method.toLowerCase()] || (this.requestMethodLabels as any)[method.toLowerCase()] ||
this.requestMethodLabels.default this.requestMethodLabels.default
) )
}, },

View File

@@ -232,7 +232,7 @@ import {
import { defineActionHandler } from "~/helpers/actions" import { defineActionHandler } from "~/helpers/actions"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useSetting } from "~/newstore/settings" import { useSetting } from "~/newstore/settings"
import { saveRequestAsTeams } from "~/helpers/teams/utils" import { overwriteRequestTeams } from "~/helpers/teams/utils"
import { apolloClient } from "~/helpers/apollo" import { apolloClient } from "~/helpers/apollo"
const methods = [ const methods = [
@@ -386,9 +386,9 @@ export default defineComponent({
} else if (saveCtx.originLocation === "team-collection") { } else if (saveCtx.originLocation === "team-collection") {
const req = getRESTRequest() const req = getRESTRequest()
// TODO: handle error case (NOTE: saveRequestAsTeams is async) // TODO: handle error case (NOTE: overwriteRequestTeams is async)
try { try {
saveRequestAsTeams( overwriteRequestTeams(
apolloClient, apolloClient,
JSON.stringify(req), JSON.stringify(req),
req.name, req.name,

View File

@@ -457,10 +457,11 @@ export async function saveRequestAsTeams(
teamID, teamID,
collectionID collectionID
) { ) {
await apollo.mutate({ const x = await apollo.mutate({
mutation: gql` mutation: gql`
mutation ($data: CreateTeamRequestInput!, $collectionID: String!) { mutation ($data: CreateTeamRequestInput!, $collectionID: String!) {
createRequestInCollection(data: $data, collectionID: $collectionID) { createRequestInCollection(data: $data, collectionID: $collectionID) {
id
collection { collection {
id id
team { team {
@@ -480,6 +481,7 @@ export async function saveRequestAsTeams(
}, },
}, },
}) })
return x.data?.createRequestInCollection
} }
export async function overwriteRequestTeams(apollo, request, title, requestID) { export async function overwriteRequestTeams(apollo, request, title, requestID) {