Skip to content

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

Fixing bug on request saving

adevrc4bd47151620
diff --git a/components/collections/saveRequestAs.vue b/components/collections/saveRequestAs.vue
index e48f01631..d880933c4 100644
--- a/components/collections/saveRequestAs.vue
+++ b/components/collections/saveRequestAs.vue
@@ -128,7 +128,11 @@ export default {
const userSelectedAnyCollection =
this.$data.requestData.collectionIndex !== undefined;
if (!userSelectedAnyCollection) return [];
-
+
+ const noCollectionAvailable =
+ this.$store.state.postwoman.collections[this.$data.requestData.collectionIndex] !== undefined;
+ if (!noCollectionAvailable) return [];
+
return this.$store.state.postwoman.collections[
this.$data.requestData.collectionIndex
].folders;
@@ -151,6 +155,10 @@ export default {
const collection = this.$store.state.postwoman.collections[
this.$data.requestData.collectionIndex
];
+ const noCollectionAvailable =
+ this.$store.state.postwoman.collections[this.$data.requestData.collectionIndex] !== undefined;
+ if (!noCollectionAvailable) return [];
+
const requests = collection.requests;
return requests;
}
diff --git a/pages/index.vue b/pages/index.vue
index f8e69737a..a417b0a1e 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -44,7 +44,17 @@
<ul>
<li>
<label for="method">{{ $t("method") }}</label>
- <select id="method" v-model="method" @change="methodChange">
+ <input
+ id="method"
+ name="method"
+ type="text"
+ v-model="method"
+ @change="methodChange"
+ value="GET"
+ placeholder="GET"
+ list="preMethods"
+ />
+ <datalist id="preMethods">
<option value="GET">GET</option>
<option value="HEAD">HEAD</option>
<option value="POST">POST</option>
@@ -54,7 +64,17 @@
<option value="OPTIONS">OPTIONS</option>
<option value="TRACE">TRACE</option>
<option value="PATCH">PATCH</option>
- </select>
+ </datalist>
+ <!-- <select id="method" v-model="method" @change="methodChange">
+ <option>GET</option>
+ <option>HEAD</option>
+ <option>POST</option>
+ <option>PUT</option>
+ <option>DELETE</option>
+ <option>OPTIONS</option>
+ <option>PATCH</option>
+ <option>LIST</option>
+ </select> -->
</li>
<li>
<label for="url">{{ $t("url") }}</label>
@@ -85,7 +105,14 @@
type="text"
v-model="label"
placeholder="(optional)"
+ list="preLabels"
/>
+ <datalist id="preLabels">
+ <option value="Login"></option>
+ <option value="Logout"></option>
+ <option value="Bug"></option>
+ <option value="Users"></option>
+ </datalist>
</li>
<li>
<label class="hide-on-small-screen" for="send">&nbsp;</label>
@@ -1360,6 +1387,11 @@ export default {
}
},
methods: {
+ checkCollections() {
+ const checkCollectionAvailability =
+ this.$store.state.postwoman.collections && this.$store.state.postwoman.collections.length > 0 ;
+ return checkCollectionAvailability;
+ },
scrollInto(view) {
this.$refs[view].$el.scrollIntoView({
behavior: "smooth"
@@ -1958,6 +1990,13 @@ export default {
);
},
saveRequest() {
+ if (!this.checkCollections()) {
+ this.$toast.error("Create a Collection", {
+ icon: "error"
+ });
+ return;
+ }
+
this.editRequest = {
url: this.url,
path: this.path,