chore: Gist export flow updates

This commit is contained in:
jamesgeorge007
2023-12-18 23:00:14 +05:30
parent 5ad8f6c2ce
commit 2affb21d22
5 changed files with 71 additions and 20 deletions

View File

@@ -313,10 +313,12 @@
"export": { "export": {
"as_json": "Export as JSON", "as_json": "Export as JSON",
"create_secret_gist": "Create secret Gist", "create_secret_gist": "Create secret Gist",
"create_secret_gist_tooltip_text": "Export as secret Gist",
"failed": "Something went wrong while exporting", "failed": "Something went wrong while exporting",
"gist_created": "Gist created", "secret_gist_success": "Successfully exported as secret Gist",
"require_github": "Login with GitHub to create secret gist", "require_github": "Login with GitHub to create secret gist",
"title": "Export" "title": "Export",
"success": "Successfully exported"
}, },
"filter": { "filter": {
"all": "All", "all": "All",

View File

@@ -83,6 +83,8 @@ const currentUser = useReadonlyStream(
platform.auth.getCurrentUser() platform.auth.getCurrentUser()
) )
const myCollections = useReadonlyStream(restCollections$, [])
const showImportFailedError = () => { const showImportFailedError = () => {
toast.error(t("import.failed")) toast.error(t("import.failed"))
} }
@@ -469,11 +471,20 @@ const HoppGistCollectionsExporter: ImporterOrExporter = {
disabled: !currentUser.value disabled: !currentUser.value
? true ? true
: currentUser.value.provider !== "github.com", : currentUser.value.provider !== "github.com",
title: t("export.create_secret_gist"), title:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
currentUser?.value.provider === "github.com"
? "export.create_secret_gist_tooltip_text"
: "export.require_github",
applicableTo: ["personal-workspace", "team-workspace"], applicableTo: ["personal-workspace", "team-workspace"],
isLoading: isHoppGistCollectionExporterInProgress, isLoading: isHoppGistCollectionExporterInProgress,
}, },
action: async () => { action: async () => {
if (!myCollections.value.length) {
return toast.error(t("error.no_collections_to_export"))
}
isHoppGistCollectionExporterInProgress.value = true isHoppGistCollectionExporterInProgress.value = true
const collectionJSON = await getCollectionJSON() const collectionJSON = await getCollectionJSON()
@@ -486,13 +497,29 @@ const HoppGistCollectionsExporter: ImporterOrExporter = {
} }
if (E.isRight(collectionJSON)) { if (E.isRight(collectionJSON)) {
collectionsGistExporter(collectionJSON.right, accessToken) const res = await collectionsGistExporter(
collectionJSON.right,
accessToken
)
console.log(JSON.stringify(res, null, 2))
if (E.isLeft(res)) {
toast.error(t("export.failed"))
return
}
toast.success(t("export.secret_gist_success"))
platform.analytics?.logEvent({ platform.analytics?.logEvent({
type: "HOPP_EXPORT_COLLECTION", type: "HOPP_EXPORT_COLLECTION",
exporter: "gist", exporter: "gist",
platform: "rest", platform: "rest",
}) })
if (res.right) {
window.open(res.right, "_blank")
}
} }
isHoppGistCollectionExporterInProgress.value = false isHoppGistCollectionExporterInProgress.value = false
@@ -560,8 +587,6 @@ const selectedTeamID = computed(() => {
: undefined : undefined
}) })
const myCollections = useReadonlyStream(restCollections$, [])
const getCollectionJSON = async () => { const getCollectionJSON = async () => {
if ( if (
props.collectionsType.type === "team-collections" && props.collectionsType.type === "team-collections" &&

View File

@@ -15,6 +15,7 @@ import { HoppCollection } from "@hoppscotch/data"
import { ImporterOrExporter } from "~/components/importExport/types" import { ImporterOrExporter } from "~/components/importExport/types"
import { FileSource } from "~/helpers/import-export/import/import-sources/FileSource" import { FileSource } from "~/helpers/import-export/import/import-sources/FileSource"
import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource" import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource"
import { ref } from "vue"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
@@ -42,6 +43,10 @@ const currentUser = useReadonlyStream(
platform.auth.getCurrentUser() platform.auth.getCurrentUser()
) )
const gqlCollections = useReadonlyStream(graphqlCollections$, [])
const isGqlCollectionGistExportInProgress = ref(false)
const GqlCollectionsHoppImporter: ImporterOrExporter = { const GqlCollectionsHoppImporter: ImporterOrExporter = {
metadata: { metadata: {
id: "import.from_json", id: "import.from_json",
@@ -119,8 +124,6 @@ const GqlCollectionsGistImporter: ImporterOrExporter = {
}), }),
} }
const gqlCollections = useReadonlyStream(graphqlCollections$, [])
const GqlCollectionsHoppExporter: ImporterOrExporter = { const GqlCollectionsHoppExporter: ImporterOrExporter = {
metadata: { metadata: {
id: "export.as_json", id: "export.as_json",
@@ -159,25 +162,31 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
metadata: { metadata: {
id: "export.as_gist", id: "export.as_gist",
name: "export.create_secret_gist", name: "export.create_secret_gist",
title: !currentUser title:
? "export.require_github" // eslint-disable-next-line @typescript-eslint/ban-ts-comment
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore
// @ts-ignore currentUser?.value.provider === "github.com"
currentUser.provider !== "github.com" ? "export.create_secret_gist_tooltip_text"
? `export.require_github` : "export.require_github",
: "export.create_secret_gist",
icon: IconUser, icon: IconUser,
disabled: !currentUser.value disabled: !currentUser.value
? true ? true
: currentUser.value.provider !== "github.com", : currentUser.value.provider !== "github.com",
applicableTo: ["personal-workspace"], applicableTo: ["personal-workspace"],
isLoading: isGqlCollectionGistExportInProgress,
}, },
action: async () => { action: async () => {
if (!gqlCollections.value.length) {
return toast.error(t("error.no_collections_to_export"))
}
if (!currentUser.value) { if (!currentUser.value) {
toast.error(t("profile.no_permission")) toast.error(t("profile.no_permission"))
return return
} }
isGqlCollectionGistExportInProgress.value = true
const accessToken = currentUser.value?.accessToken const accessToken = currentUser.value?.accessToken
if (accessToken) { if (accessToken) {
@@ -191,7 +200,7 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
return return
} }
toast.success(t("export.success")) toast.success(t("export.secret_gist_success"))
platform.analytics?.logEvent({ platform.analytics?.logEvent({
type: "HOPP_EXPORT_COLLECTION", type: "HOPP_EXPORT_COLLECTION",
@@ -201,6 +210,8 @@ const GqlCollectionsGistExporter: ImporterOrExporter = {
platform.io.openExternalLink(res.right) platform.io.openExternalLink(res.right)
} }
isGqlCollectionGistExportInProgress.value = false
}, },
} }

View File

@@ -30,6 +30,7 @@ import { GQLError } from "~/helpers/backend/GQLClient"
import { CreateTeamEnvironmentMutation } from "~/helpers/backend/graphql" import { CreateTeamEnvironmentMutation } from "~/helpers/backend/graphql"
import { postmanEnvImporter } from "~/helpers/import-export/import/postmanEnv" import { postmanEnvImporter } from "~/helpers/import-export/import/postmanEnv"
import { insomniaEnvImporter } from "~/helpers/import-export/import/insomniaEnv" import { insomniaEnvImporter } from "~/helpers/import-export/import/insomniaEnv"
import { ref } from "vue"
import IconFolderPlus from "~icons/lucide/folder-plus" import IconFolderPlus from "~icons/lucide/folder-plus"
import IconPostman from "~icons/hopp/postman" import IconPostman from "~icons/hopp/postman"
@@ -58,6 +59,8 @@ const currentUser = useReadonlyStream(
platform.auth.getCurrentUser() platform.auth.getCurrentUser()
) )
const isEnvironmentGistExportInProgress = ref(false)
const isTeamEnvironment = computed(() => { const isTeamEnvironment = computed(() => {
return props.environmentType === "TEAM_ENV" return props.environmentType === "TEAM_ENV"
}) })
@@ -262,21 +265,28 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
title: title:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
currentUser?.provider === "github.com" currentUser?.value.provider === "github.com"
? "export.create_secret_gist" ? "export.create_secret_gist_tooltip_text"
: "export.require_github", : "export.require_github",
icon: IconUser, icon: IconUser,
disabled: !currentUser.value disabled: !currentUser.value
? true ? true
: currentUser.value.provider !== "github.com", : currentUser.value.provider !== "github.com",
applicableTo: ["personal-workspace", "team-workspace"], applicableTo: ["personal-workspace", "team-workspace"],
isLoading: isEnvironmentGistExportInProgress,
}, },
action: async () => { action: async () => {
if (!environmentJson.value.length) {
return toast.error(t("error.no_environments_to_export"))
}
if (!currentUser.value) { if (!currentUser.value) {
toast.error(t("profile.no_permission")) toast.error(t("profile.no_permission"))
return return
} }
isEnvironmentGistExportInProgress.value = true
const accessToken = currentUser.value?.accessToken const accessToken = currentUser.value?.accessToken
if (accessToken) { if (accessToken) {
@@ -287,10 +297,11 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
if (E.isLeft(res)) { if (E.isLeft(res)) {
toast.error(t("export.failed")) toast.error(t("export.failed"))
isEnvironmentGistExportInProgress.value = false
return return
} }
toast.success(t("export.success")) toast.success(t("export.secret_gist_success"))
platform.analytics?.logEvent({ platform.analytics?.logEvent({
type: "HOPP_EXPORT_ENVIRONMENT", type: "HOPP_EXPORT_ENVIRONMENT",
@@ -299,6 +310,8 @@ const HoppEnvironmentsGistExporter: ImporterOrExporter = {
platform.io.openExternalLink(res.right) platform.io.openExternalLink(res.right)
} }
isEnvironmentGistExportInProgress.value = false
}, },
} }

View File

@@ -18,5 +18,5 @@ export const collectionsGistExporter = async (
if (E.isLeft(res)) { if (E.isLeft(res)) {
return E.left(res.left) return E.left(res.left)
} }
return E.right(true) return E.right(res.right.data.html_url as string)
} }