feat: ui for new importer
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
<i class="material-icons">check_circle</i>
|
<i class="material-icons">check_circle</i>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
{{ t("import.json_description") }}
|
{{ t(`${step.metadata.caption}`) }}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="flex flex-col ml-10">
|
<p class="flex flex-col ml-10">
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<i class="material-icons">check_circle</i>
|
<i class="material-icons">check_circle</i>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
{{ t("import.gist_description") }}
|
{{ t(`${step.metadata.caption}`) }}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="flex flex-col ml-10">
|
<p class="flex flex-col ml-10">
|
||||||
@@ -77,23 +77,13 @@
|
|||||||
>
|
>
|
||||||
<div class="select-wrapper">
|
<div class="select-wrapper">
|
||||||
<select
|
<select
|
||||||
|
v-model="mySelectedCollectionID"
|
||||||
type="text"
|
type="text"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
class="select"
|
class="select"
|
||||||
autofocus
|
autofocus
|
||||||
@change="
|
|
||||||
($event) => {
|
|
||||||
mySelectedCollectionID = $event.target.value
|
|
||||||
}
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<option
|
<option :key="undefined" :value="undefined" disabled selected>
|
||||||
:key="undefined"
|
|
||||||
:value="undefined"
|
|
||||||
hidden
|
|
||||||
disabled
|
|
||||||
selected
|
|
||||||
>
|
|
||||||
{{ t("collection.select") }}
|
{{ t("collection.select") }}
|
||||||
</option>
|
</option>
|
||||||
<option
|
<option
|
||||||
@@ -112,6 +102,7 @@
|
|||||||
:label="t('import.title')"
|
:label="t('import.title')"
|
||||||
:disabled="enableImportButton"
|
:disabled="enableImportButton"
|
||||||
class="mx-2"
|
class="mx-2"
|
||||||
|
:loading="importingMyCollections"
|
||||||
@click.native="finishImport"
|
@click.native="finishImport"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -119,7 +110,7 @@
|
|||||||
<SmartExpand>
|
<SmartExpand>
|
||||||
<template #body>
|
<template #body>
|
||||||
<SmartItem
|
<SmartItem
|
||||||
v-for="(importer, index) in RESTCollectionImporters"
|
v-for="(importer, index) in importerModules"
|
||||||
:key="`importer-${index}`"
|
:key="`importer-${index}`"
|
||||||
:svg="importer.icon"
|
:svg="importer.icon"
|
||||||
:label="t(`${importer.name}`)"
|
:label="t(`${importer.name}`)"
|
||||||
@@ -182,8 +173,14 @@ import {
|
|||||||
} from "~/helpers/utils/composables"
|
} from "~/helpers/utils/composables"
|
||||||
import { currentUser$ } from "~/helpers/fb/auth"
|
import { currentUser$ } from "~/helpers/fb/auth"
|
||||||
import * as teamUtils from "~/helpers/teams/utils"
|
import * as teamUtils from "~/helpers/teams/utils"
|
||||||
import { appendRESTCollections, restCollections$ } from "~/newstore/collections"
|
import {
|
||||||
|
appendRESTCollections,
|
||||||
|
Collection,
|
||||||
|
restCollections$,
|
||||||
|
} from "~/newstore/collections"
|
||||||
import { RESTCollectionImporters } from "~/helpers/import-export/import/importers"
|
import { RESTCollectionImporters } from "~/helpers/import-export/import/importers"
|
||||||
|
import { HoppRESTRequest } from "~/../hoppscotch-data/dist"
|
||||||
|
import { StepReturnValue } from "~/helpers/import-export/steps"
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
show: boolean
|
show: boolean
|
||||||
@@ -210,7 +207,7 @@ const currentUser = useReadonlyStream(currentUser$, null)
|
|||||||
|
|
||||||
// Template refs
|
// Template refs
|
||||||
const mode = ref("import_export")
|
const mode = ref("import_export")
|
||||||
const mySelectedCollectionID = ref(undefined)
|
const mySelectedCollectionID = ref<undefined | number>(undefined)
|
||||||
const collectionJson = ref("")
|
const collectionJson = ref("")
|
||||||
const inputChooseFileToImportFrom = ref<HTMLInputElement | any>()
|
const inputChooseFileToImportFrom = ref<HTMLInputElement | any>()
|
||||||
const inputChooseGistToImportFrom = ref<string>("")
|
const inputChooseGistToImportFrom = ref<string>("")
|
||||||
@@ -278,30 +275,39 @@ const hideModal = () => {
|
|||||||
emit("hide-modal")
|
emit("hide-modal")
|
||||||
}
|
}
|
||||||
|
|
||||||
const stepResults = ref<string[]>([])
|
const stepResults = ref<StepReturnValue[]>([])
|
||||||
|
|
||||||
// const importFromMyCollections = () => {
|
watch(mySelectedCollectionID, (newValue) => {
|
||||||
// if (props.collectionsType.type !== "team-collections") return
|
if (newValue === undefined) return
|
||||||
|
stepResults.value = []
|
||||||
|
stepResults.value.push(newValue)
|
||||||
|
})
|
||||||
|
|
||||||
// teamUtils
|
const importingMyCollections = ref(false)
|
||||||
// .importFromMyCollections(
|
|
||||||
// apolloClient,
|
const importToTeams = async (content: Collection<HoppRESTRequest>) => {
|
||||||
// mySelectedCollectionID.value,
|
importingMyCollections.value = true
|
||||||
// props.collectionsType.selectedTeam.id
|
if (props.collectionsType.type !== "team-collections") return
|
||||||
// )
|
await teamUtils
|
||||||
// .then((success) => {
|
.importFromJSON(
|
||||||
// if (success) {
|
apolloClient,
|
||||||
// fileImported()
|
content,
|
||||||
// emit("update-team-collections")
|
props.collectionsType.selectedTeam.id
|
||||||
// } else {
|
)
|
||||||
// failedImport()
|
.then((status) => {
|
||||||
// }
|
if (status) {
|
||||||
// })
|
emit("update-team-collections")
|
||||||
// .catch((e) => {
|
} else {
|
||||||
// console.error(e)
|
console.error(status)
|
||||||
// failedImport()
|
}
|
||||||
// })
|
})
|
||||||
// }
|
.catch((e) => {
|
||||||
|
console.error(e)
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
importingMyCollections.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const exportJSON = () => {
|
const exportJSON = () => {
|
||||||
getJSONCollection()
|
getJSONCollection()
|
||||||
@@ -323,13 +329,18 @@ const exportJSON = () => {
|
|||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const importerModules = computed(() =>
|
||||||
|
RESTCollectionImporters.filter(
|
||||||
|
(i) => i.applicableTo?.includes(props.collectionsType.type) ?? true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
const importerType = ref<number | null>(null)
|
const importerType = ref<number | null>(null)
|
||||||
|
|
||||||
const importerModule = computed(() =>
|
const importerModule = computed(() =>
|
||||||
importerType.value !== null
|
importerType.value !== null ? importerModules.value[importerType.value] : null
|
||||||
? RESTCollectionImporters[importerType.value]
|
|
||||||
: null
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const importerSteps = computed(() => importerModule.value?.steps ?? null)
|
const importerSteps = computed(() => importerModule.value?.steps ?? null)
|
||||||
|
|
||||||
const finishImport = async () => {
|
const finishImport = async () => {
|
||||||
@@ -343,8 +354,13 @@ const importerAction = async (stepResults: any[]) => {
|
|||||||
failedImport()
|
failedImport()
|
||||||
console.error("error", result.left)
|
console.error("error", result.left)
|
||||||
} else if (E.isRight(result)) {
|
} else if (E.isRight(result)) {
|
||||||
appendRESTCollections(result.right)
|
if (props.collectionsType.type === "team-collections") {
|
||||||
fileImported()
|
importToTeams(result.right)
|
||||||
|
fileImported()
|
||||||
|
} else {
|
||||||
|
appendRESTCollections(result.right)
|
||||||
|
fileImported()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,6 +378,7 @@ watch(inputChooseGistToImportFrom, (v) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const onFileChange = () => {
|
const onFileChange = () => {
|
||||||
|
stepResults.value = []
|
||||||
if (!inputChooseFileToImportFrom.value[0]) {
|
if (!inputChooseFileToImportFrom.value[0]) {
|
||||||
hasFile.value = false
|
hasFile.value = false
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -29,12 +29,13 @@ const fetchGist = (url: string): TO.TaskOption<Collection<HoppRESTRequest>> =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
export default defineImporter({
|
export default defineImporter({
|
||||||
name: "import.gist",
|
name: "import.from_gist",
|
||||||
icon: "github",
|
icon: "github",
|
||||||
steps: [
|
steps: [
|
||||||
step({
|
step({
|
||||||
stepName: "URL_IMPORT",
|
stepName: "URL_IMPORT",
|
||||||
metadata: {
|
metadata: {
|
||||||
|
caption: "import.from_gist_description",
|
||||||
placeholder: "import.gist_url",
|
placeholder: "import.gist_url",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import { defineImporter, IMPORTER_INVALID_FILE_FORMAT } from "."
|
|||||||
import { translateToNewRESTCollection } from "~/newstore/collections"
|
import { translateToNewRESTCollection } from "~/newstore/collections"
|
||||||
|
|
||||||
export default defineImporter({
|
export default defineImporter({
|
||||||
name: "import.json",
|
name: "import.from_json",
|
||||||
icon: "folder-plus",
|
icon: "folder-plus",
|
||||||
steps: [
|
steps: [
|
||||||
step({
|
step({
|
||||||
stepName: "FILE_IMPORT",
|
stepName: "FILE_IMPORT",
|
||||||
metadata: {
|
metadata: {
|
||||||
|
caption: "import.from_json_description",
|
||||||
acceptedFileTypes: "application/json",
|
acceptedFileTypes: "application/json",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import OpenAPIImporter from "./openapi"
|
|||||||
import PostmanImporter from "./postman"
|
import PostmanImporter from "./postman"
|
||||||
import InsomniaImporter from "./insomnia"
|
import InsomniaImporter from "./insomnia"
|
||||||
import GistImporter from "./gist"
|
import GistImporter from "./gist"
|
||||||
|
import MyCollectionsImporter from "./myCollections"
|
||||||
|
|
||||||
export const RESTCollectionImporters = [
|
export const RESTCollectionImporters = [
|
||||||
HoppRESTCollImporter,
|
HoppRESTCollImporter,
|
||||||
@@ -10,4 +11,5 @@ export const RESTCollectionImporters = [
|
|||||||
PostmanImporter,
|
PostmanImporter,
|
||||||
InsomniaImporter,
|
InsomniaImporter,
|
||||||
GistImporter,
|
GistImporter,
|
||||||
|
MyCollectionsImporter,
|
||||||
] as const
|
] as const
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ type HoppImporterDefintion<T, Y, E> = {
|
|||||||
*/
|
*/
|
||||||
icon: string
|
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 ?)
|
* The importer function, It is a Promise because its supposed to be loaded in lazily (dynamic imports ?)
|
||||||
*/
|
*/
|
||||||
@@ -45,6 +50,7 @@ export const defineImporter = <ReturnType, StepType, Errors>(input: {
|
|||||||
name: string
|
name: string
|
||||||
icon: string
|
icon: string
|
||||||
importer: HoppImporter<ReturnType, StepType, Errors>
|
importer: HoppImporter<ReturnType, StepType, Errors>
|
||||||
|
applicableTo?: Array<"team-collections" | "my-collections">
|
||||||
steps: StepType
|
steps: StepType
|
||||||
}) => {
|
}) => {
|
||||||
return <HoppImporterDefintion<ReturnType, StepType, Errors>>{
|
return <HoppImporterDefintion<ReturnType, StepType, Errors>>{
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ export default defineImporter({
|
|||||||
step({
|
step({
|
||||||
stepName: "FILE_IMPORT",
|
stepName: "FILE_IMPORT",
|
||||||
metadata: {
|
metadata: {
|
||||||
|
caption: "import.from_insomnia_description",
|
||||||
acceptedFileTypes: ".json, .yaml",
|
acceptedFileTypes: ".json, .yaml",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -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),
|
||||||
|
})
|
||||||
@@ -591,6 +591,7 @@ export default defineImporter({
|
|||||||
step({
|
step({
|
||||||
stepName: "FILE_IMPORT",
|
stepName: "FILE_IMPORT",
|
||||||
metadata: {
|
metadata: {
|
||||||
|
caption: "import.from_openapi_description",
|
||||||
acceptedFileTypes: ".json, .yaml, .yml",
|
acceptedFileTypes: ".json, .yaml, .yml",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ export default defineImporter({
|
|||||||
step({
|
step({
|
||||||
stepName: "FILE_IMPORT",
|
stepName: "FILE_IMPORT",
|
||||||
metadata: {
|
metadata: {
|
||||||
|
caption: "import.from_postman_description",
|
||||||
acceptedFileTypes: ".json",
|
acceptedFileTypes: ".json",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -6,21 +6,27 @@ export type StepDefinition = {
|
|||||||
FILE_IMPORT: {
|
FILE_IMPORT: {
|
||||||
returnType: string
|
returnType: string
|
||||||
metadata: {
|
metadata: {
|
||||||
|
caption: string
|
||||||
acceptedFileTypes: string
|
acceptedFileTypes: string
|
||||||
}
|
}
|
||||||
} // String content of the file
|
} // String content of the file
|
||||||
TARGET_MY_COLLECTION: {
|
TARGET_MY_COLLECTION: {
|
||||||
returnType: number
|
returnType: number
|
||||||
metadata: never
|
metadata: {
|
||||||
|
caption: string
|
||||||
|
}
|
||||||
} // folderPath
|
} // folderPath
|
||||||
URL_IMPORT: {
|
URL_IMPORT: {
|
||||||
returnType: string
|
returnType: string
|
||||||
metadata: {
|
metadata: {
|
||||||
|
caption: string
|
||||||
placeholder: string
|
placeholder: string
|
||||||
}
|
}
|
||||||
} // String content of the url
|
} // String content of the url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type StepReturnValue = StepDefinition[keyof StepDefinition]["returnType"]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines what the data structure of a step
|
* Defines what the data structure of a step
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -229,15 +229,20 @@
|
|||||||
"collections": "Import collections",
|
"collections": "Import collections",
|
||||||
"curl": "Import cURL",
|
"curl": "Import cURL",
|
||||||
"failed": "Error while importing: format not recognized",
|
"failed": "Error while importing: format not recognized",
|
||||||
"gist": "Import from Gist",
|
"from_gist": "Import from Gist",
|
||||||
"gist_description": "Import a Gist",
|
"from_gist_description": "Import from Gist URL",
|
||||||
"from_insomnia": "Import from Insomnia",
|
"from_insomnia": "Import from Insomnia",
|
||||||
|
"from_insomnia_description": "Import from Insomnia collection",
|
||||||
"from_my_collections": "Import from My Collections",
|
"from_my_collections": "Import from My Collections",
|
||||||
|
"from_my_collections_description": "Import from My Collections file",
|
||||||
"from_openapi": "Import from OpenAPI",
|
"from_openapi": "Import from OpenAPI",
|
||||||
|
"from_openapi_description": "Import from OpenAPI specification file (YML/JSON)",
|
||||||
"from_postman": "Import from Postman",
|
"from_postman": "Import from Postman",
|
||||||
|
"from_postman_description": "Import from Postman collection",
|
||||||
"from_url": "Import from URL",
|
"from_url": "Import from URL",
|
||||||
|
"from_json": "Import from Hoppscotch",
|
||||||
|
"from_json_description": "Import from Hoppscotch collection file",
|
||||||
"gist_url": "Enter Gist URL",
|
"gist_url": "Enter Gist URL",
|
||||||
"json": "Import from file",
|
|
||||||
"json_description": "Import collections from a Hoppscotch Collections JSON file",
|
"json_description": "Import collections from a Hoppscotch Collections JSON file",
|
||||||
"title": "Import"
|
"title": "Import"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -694,6 +694,10 @@ export function removeRESTCollection(collectionIndex: number) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRESTCollection(collectionIndex: number) {
|
||||||
|
return restCollectionStore.value.state[collectionIndex]
|
||||||
|
}
|
||||||
|
|
||||||
export function editRESTCollection(
|
export function editRESTCollection(
|
||||||
collectionIndex: number,
|
collectionIndex: number,
|
||||||
collection: Collection<HoppRESTRequest>
|
collection: Collection<HoppRESTRequest>
|
||||||
|
|||||||
Reference in New Issue
Block a user