Skip to content

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

feat: duplicate team requests

liyasthomas914d20ad37a1
diff --git a/packages/hoppscotch-app/components/collections/index.vue b/packages/hoppscotch-app/components/collections/index.vue
index 4318ffe4f..2c9fefd0b 100644
--- a/packages/hoppscotch-app/components/collections/index.vue
+++ b/packages/hoppscotch-app/components/collections/index.vue
@@ -647,11 +647,26 @@ export default defineComponent({
})
}
},
- duplicateRequest({ folderPath, request }) {
- saveRESTRequestAs(folderPath, {
- ...cloneDeep(request),
- name: `${request.name} - ${this.$t("action.duplicate")}`,
- })
+ duplicateRequest({ folderPath, request, collectionID }) {
+ if (this.collectionsType.type === "team-collections") {
+ const newReq = {
+ ...cloneDeep(request),
+ name: `${request.name} - ${this.$t("action.duplicate")}`,
+ }
+
+ teamUtils.saveRequestAsTeams(
+ this.$apollo,
+ JSON.stringify(newReq),
+ `${request.name} - ${this.$t("action.duplicate")}`,
+ this.collectionsType.selectedTeam.id,
+ collectionID
+ )
+ } else if (this.collectionsType.type === "my-collections") {
+ saveRESTRequestAs(folderPath, {
+ ...cloneDeep(request),
+ name: `${request.name} - ${this.$t("action.duplicate")}`,
+ })
+ }
},
},
})
diff --git a/packages/hoppscotch-app/components/collections/teams/Collection.vue b/packages/hoppscotch-app/components/collections/teams/Collection.vue
index 20e9febc5..65f6152dc 100644
--- a/packages/hoppscotch-app/components/collections/teams/Collection.vue
+++ b/packages/hoppscotch-app/components/collections/teams/Collection.vue
@@ -152,6 +152,7 @@
@select="$emit('select', $event)"
@expand-collection="expandCollection"
@remove-request="removeRequest"
+ @duplicate-request="$emit('duplicate-request', $event)"
/>
<CollectionsTeamsRequest
v-for="(request, index) in collection.requests"
@@ -163,11 +164,13 @@
:request-index="request.id"
:doc="doc"
:save-request="saveRequest"
+ :collection-i-d="collection.id"
:collections-type="collectionsType"
:picked="picked"
@edit-request="editRequest($event)"
@select="$emit('select', $event)"
@remove-request="removeRequest"
+ @duplicate-request="$emit('duplicate-request', $event)"
/>
<div
v-if="
diff --git a/packages/hoppscotch-app/components/collections/teams/Folder.vue b/packages/hoppscotch-app/components/collections/teams/Folder.vue
index 6d8e8f4ff..df83fb980 100644
--- a/packages/hoppscotch-app/components/collections/teams/Folder.vue
+++ b/packages/hoppscotch-app/components/collections/teams/Folder.vue
@@ -133,6 +133,7 @@
@select="$emit('select', $event)"
@expand-collection="expandCollection"
@remove-request="removeRequest"
+ @duplicate-request="$emit('duplicate-request', $event)"
/>
<CollectionsTeamsRequest
v-for="(request, index) in folder.requests"
@@ -146,9 +147,11 @@
:save-request="saveRequest"
:collections-type="collectionsType"
:picked="picked"
+ :collection-i-d="folder.id"
@edit-request="$emit('edit-request', $event)"
@select="$emit('select', $event)"
@remove-request="removeRequest"
+ @duplicate-request="$emit('duplicate-request', $event)"
/>
<div
v-if="
diff --git a/packages/hoppscotch-app/components/collections/teams/Request.vue b/packages/hoppscotch-app/components/collections/teams/Request.vue
index 38acc3a3b..3ffe265a5 100644
--- a/packages/hoppscotch-app/components/collections/teams/Request.vue
+++ b/packages/hoppscotch-app/components/collections/teams/Request.vue
@@ -81,6 +81,7 @@
class="flex flex-col focus:outline-none"
tabindex="0"
@keyup.e="edit.$el.click()"
+ @keyup.d="duplicate.$el.click()"
@keyup.delete="deleteAction.$el.click()"
@keyup.escape="options.tippy().hide()"
>
@@ -102,6 +103,22 @@
}
"
/>
+ <SmartItem
+ ref="duplicate"
+ svg="copy"
+ :label="$t('action.duplicate')"
+ :shortcut="['D']"
+ @click.native="
+ () => {
+ $emit('duplicate-request', {
+ request,
+ requestIndex,
+ collectionID,
+ })
+ options.tippy().hide()
+ }
+ "
+ />
<SmartItem
ref="deleteAction"
svg="trash-2"
@@ -150,6 +167,7 @@ export default defineComponent({
saveRequest: Boolean,
collectionsType: { type: Object, default: () => {} },
picked: { type: Object, default: () => {} },
+ collectionID: { type: String, default: null },
},
setup() {
const active = useReadonlyStream(restSaveContext$, null)
@@ -159,6 +177,7 @@ export default defineComponent({
options: ref<any | null>(null),
edit: ref<any | null>(null),
deleteAction: ref<any | null>(null),
+ duplicate: ref<any | null>(null),
}
},
data() {