mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-27 09:46:06 +03:00
[PR #3425] [MERGED] refactor: revamp the importers & exporters systems to be reused #4379
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#4379
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/3425
Author: @amk-dev
Created: 10/5/2023
Status: ✅ Merged
Merged: 12/6/2023
Merged by: @AndrewBastin
Base:
release/2023.12.0← Head:feat/env-importers📝 Commits (10+)
adcf478refactor: add import sources and components291602fchore: make base import export components3f2aaf7refactor: extract importing from my collections ui69a6061refactor: refactor collections import export82464cerefactor: refactor gql collections import exporte6358b3refactor: refactor environments import export656dd42chore: add i18n stringsddf2b2frefactor: add some missing exporters/importersd737f29refactor: refactor import from url using query params to use the new system19ef6dechore: remove old code no longer used📊 Changes
90 files changed (+2356 additions, -1849 deletions)
View changed files
📝
packages/hoppscotch-common/.eslintrc.js(+2 -0)📝
packages/hoppscotch-common/locales/en.json(+14 -2)📝
packages/hoppscotch-common/src/components/app/Inspection.vue(+1 -2)📝
packages/hoppscotch-common/src/components/collections/Collection.vue(+3 -4)📝
packages/hoppscotch-common/src/components/collections/ImportExport.vue(+519 -312)📝
packages/hoppscotch-common/src/components/collections/MyCollections.vue(+9 -11)📝
packages/hoppscotch-common/src/components/collections/Request.vue(+1 -2)📝
packages/hoppscotch-common/src/components/collections/SaveRequest.vue(+15 -17)📝
packages/hoppscotch-common/src/components/collections/TeamCollections.vue(+71 -76)📝
packages/hoppscotch-common/src/components/collections/graphql/Collection.vue(+1 -1)📝
packages/hoppscotch-common/src/components/collections/graphql/Folder.vue(+1 -1)📝
packages/hoppscotch-common/src/components/collections/graphql/ImportExport.vue(+175 -247)📝
packages/hoppscotch-common/src/components/collections/graphql/index.vue(+1 -1)📝
packages/hoppscotch-common/src/components/collections/index.vue(+54 -187)📝
packages/hoppscotch-common/src/components/environments/Add.vue(+8 -9)📝
packages/hoppscotch-common/src/components/environments/ImportExport.vue(+235 -346)📝
packages/hoppscotch-common/src/components/environments/Selector.vue(+36 -43)📝
packages/hoppscotch-common/src/components/environments/my/Details.vue(+5 -7)📝
packages/hoppscotch-common/src/components/environments/my/index.vue(+1 -1)📝
packages/hoppscotch-common/src/components/environments/teams/Details.vue(+7 -11)...and 70 more files
📄 Description
Closes HFE-237,HFE-204,HFE-217
Fixs #3303
Changes
revamp the importers and exporters systems to be reused
Previously, our import logic was shattered around a lot of places, and duplicated a lot of code. this PR adds a simple consistant way to add importers without leaking the implementation to different places.
Here are some details to help navigate the PR better.
We remove duplicating code by using
Import SourcesImport sources are the different ways we can import collections,environments etc.
For example, we can import from a file, from a url etc. the flow will look like this,
FileSource/UrlSource/GistSource gets the data from the file/url/gist->and that data is passed to hoppscotchImporter/insomniaImporter/openAPIImporteretc.Importers can say which sources they support, and our UI will render those options for the user to select.
Previously we were duplicating logic to import from a file / url / gist etc across different files. but now we have Import Sources abstractions that prevents duplication.
FileSourceUrlSourceGistSourceMaking Step By Step UI more flexible and maintainable with
useStepscomposable.Previously imports had 2 steps. one to select the importer and then to Select File/Url etc. this was implemented very imperatively/hardcoded with if statements. but now our requirements are more complex. for example, we need to support multiple sources for a single importer, which adds the need for 3 steps. doing it using the previous implementation was not an ideal solution. so we added a
useStepscomposable that allows us to define steps and navigate between them, easily.Previously, we were duplicating the step by step UI logic across different places. eg:
components/importexport/ImportExport.vueandcomponents/collections/ImportExport.vuehad the same logic. but they were duplicated. this PR adds adefineStepfunction that allows us to define a step and reuse it across different places. this makes the code more maintainable and flexible.a new function
defineStepis used to create a step that can be used in the step ui. a step is nothing but an component + its props, which can be rendered when needed. for example a simple flow looks like this.component: ImportExportList, props: { importers, exporters }, renders a list of importers and exporterscomponent: ImportExportSourcesList, props: { sources }, renders a list of sources for the selected importer/exportercomponent: FileImport, props: { acceptedFileTypes, caption, onImportFromFile }, renders a file input and emits the file content as a string. the selected importer will be executed with the file content.defineStepfunction takes an ID, the component to render for the Step. and its props/emits as parameters and it will create a step for you. the props/emits also gets nice typescript autocomplete as you would expect.Extract duplicated UI logic to
components/importexport/ImporterExport.vuecomponents/importexport/ImportExport.vuecomponent, that act as the base component with all the common UI, it takesimporterModulesandexporterModulesas props and renders the UI, also implements the step logic and handles navigating between the steps.How Importers for Collections, Environments are implemented using the common ImportExport component
We create a simple wrapper for the common
ImporterExport.vuecomponent.This wrapper defines the importerModules and exporterModules. and passes it to the
components/importexport/ImporterExport.vuecomponent.The importers and exporters will have type
ImporterOrExporter,See
ImporterOrExportertype.It has
supported_sourcesfor adding an array of supported sources. eg: FileSource, UrlSource ( eg: OpenAPI Importer supports UrlImport + File Import )It has
componentfor adding a single source/any component. eg: FileSource ( eg: All other importers other than OpenAPI uses FileSource only )It has
actionfor adding a function to execute without showing any UI. ( eg: Export as JSON uses this ).When the user selects an importer, if it has a
component, we show the component UI, else we render the list of sources. it is also possible to just execute a function without showing any UI usingaction. ( eg: export as json use this.)Here is an example importer defined,
Use the same system for collections, envs, graphql import&exports
Previously we had seperate components with inconsistant UIs for collections, envs, and gql imports/exports. since we use the same base components, now we have one consistant import/export UI all across the product.
Implement
hoppEnv+postmanEnvimports with zod validationPreviously we didn't have a seperate entry for importing hopp environment and postman environment. but the code was kinda handling both of these platforms. this PR adds seperate entries in the Import/Export list. also these importers have zod validation. ( the schema for postman is created from the previous implementation. this can be improved in the future. )
OpenAPI imports from URL + File
Previously we only had support for importing openAPI from a file. but now we have support for importing from a url too. ( note: this can be enabled for any of our importers, but we only enabled it for openAPI for now. )
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.