feat: implement export single collection

This commit is contained in:
Andrew Bastin
2022-02-07 23:42:52 +05:30
parent 85521b4c37
commit 93ccf5dcf6
8 changed files with 269 additions and 29 deletions

View File

@@ -126,11 +126,11 @@
<SmartItem
ref="exportAction"
svg="download"
:label="$t('export.as_json')"
:label="$t('export.export')"
:shortcut="['X']"
@click.native="
() => {
$emit('export-collection')
exportCollection()
options.tippy().hide()
}
"
@@ -265,6 +265,23 @@ export default defineComponent({
},
},
methods: {
exportCollection() {
const collectionJSON = JSON.stringify(this.collection)
const file = new Blob([collectionJSON], { type: "application/json" })
const a = document.createElement("a")
const url = URL.createObjectURL(file)
a.href = url
a.download = `${this.collection.name}.json`
document.body.appendChild(a)
a.click()
this.$toast.success(this.$t("state.download_started").toString())
setTimeout(() => {
document.body.removeChild(a)
URL.revokeObjectURL(url)
}, 1000)
},
toggleShowChildren() {
if (this.$props.saveRequest)
this.$emit("select", {
@@ -284,7 +301,7 @@ export default defineComponent({
collectionID: this.collection.id,
})
},
dropEvent({ dataTransfer }) {
dropEvent({ dataTransfer }: any) {
this.dragging = !this.dragging
const folderPath = dataTransfer.getData("folderPath")
const requestIndex = dataTransfer.getData("requestIndex")

View File

@@ -106,11 +106,11 @@
<SmartItem
ref="exportAction"
svg="download"
:label="$t('export.as_json')"
:label="$t('export.export')"
:shortcut="['X']"
@click.native="
() => {
$emit('export-collection')
exportFolder()
options.tippy().hide()
}
"
@@ -253,6 +253,23 @@ export default defineComponent({
},
},
methods: {
exportFolder() {
const folderJSON = JSON.stringify(this.folder)
const file = new Blob([folderJSON], { type: "application/json" })
const a = document.createElement("a")
const url = URL.createObjectURL(file)
a.href = url
a.download = `${this.folder.name}.json`
document.body.appendChild(a)
a.click()
this.$toast.success(this.$t("state.download_started").toString())
setTimeout(() => {
document.body.removeChild(a)
URL.revokeObjectURL(url)
}, 1000)
},
toggleShowChildren() {
if (this.$props.saveRequest)
this.$emit("select", {

View File

@@ -127,18 +127,10 @@
<SmartItem
ref="exportAction"
svg="download"
:label="$t('export.as_json')"
:label="$t('export.export')"
:shortcut="['X']"
:loading="exportLoading"
@click.native="
() => {
$emit('export-collection')
// TODO: remove the below line
exportLoading = true
// TODO: remove the below line, instead hide the tooltip after finishing export
options.tippy().hide()
}
"
@click.native="exportCollection"
/>
</div>
</tippy>
@@ -230,6 +222,10 @@
<script lang="ts">
import { defineComponent, ref } from "@nuxtjs/composition-api"
import * as E from "fp-ts/Either"
import {
getCompleteCollectionTree,
teamCollToHoppRESTColl,
} from "~/helpers/backend/helpers"
import { moveRESTTeamRequest } from "~/helpers/backend/mutations/TeamRequest"
import { useI18n } from "~/helpers/utils/composables"
@@ -286,7 +282,44 @@ export default defineComponent({
},
},
methods: {
editRequest(event) {
async exportCollection() {
this.exportLoading = true
const result = await getCompleteCollectionTree(this.collection.id)()
if (E.isLeft(result)) {
this.$toast.error(this.$t("error.something_went_wrong").toString())
console.log(result.left)
this.exportLoading = false
this.options.tippy().hide()
return
}
const hoppColl = teamCollToHoppRESTColl(result.right)
const collectionJSON = JSON.stringify(hoppColl)
const file = new Blob([collectionJSON], { type: "application/json" })
const a = document.createElement("a")
const url = URL.createObjectURL(file)
a.href = url
a.download = `${hoppColl.name}.json`
document.body.appendChild(a)
a.click()
this.$toast.success(this.$t("state.download_started").toString())
setTimeout(() => {
document.body.removeChild(a)
URL.revokeObjectURL(url)
}, 1000)
this.exportLoading = false
this.options.tippy().hide()
},
editRequest(event: any) {
this.$emit("edit-request", event)
if (this.$props.saveRequest)
this.$emit("select", {
@@ -315,10 +348,10 @@ export default defineComponent({
collectionID: this.collection.id,
})
},
expandCollection(collectionID) {
expandCollection(collectionID: string) {
this.$emit("expand-collection", collectionID)
},
async dropEvent({ dataTransfer }) {
async dropEvent({ dataTransfer }: any) {
this.dragging = !this.dragging
const requestIndex = dataTransfer.getData("requestIndex")
const moveRequestResult = await moveRESTTeamRequest(
@@ -328,7 +361,7 @@ export default defineComponent({
if (E.isLeft(moveRequestResult))
this.$toast.error(`${this.$t("error.something_went_wrong")}`)
},
removeRequest({ collectionIndex, folderName, requestIndex }) {
removeRequest({ collectionIndex, folderName, requestIndex }: any) {
this.$emit("remove-request", {
collectionIndex,
folderName,

View File

@@ -108,18 +108,10 @@
<SmartItem
ref="exportAction"
svg="download"
:label="$t('export.as_json')"
:label="$t('export.export')"
:shortcut="['X']"
:loading="exportLoading"
@click.native="
() => {
$emit('export-collection')
// TODO: remove the below line
exportLoading = true
// TODO: remove the below line, instead hide the tooltip after finishing export
options.tippy().hide()
}
"
@click.native="exportFolder"
/>
</div>
</tippy>
@@ -211,6 +203,10 @@ import { defineComponent, ref } from "@nuxtjs/composition-api"
import * as E from "fp-ts/Either"
import { runMutation } from "~/helpers/backend/GQLClient"
import { DeleteCollectionDocument } from "~/helpers/backend/graphql"
import {
getCompleteCollectionTree,
teamCollToHoppRESTColl,
} from "~/helpers/backend/helpers"
import { moveRESTTeamRequest } from "~/helpers/backend/mutations/TeamRequest"
export default defineComponent({
@@ -263,6 +259,43 @@ export default defineComponent({
},
},
methods: {
async exportFolder() {
this.exportLoading = true
const result = await getCompleteCollectionTree(this.folder.id)()
if (E.isLeft(result)) {
this.$toast.error(this.$t("error.something_went_wrong").toString())
console.log(result.left)
this.exportLoading = false
this.options.tippy().hide()
return
}
const hoppColl = teamCollToHoppRESTColl(result.right)
const collectionJSON = JSON.stringify(hoppColl)
const file = new Blob([collectionJSON], { type: "application/json" })
const a = document.createElement("a")
const url = URL.createObjectURL(file)
a.href = url
a.download = `${hoppColl.name}.json`
document.body.appendChild(a)
a.click()
this.$toast.success(this.$t("state.download_started").toString())
setTimeout(() => {
document.body.removeChild(a)
URL.revokeObjectURL(url)
}, 1000)
this.exportLoading = false
this.options.tippy().hide()
},
toggleShowChildren() {
if (this.$props.saveRequest)
this.$emit("select", {