diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index a114f6c53..b9d7b0dbb 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -250,7 +250,9 @@ "json_prettify_invalid_body": "Couldn't prettify an invalid body, solve json syntax errors and try again", "network_error": "There seems to be a network error. Please try again.", "network_fail": "Could not send request", + "no_collections_to_export": "No collections to export. Please create a collection to get started.", "no_duration": "No duration", + "no_environments_to_export": "No environments to export. Please create an environment to get started.", "no_results_found": "No matches found", "page_not_found": "This page could not be found", "proxy_error": "Proxy error", diff --git a/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue b/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue index d94a2c89e..ec92bbfc3 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue @@ -260,6 +260,13 @@ const importFromJSON = () => { const exportJSON = () => { const dataToWrite = collectionJson.value + + const parsedCollections = JSON.parse(dataToWrite) + + if (!parsedCollections.length) { + return toast.error(t("error.no_collections_to_export")) + } + const file = new Blob([dataToWrite], { type: "application/json" }) const a = document.createElement("a") const url = URL.createObjectURL(file) diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index 217cb4036..a7bd98fe9 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -1938,6 +1938,12 @@ const exportJSONCollection = async () => { await getJSONCollection() + const parsedCollections = JSON.parse(collectionJSON.value) + + if (!parsedCollections.length) { + return toast.error(t("error.no_collections_to_export")) + } + initializeDownloadCollection(collectionJSON.value, null) } diff --git a/packages/hoppscotch-common/src/components/environments/ImportExport.vue b/packages/hoppscotch-common/src/components/environments/ImportExport.vue index ac1b1c858..a84461d3e 100644 --- a/packages/hoppscotch-common/src/components/environments/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/environments/ImportExport.vue @@ -377,6 +377,13 @@ const importFromPostman = ({ const exportJSON = () => { const dataToWrite = environmentJson.value + + const parsedCollections = JSON.parse(dataToWrite) + + if (!parsedCollections.length) { + return toast.error(t("error.no_environments_to_export")) + } + const file = new Blob([dataToWrite], { type: "application/json" }) const a = document.createElement("a") const url = URL.createObjectURL(file)