From fdf5bf34ed900a7148dd04dc15c33702480f5590 Mon Sep 17 00:00:00 2001 From: Akash K <57758277+amk-dev@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:42:09 +0530 Subject: [PATCH] feat: support import collections between workspaces (#4377) Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com> --- packages/hoppscotch-common/locales/en.json | 9 +- .../hoppscotch-common/src/components.d.ts | 1 + .../components/collections/ImportExport.vue | 36 +- .../importExport/ImportExportList.vue | 20 +- .../ImportExportSteps/AllCollectionImport.vue | 366 ++++++++++++++++++ .../src/helpers/teams/TeamCollection.ts | 21 + .../helpers/teams/TeamCollectionAdapter.ts | 2 +- .../src/helpers/teams/TeamRequest.ts | 21 + .../src/helpers/teams/TeamsSearch.service.ts | 48 +-- 9 files changed, 447 insertions(+), 77 deletions(-) create mode 100644 packages/hoppscotch-common/src/components/importExport/ImportExportSteps/AllCollectionImport.vue diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 312a8ff2d..c036de5b7 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -4,6 +4,9 @@ "autoscroll": "Autoscroll", "cancel": "Cancel", "choose_file": "Choose a file", + "choose_workspace": "Choose a workspace", + "choose_collection": "Choose a collection", + "select_workspace": "Select a workspace", "clear": "Clear", "clear_all": "Clear all", "clear_history": "Clear all History", @@ -460,6 +463,8 @@ "from_json_description": "Import from Hoppscotch collection file", "from_my_collections": "Import from Personal Collections", "from_my_collections_description": "Import from Personal Collections file", + "from_all_collections": "Import from Another Workspace", + "from_all_collections_description": "Import any collection from Another Workspace to the current workspace", "from_openapi": "Import from OpenAPI", "from_openapi_description": "Import from OpenAPI specification file (YML/JSON)", "from_postman": "Import from Postman", @@ -947,7 +952,9 @@ "subscribed_success": "Successfully subscribed to topic: {topic}", "unsubscribed_failed": "Failed to unsubscribe from topic: {topic}", "unsubscribed_success": "Successfully unsubscribed from topic: {topic}", - "waiting_send_request": "Waiting to send request" + "waiting_send_request": "Waiting to send request", + "loading_workspaces": "Loading workspaces", + "loading_collections_in_workspace": "Loading collections in workspace" }, "support": { "changelog": "Read more about latest releases", diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 06dfe2ae5..e51899b8d 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -186,6 +186,7 @@ declare module 'vue' { ImportExportBase: typeof import('./components/importExport/Base.vue')['default'] ImportExportImportExportList: typeof import('./components/importExport/ImportExportList.vue')['default'] ImportExportImportExportSourcesList: typeof import('./components/importExport/ImportExportSourcesList.vue')['default'] + ImportExportImportExportStepsAllCollectionImport: typeof import('./components/importExport/ImportExportSteps/AllCollectionImport.vue')['default'] ImportExportImportExportStepsFileImport: typeof import('./components/importExport/ImportExportSteps/FileImport.vue')['default'] ImportExportImportExportStepsMyCollectionImport: typeof import('./components/importExport/ImportExportSteps/MyCollectionImport.vue')['default'] ImportExportImportExportStepsUrlImport: typeof import('./components/importExport/ImportExportSteps/UrlImport.vue')['default'] diff --git a/packages/hoppscotch-common/src/components/collections/ImportExport.vue b/packages/hoppscotch-common/src/components/collections/ImportExport.vue index 4287fde90..80a67abc4 100644 --- a/packages/hoppscotch-common/src/components/collections/ImportExport.vue +++ b/packages/hoppscotch-common/src/components/collections/ImportExport.vue @@ -29,7 +29,7 @@ import { import { defineStep } from "~/composables/step-components" -import MyCollectionImport from "~/components/importExport/ImportExportSteps/MyCollectionImport.vue" +import AllCollectionImport from "~/components/importExport/ImportExportSteps/AllCollectionImport.vue" import { useI18n } from "~/composables/i18n" import { useToast } from "~/composables/toast" import { appendRESTCollections, restCollections$ } from "~/newstore/collections" @@ -61,7 +61,7 @@ const isPostmanImporterInProgress = ref(false) const isInsomniaImporterInProgress = ref(false) const isOpenAPIImporterInProgress = ref(false) const isRESTImporterInProgress = ref(false) -const isPersonalCollectionImporterInProgress = ref(false) +const isAllCollectionImporterInProgress = ref(false) const isHarImporterInProgress = ref(false) const isGistImporterInProgress = ref(false) @@ -209,19 +209,19 @@ const HoppRESTImporter: ImporterOrExporter = { }), } -const HoppMyCollectionImporter: ImporterOrExporter = { +const HoppAllCollectionImporter: ImporterOrExporter = { metadata: { - id: "hopp_my_collection", - name: "import.from_my_collections", - title: "import.from_my_collections_description", + id: "hopp_all_collection", + name: "import.from_all_collections", + title: "import.from_all_collections_description", icon: IconUser, - disabled: false, - applicableTo: ["team-workspace"], + disabled: !currentUser.value, + applicableTo: ["personal-workspace", "team-workspace"], }, - component: defineStep("my_collection_import", MyCollectionImport, () => ({ - loading: isPersonalCollectionImporterInProgress.value, - async onImportFromMyCollection(content) { - isPersonalCollectionImporterInProgress.value = true + component: defineStep("all_collection_import", AllCollectionImport, () => ({ + loading: isAllCollectionImporterInProgress.value, + async onImportCollection(content) { + isAllCollectionImporterInProgress.value = true await handleImportToStore([content]) @@ -232,7 +232,7 @@ const HoppMyCollectionImporter: ImporterOrExporter = { platform: "rest", }) - isPersonalCollectionImporterInProgress.value = false + isAllCollectionImporterInProgress.value = false }, })), } @@ -351,7 +351,7 @@ const HoppInsomniaImporter: ImporterOrExporter = { name: "import.from_insomnia", title: "import.from_insomnia_description", icon: IconInsomnia, - disabled: true, + disabled: false, applicableTo: ["personal-workspace", "team-workspace", "url-import"], }, component: FileSource({ @@ -387,7 +387,7 @@ const HoppGistImporter: ImporterOrExporter = { name: "import.from_gist", title: "import.from_gist_description", icon: IconGithub, - disabled: true, + disabled: false, applicableTo: ["personal-workspace", "team-workspace", "url-import"], }, component: GistSource({ @@ -596,7 +596,7 @@ const HARImporter: ImporterOrExporter = { const importerModules = computed(() => { const enabledImporters = [ HoppRESTImporter, - HoppMyCollectionImporter, + HoppAllCollectionImporter, HoppOpenAPIImporter, HoppPostmanImporter, HoppInsomniaImporter, @@ -607,6 +607,10 @@ const importerModules = computed(() => { const isTeams = props.collectionsType.type === "team-collections" return enabledImporters.filter((importer) => { + if (importer.metadata.disabled) { + return false + } + return isTeams ? importer.metadata.applicableTo.includes("team-workspace") : importer.metadata.applicableTo.includes("personal-workspace") diff --git a/packages/hoppscotch-common/src/components/importExport/ImportExportList.vue b/packages/hoppscotch-common/src/components/importExport/ImportExportList.vue index e26599b72..af99299b5 100644 --- a/packages/hoppscotch-common/src/components/importExport/ImportExportList.vue +++ b/packages/hoppscotch-common/src/components/importExport/ImportExportList.vue @@ -1,18 +1,6 @@