feat: add loading state for import actions (#4217)

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
HelixY2J
2024-09-23 17:00:48 +05:30
committed by GitHub
parent e9e1366cc8
commit 1701961335
9 changed files with 196 additions and 95 deletions

View File

@@ -60,6 +60,11 @@ const currentUser = useReadonlyStream(
platform.auth.getCurrentUser()
)
const isPostmanImporterInProgress = ref(false)
const isInsomniaImporterInProgress = ref(false)
const isRESTImporterInProgress = ref(false)
const isGistImporterInProgress = ref(false)
const isEnvironmentGistExportInProgress = ref(false)
const isTeamEnvironment = computed(() => {
@@ -91,23 +96,27 @@ const HoppEnvironmentsImport: ImporterOrExporter = {
acceptedFileTypes: "application/json",
caption: "import.hoppscotch_environment_description",
onImportFromFile: async (environments) => {
isRESTImporterInProgress.value = true
const res = await hoppEnvImporter(environments)()
if (E.isLeft(res)) {
if (E.isRight(res)) {
await handleImportToStore(res.right)
platform.analytics?.logEvent({
type: "HOPP_IMPORT_ENVIRONMENT",
platform: "rest",
workspaceType: isTeamEnvironment.value ? "team" : "personal",
})
emit("hide-modal")
} else {
showImportFailedError()
return
}
handleImportToStore(res.right)
platform.analytics?.logEvent({
type: "HOPP_IMPORT_ENVIRONMENT",
platform: "rest",
workspaceType: workspaceType.value,
})
emit("hide-modal")
isRESTImporterInProgress.value = false
},
isLoading: isRESTImporterInProgress,
}),
}
@@ -124,23 +133,27 @@ const PostmanEnvironmentsImport: ImporterOrExporter = {
acceptedFileTypes: "application/json",
caption: "import.postman_environment_description",
onImportFromFile: async (environments) => {
isPostmanImporterInProgress.value = true
const res = await postmanEnvImporter(environments)()
if (E.isLeft(res)) {
if (E.isRight(res)) {
await handleImportToStore(res.right)
platform.analytics?.logEvent({
type: "HOPP_IMPORT_ENVIRONMENT",
platform: "rest",
workspaceType: isTeamEnvironment.value ? "team" : "personal",
})
emit("hide-modal")
} else {
showImportFailedError()
return
}
handleImportToStore(res.right)
platform.analytics?.logEvent({
type: "HOPP_IMPORT_ENVIRONMENT",
platform: "rest",
workspaceType: workspaceType.value,
})
emit("hide-modal")
isPostmanImporterInProgress.value = false
},
isLoading: isPostmanImporterInProgress,
}),
}
@@ -157,30 +170,34 @@ const insomniaEnvironmentsImport: ImporterOrExporter = {
acceptedFileTypes: "application/json",
caption: "import.insomnia_environment_description",
onImportFromFile: async (environments) => {
isInsomniaImporterInProgress.value = true
const res = await insomniaEnvImporter(environments)()
if (E.isLeft(res)) {
if (E.isRight(res)) {
const globalEnvs = res.right.filter(
(env) => env.name === "Base Environment"
)
const otherEnvs = res.right.filter(
(env) => env.name !== "Base Environment"
)
await handleImportToStore(otherEnvs, globalEnvs)
platform.analytics?.logEvent({
type: "HOPP_IMPORT_ENVIRONMENT",
platform: "rest",
workspaceType: isTeamEnvironment.value ? "team" : "personal",
})
emit("hide-modal")
} else {
showImportFailedError()
return
}
const globalEnvs = res.right.filter(
(env) => env.name === "Base Environment"
)
const otherEnvs = res.right.filter(
(env) => env.name !== "Base Environment"
)
handleImportToStore(otherEnvs, globalEnvs)
platform.analytics?.logEvent({
type: "HOPP_IMPORT_ENVIRONMENT",
platform: "rest",
workspaceType: workspaceType.value,
})
emit("hide-modal")
isInsomniaImporterInProgress.value = false
},
isLoading: isInsomniaImporterInProgress,
}),
}
@@ -201,21 +218,26 @@ const EnvironmentsImportFromGIST: ImporterOrExporter = {
return
}
isGistImporterInProgress.value = true
const res = await hoppEnvImporter(environments.right)()
if (E.isLeft(res)) {
if (E.isRight(res)) {
await handleImportToStore(res.right)
platform.analytics?.logEvent({
type: "HOPP_IMPORT_ENVIRONMENT",
platform: "rest",
workspaceType: isTeamEnvironment.value ? "team" : "personal",
})
emit("hide-modal")
} else {
showImportFailedError()
return
}
handleImportToStore(res.right)
platform.analytics?.logEvent({
type: "HOPP_IMPORT_ENVIRONMENT",
platform: "rest",
workspaceType: workspaceType.value,
})
emit("hide-modal")
isGistImporterInProgress.value = false
},
isLoading: isGistImporterInProgress,
}),
}