Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
Fix import export for environments
Andrew Bastin50fa1c8f0ac9
diff --git a/components/environments/ImportExport.vue b/components/environments/ImportExport.vueindex 537c4d109..369a46f83 100644--- a/components/environments/ImportExport.vue+++ b/components/environments/ImportExport.vue@@ -56,22 +56,6 @@</div><div slot="body" class="flex flex-col"><div class="flex flex-col items-start p-2">- <span- v-tooltip="{- content: !fb.currentUser- ? $t('login_first')- : $t('replace_current'),- }"- >- <button- :disabled="!fb.currentUser"- class="icon"- @click="syncEnvironments"- >- <i class="material-icons">folder_shared</i>- <span>{{ $t("import_from_sync") }}</span>- </button>- </span><buttonv-tooltip="$t('replace_current')"class="icon"@@ -133,7 +117,7 @@<script>import { fb } from "~/helpers/fb"-import { getSettingSubject } from "~/newstore/settings"+import { environments$, replaceEnvironments, appendEnvironments } from "~/newstore/environments"export default {props: {@@ -147,12 +131,12 @@ export default {},subscriptions() {return {- SYNC_ENVIRONMENTS: getSettingSubject("syncEnvironments"),+ environments: environments$}},computed: {environmentJson() {- return JSON.stringify(this.$store.state.postwoman.environments, null, 2)+ return JSON.stringify(this.environments, null, 2)},},methods: {@@ -198,9 +182,8 @@ export default {}).then(({ files }) => {const environments = JSON.parse(Object.values(files)[0].content)- this.$store.commit("postwoman/replaceEnvironments", environments)+ replaceEnvironments(environments)this.fileImported()- this.syncToFBEnvironments()}).catch((error) => {this.failedImport()@@ -221,11 +204,10 @@ export default {reader.onload = ({ target }) => {const content = target.resultconst environments = JSON.parse(content)- this.$store.commit("postwoman/replaceEnvironments", environments)+ replaceEnvironments(environments)}reader.readAsText(this.$refs.inputChooseFileToReplaceWith.files[0])this.fileImported()- this.syncToFBEnvironments()this.$refs.inputChooseFileToReplaceWith.value = ""},importFromJSON() {@@ -243,15 +225,11 @@ export default {}}reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0])- this.syncToFBEnvironments()this.$refs.inputChooseFileToImportFrom.value = ""},importFromPostwoman(environments) {- const confirmation = this.$t("file_imported")- this.$store.commit("postwoman/importAddEnvironments", {- environments,- confirmation,- })+ appendEnvironments(environments)+ this.fileImported()},importFromPostman({ name, values }) {const environment = { name, variables: [] }@@ -279,20 +257,6 @@ export default {icon: "done",})},- syncEnvironments() {- this.$store.commit(- "postwoman/replaceEnvironments",- fb.currentEnvironments- )- this.fileImported()- },- syncToFBEnvironments() {- if (fb.currentUser !== null && this.SYNC_ENVIRONMENTS) {- fb.writeEnvironments(- JSON.parse(JSON.stringify(this.$store.state.postwoman.environments))- )- }- },fileImported() {this.$toast.info(this.$t("file_imported"), {icon: "folder_shared",diff --git a/newstore/environments.ts b/newstore/environments.tsindex 8702bf496..61a132f84 100644--- a/newstore/environments.ts+++ b/newstore/environments.ts@@ -43,6 +43,14 @@ const dispatchers = defineDispatchers({currentEnvironmentIndex: newIndex,}},+ appendEnvironments(+ { environments }: EnvironmentStore,+ { envs }: { envs: Environment[] }+ ) {+ return {+ environments: [...environments, ...envs],+ }+ },replaceEnvironments(_: EnvironmentStore,{ environments }: { environments: Environment[] }@@ -235,6 +243,15 @@ export function replaceEnvironments(newEnvironments: any[]) {})}+export function appendEnvironments(envs: Environment[]) {+ environmentsStore.dispatch({+ dispatcher: "appendEnvironments",+ payload: {+ envs,+ },+ })+}+export function createEnvironment(envName: string) {environmentsStore.dispatch({dispatcher: "createEnvironment",