Fix import export for environments

This commit is contained in:
Andrew Bastin
2021-06-07 00:13:28 -04:00
parent e361d66c88
commit 50fa1c8f0a
2 changed files with 24 additions and 43 deletions

View File

@@ -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>
<button
v-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.result
const 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",