feat: ui for new importer

This commit is contained in:
liyasthomas
2022-01-14 20:40:54 +05:30
parent 67934fd19a
commit e323b4355e
12 changed files with 116 additions and 50 deletions

View File

@@ -29,12 +29,13 @@ const fetchGist = (url: string): TO.TaskOption<Collection<HoppRESTRequest>> =>
)
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",
},
}),

View File

@@ -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",
},
}),

View File

@@ -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

View File

@@ -27,6 +27,11 @@ type HoppImporterDefintion<T, Y, E> = {
*/
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 = <ReturnType, StepType, Errors>(input: {
name: string
icon: string
importer: HoppImporter<ReturnType, StepType, Errors>
applicableTo?: Array<"team-collections" | "my-collections">
steps: StepType
}) => {
return <HoppImporterDefintion<ReturnType, StepType, Errors>>{

View File

@@ -215,6 +215,7 @@ export default defineImporter({
step({
stepName: "FILE_IMPORT",
metadata: {
caption: "import.from_insomnia_description",
acceptedFileTypes: ".json, .yaml",
},
}),

View File

@@ -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),
})

View File

@@ -591,6 +591,7 @@ export default defineImporter({
step({
stepName: "FILE_IMPORT",
metadata: {
caption: "import.from_openapi_description",
acceptedFileTypes: ".json, .yaml, .yml",
},
}),

View File

@@ -236,6 +236,7 @@ export default defineImporter({
step({
stepName: "FILE_IMPORT",
metadata: {
caption: "import.from_postman_description",
acceptedFileTypes: ".json",
},
}),

View File

@@ -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
*/