Browse Source

feat: alert the user on empty collection/environment exports (#3416)

James George 1 year ago
parent
commit
ae89af9978

+ 2 - 0
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",

+ 7 - 0
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)

+ 6 - 0
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)
 }
 

+ 7 - 0
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)