+
-
-
+
+
+ {
+ createCollectionGist()
+ }
+ "
+ />
+
-
-
-
- {
- createCollectionGist()
- }
- "
- />
-
()
const inputChooseFileToImportFrom = ref()
const getJSONCollection = async () => {
@@ -302,16 +315,6 @@ const hideModal = () => {
emit("hide-modal")
}
-// const openDialogChooseFileToReplaceWith = () => {
-// if (inputChooseFileToReplaceWith.value)
-// inputChooseFileToReplaceWith.value.click()
-// }
-
-const openDialogChooseFileToImportFrom = () => {
- if (inputChooseFileToImportFrom.value)
- inputChooseFileToImportFrom.value.click()
-}
-
const hasFolder = (item: { item?: any }) => {
return Object.prototype.hasOwnProperty.call(item, "item")
}
@@ -478,68 +481,6 @@ const parsePostmanRequest = ({
return translateToNewRequest(pwRequest)
}
-const replaceWithJSON = () => {
- if (!inputChooseFileToReplaceWith.value) return
-
- if (
- !inputChooseFileToReplaceWith.value.files ||
- inputChooseFileToReplaceWith.value.files.length === 0
- ) {
- toast.show(t("action.choose_file").toString())
- return
- }
-
- const reader = new FileReader()
-
- reader.onload = ({ target }) => {
- const content = target!.result as string | null
-
- if (!content) {
- toast.show(t("action.choose_file").toString())
- return
- }
-
- let collections = JSON.parse(content)
-
- // TODO: File validation
- if (collections[0]) {
- const [name, folders, requests] = Object.keys(collections[0])
- if (name === "name" && folders === "folders" && requests === "requests") {
- // Do nothing
- }
- } else if (collections.info && collections.info.schema.includes("v2.1.0")) {
- collections = [parsePostmanCollection(collections)]
- } else {
- failedImport()
- }
- if (props.collectionsType.type === "team-collections") {
- teamUtils
- .replaceWithJSON(
- apolloClient,
- collections,
- props.collectionsType.selectedTeam.id
- )
- .then((status) => {
- if (status) {
- fileImported()
- } else {
- failedImport()
- }
- })
- .catch((e) => {
- console.error(e)
- failedImport()
- })
- } else {
- setRESTCollections(collections)
- fileImported()
- }
- }
-
- reader.readAsText(inputChooseFileToReplaceWith.value.files[0])
- inputChooseFileToReplaceWith.value.value = ""
-}
-
const isInsomniaCollection = (collection: any) => {
if (typeof collection === "object") {
return (
diff --git a/packages/hoppscotch-app/helpers/import-export/import/hopp.ts b/packages/hoppscotch-app/helpers/import-export/import/hopp.ts
index 9ee0d0f1c..65b5d2f34 100644
--- a/packages/hoppscotch-app/helpers/import-export/import/hopp.ts
+++ b/packages/hoppscotch-app/helpers/import-export/import/hopp.ts
@@ -11,7 +11,7 @@ export default defineImporter({
step({
stepName: "FILE_OR_URL_IMPORT",
metadata: {
- acceptedFileTypes: ["application/json"],
+ acceptedFileTypes: "application/json",
},
}),
] as const,
diff --git a/packages/hoppscotch-app/helpers/import-export/steps.ts b/packages/hoppscotch-app/helpers/import-export/steps.ts
index 989bb0c2e..cc54521c2 100644
--- a/packages/hoppscotch-app/helpers/import-export/steps.ts
+++ b/packages/hoppscotch-app/helpers/import-export/steps.ts
@@ -6,7 +6,7 @@ export type StepDefinition = {
FILE_OR_URL_IMPORT: {
returnType: string
metadata: {
- acceptedFileTypes: string[]
+ acceptedFileTypes: string
}
} // String content of the file/url
TARGET_MY_COLLECTION: {
diff --git a/packages/hoppscotch-app/locales/en.json b/packages/hoppscotch-app/locales/en.json
index 9efd1bbfc..74bb74ebe 100644
--- a/packages/hoppscotch-app/locales/en.json
+++ b/packages/hoppscotch-app/locales/en.json
@@ -237,6 +237,7 @@
"from_url": "Import from URL",
"gist_url": "Enter Gist URL",
"json": "Import from file",
+ "json_description": "Import collections from a Hoppscotch Collections JSON file",
"title": "Import"
},
"layout": {