From c11b5925435fca9039f9310f02811850479cb1ad Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Mon, 5 Dec 2022 18:11:05 +0530 Subject: [PATCH] feat: ability to export a single environment --- .../environments/my/Environment.vue | 33 +++++++++++++++++++ .../environments/teams/Environment.vue | 33 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/packages/hoppscotch-common/src/components/environments/my/Environment.vue b/packages/hoppscotch-common/src/components/environments/my/Environment.vue index 8a188bca2..ec43b26e2 100644 --- a/packages/hoppscotch-common/src/components/environments/my/Environment.vue +++ b/packages/hoppscotch-common/src/components/environments/my/Environment.vue @@ -46,6 +46,7 @@ role="menu" @keyup.e="edit!.$el.click()" @keyup.d="duplicate!.$el.click()" + @keyup.x="exportAction!.$el.click()" @keyup.delete=" !(environmentIndex === 'Global') ? deleteAction!.$el.click() @@ -77,6 +78,18 @@ } " /> + (null) const edit = ref(null) const duplicate = ref(null) const deleteAction = ref(null) +const exportAction = ref(null) const removeEnvironment = () => { if (props.environmentIndex === null) return @@ -161,4 +176,22 @@ const duplicateEnvironments = () => { ) } else duplicateEnvironment(props.environmentIndex) } + +const exportEnvironment = () => { + const environmentJSON = JSON.stringify(props.environment) + + const file = new Blob([environmentJSON], { type: "application/json" }) + const a = document.createElement("a") + const url = URL.createObjectURL(file) + a.href = url + + a.download = `${props.environment.name}.json` + document.body.appendChild(a) + a.click() + toast.success(t("state.download_started").toString()) + setTimeout(() => { + document.body.removeChild(a) + URL.revokeObjectURL(url) + }, 1000) +} diff --git a/packages/hoppscotch-common/src/components/environments/teams/Environment.vue b/packages/hoppscotch-common/src/components/environments/teams/Environment.vue index cc4796451..2cad2fe13 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/Environment.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/Environment.vue @@ -40,6 +40,7 @@ role="menu" @keyup.e="edit!.$el.click()" @keyup.d="duplicate!.$el.click()" + @keyup.x="exportAction!.$el.click()" @keyup.delete="deleteAction!.$el.click()" @keyup.escape="options!.tippy().hide()" > @@ -67,6 +68,18 @@ } " /> + (null) const edit = ref(null) const duplicate = ref(null) const deleteAction = ref(null) +const exportAction = ref(null) const removeEnvironment = () => { pipe( @@ -173,4 +188,22 @@ const getErrorMessage = (err: GQLError) => { } } } + +const exportEnvironment = () => { + const environmentJSON = JSON.stringify(props.environment.environment) + + const file = new Blob([environmentJSON], { type: "application/json" }) + const a = document.createElement("a") + const url = URL.createObjectURL(file) + a.href = url + + a.download = `${props.environment.environment.name}.json` + document.body.appendChild(a) + a.click() + toast.success(t("state.download_started").toString()) + setTimeout(() => { + document.body.removeChild(a) + URL.revokeObjectURL(url) + }, 1000) +}