diff --git a/packages/hoppscotch-common/src/components/collections/ImportExport.vue b/packages/hoppscotch-common/src/components/collections/ImportExport.vue index a1f6dc6ac..927df44ce 100644 --- a/packages/hoppscotch-common/src/components/collections/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/collections/ImportExport.vue @@ -19,29 +19,28 @@ import { UrlSource } from "~/helpers/import-export/import/import-sources/UrlSour import IconFile from "~icons/lucide/file" import { - hoppRESTImporter, hoppInsomniaImporter, - hoppPostmanImporter, - toTeamsImporter, hoppOpenAPIImporter, + hoppPostmanImporter, + hoppRESTImporter, + toTeamsImporter, } from "~/helpers/import-export/import/importers" import { defineStep } from "~/composables/step-components" +import MyCollectionImport from "~/components/importExport/ImportExportSteps/MyCollectionImport.vue" import { useI18n } from "~/composables/i18n" import { useToast } from "~/composables/toast" -import { restCollections$ } from "~/newstore/collections" -import MyCollectionImport from "~/components/importExport/ImportExportSteps/MyCollectionImport.vue" -import IconFolderPlus from "~icons/lucide/folder-plus" -import IconOpenAPI from "~icons/lucide/file" -import IconPostman from "~icons/hopp/postman" import IconInsomnia from "~icons/hopp/insomnia" +import IconPostman from "~icons/hopp/postman" +import IconOpenAPI from "~icons/lucide/file" +import IconFolderPlus from "~icons/lucide/folder-plus" import IconGithub from "~icons/lucide/github" import IconLink from "~icons/lucide/link" -import IconUser from "~icons/lucide/user" import { useReadonlyStream } from "~/composables/stream" +import IconUser from "~icons/lucide/user" import { getTeamCollectionJSON } from "~/helpers/backend/helpers" @@ -51,9 +50,9 @@ import { initializeDownloadFile } from "~/helpers/import-export/export" import { gistExporter } from "~/helpers/import-export/export/gist" import { teamCollectionsExporter } from "~/helpers/import-export/export/teamCollections" -import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource" -import { ImporterOrExporter } from "~/components/importExport/types" import { useService } from "dioc/vue" +import { ImporterOrExporter } from "~/components/importExport/types" +import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource" import { NewWorkspaceService } from "~/services/new-workspace" import { TeamWorkspace } from "~/services/workspace.service" @@ -83,8 +82,6 @@ const currentUser = useReadonlyStream( platform.auth.getCurrentUser() ) -const myCollections = useReadonlyStream(restCollections$, []) - const workspaceService = useService(NewWorkspaceService) const activeWorkspaceHandle = workspaceService.activeWorkspaceHandle @@ -96,7 +93,7 @@ const showImportFailedError = () => { const handleImportToStore = async (collections: HoppCollection[]) => { if (props.collectionsType.type === "my-collections") { if (!activeWorkspaceHandle.value) { - return + return E.left("INVALID_WORKSPACE_HANDLE") } const collectionHandleResult = await workspaceService.importRESTCollections( @@ -413,23 +410,25 @@ const HoppMyCollectionsExporter: ImporterOrExporter = { isLoading: isHoppMyCollectionExporterInProgress, }, action: async () => { - if (!myCollections.value.length) { - return toast.error(t("error.no_collections_to_export")) - } - if (!activeWorkspaceHandle.value) { - return + return toast.error("error.something_went_wrong") } isHoppMyCollectionExporterInProgress.value = true const result = await workspaceService.exportRESTCollections( - activeWorkspaceHandle.value, - myCollections.value + activeWorkspaceHandle.value ) + // INVALID_COLLECTION_HANDLE | NO_COLLECTIONS_TO_EXPORT if (E.isLeft(result)) { - // INVALID_WORKSPACE_HANDLE + isHoppMyCollectionExporterInProgress.value = false + + if (result.left.error === "NO_COLLECTIONS_TO_EXPORT") { + return toast.error(t("error.no_collections_to_export")) + } + + return toast.error(t("error.something_went_wrong")) } toast.success(t("state.download_started")) diff --git a/packages/hoppscotch-common/src/services/new-workspace/index.ts b/packages/hoppscotch-common/src/services/new-workspace/index.ts index 6e9a9fbb6..6c04d3e5f 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/index.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/index.ts @@ -439,8 +439,7 @@ export class NewWorkspaceService extends Service { } public async exportRESTCollections( - workspaceHandle: Handle, - collections: HoppCollection[] + workspaceHandle: Handle ): Promise< E.Either, void> > { @@ -458,10 +457,7 @@ export class NewWorkspaceService extends Service { return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" }) } - const result = await provider.exportRESTCollections( - workspaceHandle, - collections - ) + const result = await provider.exportRESTCollections(workspaceHandle) if (E.isLeft(result)) { return E.left({ type: "PROVIDER_ERROR", error: result.left }) diff --git a/packages/hoppscotch-common/src/services/new-workspace/provider.ts b/packages/hoppscotch-common/src/services/new-workspace/provider.ts index 6f34e8319..53684b5e3 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/provider.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/provider.ts @@ -1,21 +1,21 @@ -import { Ref } from "vue" import * as E from "fp-ts/Either" +import { Ref } from "vue" +import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { Handle } from "./handle" +import { + RESTCollectionChildrenView, + RESTCollectionJSONView, + RESTCollectionLevelAuthHeadersView, + RESTSearchResultsView, + RootRESTCollectionView, +} from "./view" import { Workspace, WorkspaceCollection, WorkspaceDecor, WorkspaceRequest, } from "./workspace" -import { - RESTCollectionLevelAuthHeadersView, - RESTCollectionChildrenView, - RootRESTCollectionView, - RESTSearchResultsView, - RESTCollectionJSONView, -} from "./view" -import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" export interface WorkspaceProvider { providerID: string @@ -83,8 +83,7 @@ export interface WorkspaceProvider { collections: HoppCollection[] ): Promise>> exportRESTCollections( - workspaceHandle: Handle, - collections: HoppCollection[] + workspaceHandle: Handle ): Promise> exportRESTCollection( collectionHandle: Handle, diff --git a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts index 9f5e0c949..45ccb9fc5 100644 --- a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts +++ b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts @@ -713,18 +713,26 @@ export class PersonalWorkspaceProviderService } public exportRESTCollections( - workspaceHandle: Handle, - collections: HoppCollection[] + workspaceHandle: Handle ): Promise> { const workspaceHandleRef = workspaceHandle.get() if ( !isValidWorkspaceHandle(workspaceHandleRef, this.providerID, "personal") ) { - return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const)) + return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const)) } - initializeDownloadFile(JSON.stringify(collections, null, 2), "Collections") + const collectionsToExport = this.restCollectionState.value.state + + if (collectionsToExport.length === 0) { + return Promise.resolve(E.left("NO_COLLECTIONS_TO_EXPORT" as const)) + } + + initializeDownloadFile( + JSON.stringify(collectionsToExport, null, 2), + `${workspaceHandleRef.value.data.workspaceID}-collections` + ) return Promise.resolve(E.right(undefined)) } @@ -1362,7 +1370,7 @@ export class PersonalWorkspaceProviderService if ( !isValidWorkspaceHandle(workspaceHandleRef, this.providerID, "personal") ) { - return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const)) + return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const)) } if (requestID === "") {