Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the ability to optionally update an existing collection on import #3615

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jGowgiel
Copy link

@jGowgiel jGowgiel commented Dec 7, 2024

Description

This PR adds a new confirmation dialog that allows for a collection import to "update" an existing collection, instead of having this operation always fail as it did before.

Currently, importing a collection that already has a matching directory causes an immediate error. Now, that error is caught and the user will be prompted if they would like to add to the existing collection:

image

If the user chooses to continue with the import, the existing import-collection logic will be run in a new updateExistingCollection mode, which creates necessary new directories but also traverses existing directories to add items that were parsed from the input file to existing directories.

When working with an OpenAPI spec that is frequently updated, this workflow allows users to add new endpoints from newer versions to an existing collection while preserving their environments and settings. This partially resolves the need detailed in #1354.

Future contributions could extend on this feature in a variety of ways:

  • Add additional parsing logic in the new method handleConfirmCollectionImportUpdate that could check for duplicate requests across the collection, regardless of folder location
    • Currently, if a user has reorganized their collection after importing, it is possible to end up with duplicates
  • Add additional options to the new dialog defined in packages/bruno-app/src/components/ConfirmCollectionImportUpdate that would allow users to "replace existing endpoints" as well as "add new endpoints."
    • Currently, existing endpoints are broadly ignored as pre-existing files. However, it would also be possible to overwrite existing endpoints entirely, perhaps to include new schema, or new arguments, if a user wants to do so.

I'm sure there are more ways that this could be built on in the future - this feature itself is fairly simple, but my hope is that it may spawn additional future contributions (from myself, or others) by breaking the assumption that "once a collection is imported, that directory can never be imported into again."

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
    • This PR introduces the ability to add new requests from an imported file to an existing collection, as well as the necessary UI for this feature
  • The pull request does not introduce any breaking changes
    • This PR only adds additional functionality, and does not change the behavior of the rest of the application
  • I have added screenshots or gifs to help explain the change if applicable.
    • See above for a screenshot of the new modal being added in this request
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Introduces a new modal with two simple options that sets a new
flag in the collection import flow. This will be connected in future
commits to trigger alternative import logic that will update an
existing collection instead of creating a net-new collection.
This enables an 'updateExistingCollection' flow which creates any missing
directories while leaving (and traversing) existing directories in place.

For example, if you are working from an OpenAPI file, and the structure
of that file is updated (e.g. by a third party) you can now re-import
that file in order to have any new endpoints be added to an existing
collection. Existing directories, endpoints, or organization are left
untouched.
Copy link
Author

@jGowgiel jGowgiel Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of the changes in this file are just the result of running the existing formatter for this project.

@@ -1140,11 +1150,14 @@ export const collectionAddEnvFileEvent = (payload) => (dispatch, getState) => {
});
};

export const importCollection = (collection, collectionLocation) => (dispatch, getState) => {
export const importCollection = (collection, collectionLocation, updateExistingCollection) => (dispatch, getState) => {
Copy link
Author

@jGowgiel jGowgiel Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was materially updated, not just formatted (with a new argument).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Work directly with or autoimport OpenAPI V3 spec files
1 participant