Skip to content

Commit

Permalink
feat: duplicate team requests
Browse files Browse the repository at this point in the history
  • Loading branch information
liyasthomas committed Jan 4, 2022
1 parent f17cdff commit 914d20a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/hoppscotch-app/components/collections/index.vue
Expand Up @@ -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")}`,
})
}
},
},
})
Expand Down
Expand Up @@ -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"
Expand All @@ -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="
Expand Down
Expand Up @@ -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"
Expand All @@ -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="
Expand Down
19 changes: 19 additions & 0 deletions packages/hoppscotch-app/components/collections/teams/Request.vue
Expand Up @@ -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()"
>
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand Down

0 comments on commit 914d20a

Please sign in to comment.