diff --git a/packages/hoppscotch-app/components/collections/ImportExport.vue b/packages/hoppscotch-app/components/collections/ImportExport.vue
index 65124db58..7103d75d6 100644
--- a/packages/hoppscotch-app/components/collections/ImportExport.vue
+++ b/packages/hoppscotch-app/components/collections/ImportExport.vue
@@ -33,7 +33,7 @@
check_circle
- {{ t("import.json_description") }}
+ {{ t(`${step.metadata.caption}`) }}
@@ -59,7 +59,7 @@
check_circle
- {{ t("import.gist_description") }}
+ {{ t(`${step.metadata.caption}`) }}
@@ -77,23 +77,13 @@
>
@@ -119,7 +110,7 @@
(undefined)
const collectionJson = ref("")
const inputChooseFileToImportFrom = ref()
const inputChooseGistToImportFrom = ref("")
@@ -278,30 +275,39 @@ const hideModal = () => {
emit("hide-modal")
}
-const stepResults = ref([])
+const stepResults = ref([])
-// const importFromMyCollections = () => {
-// if (props.collectionsType.type !== "team-collections") return
+watch(mySelectedCollectionID, (newValue) => {
+ if (newValue === undefined) return
+ stepResults.value = []
+ stepResults.value.push(newValue)
+})
-// teamUtils
-// .importFromMyCollections(
-// apolloClient,
-// mySelectedCollectionID.value,
-// props.collectionsType.selectedTeam.id
-// )
-// .then((success) => {
-// if (success) {
-// fileImported()
-// emit("update-team-collections")
-// } else {
-// failedImport()
-// }
-// })
-// .catch((e) => {
-// console.error(e)
-// failedImport()
-// })
-// }
+const importingMyCollections = ref(false)
+
+const importToTeams = async (content: Collection) => {
+ importingMyCollections.value = true
+ if (props.collectionsType.type !== "team-collections") return
+ await teamUtils
+ .importFromJSON(
+ apolloClient,
+ content,
+ props.collectionsType.selectedTeam.id
+ )
+ .then((status) => {
+ if (status) {
+ emit("update-team-collections")
+ } else {
+ console.error(status)
+ }
+ })
+ .catch((e) => {
+ console.error(e)
+ })
+ .finally(() => {
+ importingMyCollections.value = false
+ })
+}
const exportJSON = () => {
getJSONCollection()
@@ -323,13 +329,18 @@ const exportJSON = () => {
}, 1000)
}
+const importerModules = computed(() =>
+ RESTCollectionImporters.filter(
+ (i) => i.applicableTo?.includes(props.collectionsType.type) ?? true
+ )
+)
+
const importerType = ref(null)
const importerModule = computed(() =>
- importerType.value !== null
- ? RESTCollectionImporters[importerType.value]
- : null
+ importerType.value !== null ? importerModules.value[importerType.value] : null
)
+
const importerSteps = computed(() => importerModule.value?.steps ?? null)
const finishImport = async () => {
@@ -343,8 +354,13 @@ const importerAction = async (stepResults: any[]) => {
failedImport()
console.error("error", result.left)
} else if (E.isRight(result)) {
- appendRESTCollections(result.right)
- fileImported()
+ if (props.collectionsType.type === "team-collections") {
+ importToTeams(result.right)
+ fileImported()
+ } else {
+ appendRESTCollections(result.right)
+ fileImported()
+ }
}
}
@@ -362,6 +378,7 @@ watch(inputChooseGistToImportFrom, (v) => {
})
const onFileChange = () => {
+ stepResults.value = []
if (!inputChooseFileToImportFrom.value[0]) {
hasFile.value = false
return
diff --git a/packages/hoppscotch-app/helpers/import-export/import/gist.ts b/packages/hoppscotch-app/helpers/import-export/import/gist.ts
index ce4f7f34e..36ecf4ddc 100644
--- a/packages/hoppscotch-app/helpers/import-export/import/gist.ts
+++ b/packages/hoppscotch-app/helpers/import-export/import/gist.ts
@@ -29,12 +29,13 @@ const fetchGist = (url: string): TO.TaskOption> =>
)
export default defineImporter({
- name: "import.gist",
+ name: "import.from_gist",
icon: "github",
steps: [
step({
stepName: "URL_IMPORT",
metadata: {
+ caption: "import.from_gist_description",
placeholder: "import.gist_url",
},
}),
diff --git a/packages/hoppscotch-app/helpers/import-export/import/hopp.ts b/packages/hoppscotch-app/helpers/import-export/import/hopp.ts
index 266c7f2b3..14f831a53 100644
--- a/packages/hoppscotch-app/helpers/import-export/import/hopp.ts
+++ b/packages/hoppscotch-app/helpers/import-export/import/hopp.ts
@@ -6,12 +6,13 @@ import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "."
import { translateToNewRESTCollection } from "~/newstore/collections"
export default defineImporter({
- name: "import.json",
+ name: "import.from_json",
icon: "folder-plus",
steps: [
step({
stepName: "FILE_IMPORT",
metadata: {
+ caption: "import.from_json_description",
acceptedFileTypes: "application/json",
},
}),
diff --git a/packages/hoppscotch-app/helpers/import-export/import/importers.ts b/packages/hoppscotch-app/helpers/import-export/import/importers.ts
index 41c281ab2..559a247d2 100644
--- a/packages/hoppscotch-app/helpers/import-export/import/importers.ts
+++ b/packages/hoppscotch-app/helpers/import-export/import/importers.ts
@@ -3,6 +3,7 @@ import OpenAPIImporter from "./openapi"
import PostmanImporter from "./postman"
import InsomniaImporter from "./insomnia"
import GistImporter from "./gist"
+import MyCollectionsImporter from "./myCollections"
export const RESTCollectionImporters = [
HoppRESTCollImporter,
@@ -10,4 +11,5 @@ export const RESTCollectionImporters = [
PostmanImporter,
InsomniaImporter,
GistImporter,
+ MyCollectionsImporter,
] as const
diff --git a/packages/hoppscotch-app/helpers/import-export/import/index.ts b/packages/hoppscotch-app/helpers/import-export/import/index.ts
index f01ef34b1..75eebddcf 100644
--- a/packages/hoppscotch-app/helpers/import-export/import/index.ts
+++ b/packages/hoppscotch-app/helpers/import-export/import/index.ts
@@ -27,6 +27,11 @@ type HoppImporterDefintion = {
*/
icon: string
+ /**
+ * Identifier for the importer
+ */
+ applicableTo?: Array<"team-collections" | "my-collections">
+
/**
* The importer function, It is a Promise because its supposed to be loaded in lazily (dynamic imports ?)
*/
@@ -45,6 +50,7 @@ export const defineImporter = (input: {
name: string
icon: string
importer: HoppImporter
+ applicableTo?: Array<"team-collections" | "my-collections">
steps: StepType
}) => {
return >{
diff --git a/packages/hoppscotch-app/helpers/import-export/import/insomnia.ts b/packages/hoppscotch-app/helpers/import-export/import/insomnia.ts
index 9c352640b..78fc12e25 100644
--- a/packages/hoppscotch-app/helpers/import-export/import/insomnia.ts
+++ b/packages/hoppscotch-app/helpers/import-export/import/insomnia.ts
@@ -215,6 +215,7 @@ export default defineImporter({
step({
stepName: "FILE_IMPORT",
metadata: {
+ caption: "import.from_insomnia_description",
acceptedFileTypes: ".json, .yaml",
},
}),
diff --git a/packages/hoppscotch-app/helpers/import-export/import/myCollections.ts b/packages/hoppscotch-app/helpers/import-export/import/myCollections.ts
new file mode 100644
index 000000000..0c8942d31
--- /dev/null
+++ b/packages/hoppscotch-app/helpers/import-export/import/myCollections.ts
@@ -0,0 +1,21 @@
+import * as TE from "fp-ts/TaskEither"
+import * as A from "fp-ts/Array"
+import { pipe } from "fp-ts/function"
+import { step } from "../steps"
+import { defineImporter } from "."
+import { getRESTCollection } from "~/newstore/collections"
+
+export default defineImporter({
+ name: "import.from_my_collections",
+ icon: "user",
+ applicableTo: ["team-collections"],
+ steps: [
+ step({
+ stepName: "TARGET_MY_COLLECTION",
+ metadata: {
+ caption: "import.from_my_collections_description",
+ },
+ }),
+ ] as const,
+ importer: ([content]) => pipe(content, getRESTCollection, A.of, TE.of),
+})
diff --git a/packages/hoppscotch-app/helpers/import-export/import/openapi.ts b/packages/hoppscotch-app/helpers/import-export/import/openapi.ts
index 52cf127fa..ac3bc4f5d 100644
--- a/packages/hoppscotch-app/helpers/import-export/import/openapi.ts
+++ b/packages/hoppscotch-app/helpers/import-export/import/openapi.ts
@@ -591,6 +591,7 @@ export default defineImporter({
step({
stepName: "FILE_IMPORT",
metadata: {
+ caption: "import.from_openapi_description",
acceptedFileTypes: ".json, .yaml, .yml",
},
}),
diff --git a/packages/hoppscotch-app/helpers/import-export/import/postman.ts b/packages/hoppscotch-app/helpers/import-export/import/postman.ts
index 24a7ee1d9..7ac6322b1 100644
--- a/packages/hoppscotch-app/helpers/import-export/import/postman.ts
+++ b/packages/hoppscotch-app/helpers/import-export/import/postman.ts
@@ -236,6 +236,7 @@ export default defineImporter({
step({
stepName: "FILE_IMPORT",
metadata: {
+ caption: "import.from_postman_description",
acceptedFileTypes: ".json",
},
}),
diff --git a/packages/hoppscotch-app/helpers/import-export/steps.ts b/packages/hoppscotch-app/helpers/import-export/steps.ts
index 6d39bdae1..64c967dde 100644
--- a/packages/hoppscotch-app/helpers/import-export/steps.ts
+++ b/packages/hoppscotch-app/helpers/import-export/steps.ts
@@ -6,21 +6,27 @@ export type StepDefinition = {
FILE_IMPORT: {
returnType: string
metadata: {
+ caption: string
acceptedFileTypes: string
}
} // String content of the file
TARGET_MY_COLLECTION: {
returnType: number
- metadata: never
+ metadata: {
+ caption: string
+ }
} // folderPath
URL_IMPORT: {
returnType: string
metadata: {
+ caption: string
placeholder: string
}
} // String content of the url
}
+export type StepReturnValue = StepDefinition[keyof StepDefinition]["returnType"]
+
/**
* Defines what the data structure of a step
*/
diff --git a/packages/hoppscotch-app/locales/en.json b/packages/hoppscotch-app/locales/en.json
index cc858b72c..9f99b9d13 100644
--- a/packages/hoppscotch-app/locales/en.json
+++ b/packages/hoppscotch-app/locales/en.json
@@ -229,15 +229,20 @@
"collections": "Import collections",
"curl": "Import cURL",
"failed": "Error while importing: format not recognized",
- "gist": "Import from Gist",
- "gist_description": "Import a Gist",
+ "from_gist": "Import from Gist",
+ "from_gist_description": "Import from Gist URL",
"from_insomnia": "Import from Insomnia",
+ "from_insomnia_description": "Import from Insomnia collection",
"from_my_collections": "Import from My Collections",
+ "from_my_collections_description": "Import from My Collections file",
"from_openapi": "Import from OpenAPI",
+ "from_openapi_description": "Import from OpenAPI specification file (YML/JSON)",
"from_postman": "Import from Postman",
+ "from_postman_description": "Import from Postman collection",
"from_url": "Import from URL",
+ "from_json": "Import from Hoppscotch",
+ "from_json_description": "Import from Hoppscotch collection file",
"gist_url": "Enter Gist URL",
- "json": "Import from file",
"json_description": "Import collections from a Hoppscotch Collections JSON file",
"title": "Import"
},
diff --git a/packages/hoppscotch-app/newstore/collections.ts b/packages/hoppscotch-app/newstore/collections.ts
index 5147cd8b1..cb1fe6009 100644
--- a/packages/hoppscotch-app/newstore/collections.ts
+++ b/packages/hoppscotch-app/newstore/collections.ts
@@ -694,6 +694,10 @@ export function removeRESTCollection(collectionIndex: number) {
})
}
+export function getRESTCollection(collectionIndex: number) {
+ return restCollectionStore.value.state[collectionIndex]
+}
+
export function editRESTCollection(
collectionIndex: number,
collection: Collection