Skip to content

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

refactor: request actions + fix: timeout bug

Liyas Thomas2ff0f97295bd
diff --git a/components/collections/index.vue b/components/collections/index.vue
index 4772ab5bd..70f256489 100644
--- a/components/collections/index.vue
+++ b/components/collections/index.vue
@@ -124,6 +124,7 @@
@unselect-collection="$emit('remove-collection', collection)"
@expand-collection="expandCollection"
@remove-collection="removeCollection"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -595,6 +596,36 @@ export default {
}
}
},
+ removeRequest({ collectionIndex, folderName, requestIndex }) {
+ if (this.collectionsType.type == "my-collections") {
+ this.$store.commit("postwoman/removeRequest", {
+ collectionIndex: collectionIndex,
+ folderName: folderName,
+ requestIndex: requestIndex,
+ flag: "rest",
+ })
+ this.$toast.error(this.$t("deleted"), {
+ icon: "delete",
+ })
+ this.syncCollections()
+ } else if (this.collectionsType.type == "team-collections") {
+ team_utils
+ .deleteRequest(this.$apollo, requestIndex)
+ .then((data) => {
+ // Result
+ this.$toast.success(this.$t("deleted"), {
+ icon: "delete",
+ })
+ })
+ .catch((error) => {
+ // Error
+ this.$toast.error(this.$t("error_occurred"), {
+ icon: "done",
+ })
+ console.error(error)
+ })
+ }
+ },
},
beforeDestroy() {
document.removeEventListener("keydown", this._keyListener)
diff --git a/components/collections/my/Collection.vue b/components/collections/my/Collection.vue
index a85bbe819..d9bf8426b 100644
--- a/components/collections/my/Collection.vue
+++ b/components/collections/my/Collection.vue
@@ -89,6 +89,7 @@
reqIdx: $event.reqIdx,
})
"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -115,6 +116,7 @@
reqIdx: $event.idx,
})
"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -224,6 +226,13 @@ export default {
})
this.syncCollections()
},
+ removeRequest({ collectionIndex, folderName, requestIndex }) {
+ this.$emit("remove-request", {
+ collectionIndex,
+ folderName,
+ requestIndex,
+ })
+ },
},
}
</script>
diff --git a/components/collections/my/Folder.vue b/components/collections/my/Folder.vue
index cdb7fdbfa..7a1fd8ea4 100644
--- a/components/collections/my/Folder.vue
+++ b/components/collections/my/Folder.vue
@@ -77,6 +77,7 @@
reqIdx: $event.reqIdx,
})
"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -103,6 +104,7 @@
reqIdx: $event.idx,
})
"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -206,6 +208,13 @@ export default {
})
this.syncCollections()
},
+ removeRequest({ collectionIndex, folderName, requestIndex }) {
+ this.$emit("remove-request", {
+ collectionIndex,
+ folderName,
+ requestIndex,
+ })
+ },
},
}
</script>
diff --git a/components/collections/my/Request.vue b/components/collections/my/Request.vue
index f43e7c2d0..4d49f3845 100644
--- a/components/collections/my/Request.vue
+++ b/components/collections/my/Request.vue
@@ -88,20 +88,7 @@ export default {
confirmRemove: false,
}
},
- subscriptions() {
- return {
- SYNC_COLLECTIONS: getSettingSubject("syncCollections"),
- }
- },
methods: {
- syncCollections() {
- if (fb.currentUser !== null && this.SYNC_COLLECTIONS) {
- fb.writeCollections(
- JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)),
- "collections"
- )
- }
- },
selectRequest() {
if (this.$props.saveRequest)
this.$emit("select-request", {
@@ -118,16 +105,11 @@ export default {
dataTransfer.setData("requestIndex", this.$props.requestIndex)
},
removeRequest() {
- this.$store.commit("postwoman/removeRequest", {
+ this.$emit("remove-request", {
collectionIndex: this.$props.collectionIndex,
folderName: this.$props.folderName,
requestIndex: this.$props.requestIndex,
- flag: "rest",
- })
- this.$toast.error(this.$t("deleted"), {
- icon: "delete",
})
- this.syncCollections()
},
getRequestLabelColor(method) {
return this.requestMethodLabels[method.toLowerCase()] || this.requestMethodLabels.default
diff --git a/components/collections/teams/Collection.vue b/components/collections/teams/Collection.vue
index 3954ed822..ac81803b3 100644
--- a/components/collections/teams/Collection.vue
+++ b/components/collections/teams/Collection.vue
@@ -97,6 +97,7 @@
})
"
@expand-collection="expandCollection"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -123,6 +124,7 @@
reqIdx: $event.idx,
})
"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -203,6 +205,13 @@ export default {
expandCollection(collectionID) {
this.$emit("expand-collection", collectionID)
},
+ removeRequest({ collectionIndex, folderName, requestIndex }) {
+ this.$emit("remove-request", {
+ collectionIndex,
+ folderName,
+ requestIndex,
+ })
+ },
},
}
</script>
diff --git a/components/collections/teams/Folder.vue b/components/collections/teams/Folder.vue
index b9f363025..758fd3ea6 100644
--- a/components/collections/teams/Folder.vue
+++ b/components/collections/teams/Folder.vue
@@ -81,6 +81,7 @@
})
"
@expand-collection="expandCollection"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -107,6 +108,7 @@
reqIdx: $event.idx,
})
"
+ @remove-request="removeRequest"
/>
</li>
</ul>
@@ -203,6 +205,13 @@ export default {
expandCollection(collectionID) {
this.$emit("expand-collection", collectionID)
},
+ removeRequest({ collectionIndex, folderName, requestIndex }) {
+ this.$emit("remove-request", {
+ collectionIndex,
+ folderName,
+ requestIndex,
+ })
+ },
},
}
</script>
diff --git a/components/collections/teams/Request.vue b/components/collections/teams/Request.vue
index 14ef67d73..8ea33cbb4 100644
--- a/components/collections/teams/Request.vue
+++ b/components/collections/teams/Request.vue
@@ -85,20 +85,7 @@ export default {
confirmRemove: false,
}
},
- subscriptions() {
- return {
- SYNC_COLLECTIONS: getSettingSubject("syncCollections"),
- }
- },
methods: {
- syncCollections() {
- if (fb.currentUser !== null && this.SYNC_COLLECTIONS) {
- fb.writeCollections(
- JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)),
- "collections"
- )
- }
- },
selectRequest() {
if (this.$props.saveRequest)
this.$emit("select-request", {
@@ -107,30 +94,12 @@ export default {
})
else this.$store.commit("postwoman/selectRequest", { request: this.request })
},
- dragStart({ dataTransfer }) {
- this.dragging = !this.dragging
- dataTransfer.setData("oldCollectionIndex", this.$props.collectionIndex)
- dataTransfer.setData("oldFolderIndex", this.$props.folderIndex)
- dataTransfer.setData("oldFolderName", this.$props.folderName)
- dataTransfer.setData("requestIndex", this.$props.requestIndex)
- },
removeRequest() {
- team_utils
- .deleteRequest(this.$apollo, this.$props.requestIndex)
- .then((data) => {
- // Result
- this.$toast.success(this.$t("deleted"), {
- icon: "delete",
- })
- })
- .catch((error) => {
- // Error
- this.$toast.error(this.$t("error_occurred"), {
- icon: "done",
- })
- console.error(error)
- })
- this.$data.confirmRemove = false
+ this.$emit("remove-request", {
+ collectionIndex: this.$props.collectionIndex,
+ folderName: this.$props.folderName,
+ requestIndex: this.$props.requestIndex,
+ })
},
getRequestLabelColor(method) {
return this.requestMethodLabels[method.toLowerCase()] || this.requestMethodLabels.default
diff --git a/components/teams/Edit.vue b/components/teams/Edit.vue
index f80fda497..a40f77e0a 100644
--- a/components/teams/Edit.vue
+++ b/components/teams/Edit.vue
@@ -6,7 +6,7 @@
<div class="row-wrapper">
<h3 class="title">{{ $t("edit_team") }}</h3>
<div>
- <button class="icon" @click="hideModal">
+ <button class="icon" @click="ideModal">
<i class="material-icons">close</i>
</button>
</div>
@@ -53,15 +53,17 @@
/>
<template slot="popover">
<div>
- <button class="icon" v-close-popover @click="member.role = 'OWNER'">OWNER</button>
+ <button class="icon" v-close-popover @click="updateRole(index, 'OWNER')">
+ OWNER
+ </button>
</div>
<div>
- <button class="icon" v-close-popover @click="member.role = 'EDITOR'">
+ <button class="icon" v-close-popover @click="updateRole(index, 'EDITOR')">
EDITOR
</button>
</div>
<div>
- <button class="icon" v-close-popover @click="member.role = 'VIEWER'">
+ <button class="icon" v-close-popover @click="updateRole(index, 'VIEWER')">
VIEWER
</button>
</div>
@@ -304,6 +306,9 @@ export default {
},
},
methods: {
+ updateRole(id, role) {
+ this.teamMembers[id].role = role
+ },
addTeamMember() {
let value = { key: "", value: "" }
this.members.push(value)
diff --git a/components/teams/Team.vue b/components/teams/Team.vue
index 7ef6dbc32..64fa48b36 100644
--- a/components/teams/Team.vue
+++ b/components/teams/Team.vue
@@ -1,7 +1,11 @@
<template>
<div class="row-wrapper">
<div>
- <button class="icon" v-tooltip.right="$t('use_team')">
+ <button
+ class="icon"
+ @click="team.myRole === 'OWNER' ? $emit('edit-team') : ''"
+ v-tooltip.right="$t('edit')"
+ >
<i class="material-icons">group</i>
<span>{{ team.name }}</span>
</button>
diff --git a/helpers/apollo.ts b/helpers/apollo.ts
index 719b885ed..195bbac26 100644
--- a/helpers/apollo.ts
+++ b/helpers/apollo.ts
@@ -1,8 +1,8 @@
-import { ApolloClient, HttpLink, InMemoryCache, split } from "@apollo/client/core";
-import { WebSocketLink } from "@apollo/client/link/ws";
-import { setContext } from '@apollo/client/link/context';
-import { fb } from "./fb";
-import { getMainDefinition } from "@apollo/client/utilities";
+import { ApolloClient, HttpLink, InMemoryCache, split } from "@apollo/client/core"
+import { WebSocketLink } from "@apollo/client/link/ws"
+import { setContext } from "@apollo/client/link/context"
+import { fb } from "./fb"
+import { getMainDefinition } from "@apollo/client/utilities"
/**
* Stores the current authentication token
@@ -10,14 +10,14 @@ import { getMainDefinition } from "@apollo/client/utilities";
* The token stored here is the Firebase Auth token.
* If null, no token is passed (no user signed in)
*/
-let authToken: string | null = null;
+let authToken: string | null = null
/*
* Updates the token value on Firebase ID Token changes
*/
-fb.idToken$.subscribe(newToken => {
- authToken = newToken;
-});
+fb.idToken$.subscribe((newToken) => {
+ authToken = newToken
+})
/**
* Injects auth token if available
@@ -27,63 +27,62 @@ const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
- authorization: `Bearer ${authToken}`
- }
+ authorization: `Bearer ${authToken}`,
+ },
}
} else {
return {
- headers
+ headers,
}
}
})
-
const httpLink = new HttpLink({
- uri: process.env.CONTEXT === "production"
- ? "https://api.hoppscotch.io/graphql"
- : "https://api.hoppscotch.io/graphql",
+ uri:
+ process.env.CONTEXT === "production"
+ ? "https://api.hoppscotch.io/graphql"
+ : "https://api.hoppscotch.io/graphql",
})
-
const wsLink = new WebSocketLink({
- uri: process.env.CONTEXT === "production"
- ? "wss://api.hoppscotch.io/graphql"
- : "wss://api.hoppscotch.io/graphql",
+ uri:
+ process.env.CONTEXT === "production"
+ ? "wss://api.hoppscotch.io/graphql"
+ : "wss://api.hoppscotch.io/graphql",
options: {
- lazy: true,
reconnect: true,
- timeout: 300,
+ lazy: true,
connectionParams: () => {
+ console.log("WS Authorization")
+ console.log(authToken)
+
return {
- authorization: `Bearer ${authToken}`
+ authorization: `Bearer ${authToken}`,
}
- }
- }
-});
+ },
+ },
+})
const splitLink = split(
({ query }) => {
- const definition = getMainDefinition(query);
- return (
- definition.kind === 'OperationDefinition' &&
- definition.operation === 'subscription'
- )
- },
- wsLink,
- httpLink
-);
+ const definition = getMainDefinition(query)
+ return definition.kind === "OperationDefinition" && definition.operation === "subscription"
+ },
+ wsLink,
+ httpLink
+)
export const apolloClient = new ApolloClient({
link: authLink.concat(splitLink),
cache: new InMemoryCache(),
defaultOptions: {
query: {
- fetchPolicy: 'network-only',
- errorPolicy: 'ignore'
+ fetchPolicy: "network-only",
+ errorPolicy: "ignore",
},
watchQuery: {
- fetchPolicy: 'network-only',
- errorPolicy: 'ignore'
- }
- }
-});
+ fetchPolicy: "network-only",
+ errorPolicy: "ignore",
+ },
+ },
+})