Fix import export for environments
This commit is contained in:
@@ -56,22 +56,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div slot="body" class="flex flex-col">
|
<div slot="body" class="flex flex-col">
|
||||||
<div class="flex flex-col items-start p-2">
|
<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
|
<button
|
||||||
v-tooltip="$t('replace_current')"
|
v-tooltip="$t('replace_current')"
|
||||||
class="icon"
|
class="icon"
|
||||||
@@ -133,7 +117,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { fb } from "~/helpers/fb"
|
import { fb } from "~/helpers/fb"
|
||||||
import { getSettingSubject } from "~/newstore/settings"
|
import { environments$, replaceEnvironments, appendEnvironments } from "~/newstore/environments"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -147,12 +131,12 @@ export default {
|
|||||||
},
|
},
|
||||||
subscriptions() {
|
subscriptions() {
|
||||||
return {
|
return {
|
||||||
SYNC_ENVIRONMENTS: getSettingSubject("syncEnvironments"),
|
environments: environments$
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
environmentJson() {
|
environmentJson() {
|
||||||
return JSON.stringify(this.$store.state.postwoman.environments, null, 2)
|
return JSON.stringify(this.environments, null, 2)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -198,9 +182,8 @@ export default {
|
|||||||
})
|
})
|
||||||
.then(({ files }) => {
|
.then(({ files }) => {
|
||||||
const environments = JSON.parse(Object.values(files)[0].content)
|
const environments = JSON.parse(Object.values(files)[0].content)
|
||||||
this.$store.commit("postwoman/replaceEnvironments", environments)
|
replaceEnvironments(environments)
|
||||||
this.fileImported()
|
this.fileImported()
|
||||||
this.syncToFBEnvironments()
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.failedImport()
|
this.failedImport()
|
||||||
@@ -221,11 +204,10 @@ export default {
|
|||||||
reader.onload = ({ target }) => {
|
reader.onload = ({ target }) => {
|
||||||
const content = target.result
|
const content = target.result
|
||||||
const environments = JSON.parse(content)
|
const environments = JSON.parse(content)
|
||||||
this.$store.commit("postwoman/replaceEnvironments", environments)
|
replaceEnvironments(environments)
|
||||||
}
|
}
|
||||||
reader.readAsText(this.$refs.inputChooseFileToReplaceWith.files[0])
|
reader.readAsText(this.$refs.inputChooseFileToReplaceWith.files[0])
|
||||||
this.fileImported()
|
this.fileImported()
|
||||||
this.syncToFBEnvironments()
|
|
||||||
this.$refs.inputChooseFileToReplaceWith.value = ""
|
this.$refs.inputChooseFileToReplaceWith.value = ""
|
||||||
},
|
},
|
||||||
importFromJSON() {
|
importFromJSON() {
|
||||||
@@ -243,15 +225,11 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0])
|
reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0])
|
||||||
this.syncToFBEnvironments()
|
|
||||||
this.$refs.inputChooseFileToImportFrom.value = ""
|
this.$refs.inputChooseFileToImportFrom.value = ""
|
||||||
},
|
},
|
||||||
importFromPostwoman(environments) {
|
importFromPostwoman(environments) {
|
||||||
const confirmation = this.$t("file_imported")
|
appendEnvironments(environments)
|
||||||
this.$store.commit("postwoman/importAddEnvironments", {
|
this.fileImported()
|
||||||
environments,
|
|
||||||
confirmation,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
importFromPostman({ name, values }) {
|
importFromPostman({ name, values }) {
|
||||||
const environment = { name, variables: [] }
|
const environment = { name, variables: [] }
|
||||||
@@ -279,20 +257,6 @@ export default {
|
|||||||
icon: "done",
|
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() {
|
fileImported() {
|
||||||
this.$toast.info(this.$t("file_imported"), {
|
this.$toast.info(this.$t("file_imported"), {
|
||||||
icon: "folder_shared",
|
icon: "folder_shared",
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ const dispatchers = defineDispatchers({
|
|||||||
currentEnvironmentIndex: newIndex,
|
currentEnvironmentIndex: newIndex,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
appendEnvironments(
|
||||||
|
{ environments }: EnvironmentStore,
|
||||||
|
{ envs }: { envs: Environment[] }
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
environments: [...environments, ...envs],
|
||||||
|
}
|
||||||
|
},
|
||||||
replaceEnvironments(
|
replaceEnvironments(
|
||||||
_: EnvironmentStore,
|
_: EnvironmentStore,
|
||||||
{ environments }: { environments: Environment[] }
|
{ 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) {
|
export function createEnvironment(envName: string) {
|
||||||
environmentsStore.dispatch({
|
environmentsStore.dispatch({
|
||||||
dispatcher: "createEnvironment",
|
dispatcher: "createEnvironment",
|
||||||
|
|||||||
Reference in New Issue
Block a user