From 410eecc8848007e4c4c5130a7164d5398705bc8b Mon Sep 17 00:00:00 2001 From: Baptiste Poulain <64689165+bpoulaindev@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:10:31 +0100 Subject: [PATCH] feature(postman_tests_scripts): automatic tests and scripts translation from postman import (#1151) * feature(postman_tests_scripts): automatic tests and scripts translation from postman import --------- Co-authored-by: Baptiste POULAIN Co-authored-by: bpoulaindev --- .gitignore | 1 + packages/bruno-app/package.json | 1 + .../Sidebar/ImportCollection/index.js | 80 +++++++++++++++---- .../Sidebar/ImportCollectionLocation/index.js | 6 +- .../src/components/Sidebar/TitleBar/index.js | 2 +- .../bruno-app/src/components/Welcome/index.js | 4 +- .../bruno-app/src/providers/Theme/index.js | 11 +++ packages/bruno-app/src/styles/globals.css | 2 +- .../src/utils/importers/postman-collection.js | 33 +++++--- .../translators/postman_translation.js | 27 +++++++ packages/bruno-app/tailwind.config.js | 22 ++++- packages/bruno-electron/src/ipc/collection.js | 2 +- 12 files changed, 155 insertions(+), 36 deletions(-) create mode 100644 packages/bruno-app/src/utils/importers/translators/postman_translation.js diff --git a/.gitignore b/.gitignore index 07bdab410..0da494ea2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies +bun.lockb node_modules yarn.lock pnpm-lock.yaml diff --git a/packages/bruno-app/package.json b/packages/bruno-app/package.json index 79b93f908..179719995 100644 --- a/packages/bruno-app/package.json +++ b/packages/bruno-app/package.json @@ -17,6 +17,7 @@ "@fortawesome/react-fontawesome": "^0.1.16", "@reduxjs/toolkit": "^1.8.0", "@tabler/icons": "^1.46.0", + "@tailwindcss/forms": "^0.5.7", "@tippyjs/react": "^4.2.6", "@usebruno/common": "0.1.0", "@usebruno/graphql-docs": "0.1.0", diff --git a/packages/bruno-app/src/components/Sidebar/ImportCollection/index.js b/packages/bruno-app/src/components/Sidebar/ImportCollection/index.js index ecfc4183d..f95518e43 100644 --- a/packages/bruno-app/src/components/Sidebar/ImportCollection/index.js +++ b/packages/bruno-app/src/components/Sidebar/ImportCollection/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import importBrunoCollection from 'utils/importers/bruno-collection'; import importPostmanCollection from 'utils/importers/postman-collection'; import importInsomniaCollection from 'utils/importers/insomnia-collection'; @@ -7,6 +7,13 @@ import { toastError } from 'utils/common/error'; import Modal from 'components/Modal'; const ImportCollection = ({ onClose, handleSubmit }) => { + const [options, setOptions] = useState({ + enablePostmanTranslations: { + enabled: true, + label: 'Auto translate postman scripts', + subLabel: "When enabled, Bruno will try as best to translate the scripts from the imported collection to Bruno's format." + } + }) const handleImportBrunoCollection = () => { importBrunoCollection() .then((collection) => { @@ -16,7 +23,7 @@ const ImportCollection = ({ onClose, handleSubmit }) => { }; const handleImportPostmanCollection = () => { - importPostmanCollection() + importPostmanCollection(options) .then((collection) => { handleSubmit(collection); }) @@ -38,21 +45,66 @@ const ImportCollection = ({ onClose, handleSubmit }) => { }) .catch((err) => toastError(err, 'OpenAPI v3 Import collection failed')); }; - + const toggleOptions = (event, optionKey) => { + setOptions({ ...options, [optionKey]: { + ...options[optionKey], + enabled: !options[optionKey].enabled + } }); + }; + const CollectionButton = ({ children, className, onClick }) => { + return ( + + ) + } return ( -
-
- Bruno Collection +
+

Select the type of your existing collection :

+
+ + Bruno Collection + + + Postman Collection + + + Insomnia Collection + + + OpenAPI V3 Spec +
-
- Postman Collection -
-
- Insomnia Collection -
-
- OpenAPI V3 Spec +
+ {Object.entries(options || {}).map(([key, option]) => ( +
+
+ toggleOptions(e,key)} + className="h-3.5 w-3.5 rounded border-zinc-300 dark:ring-offset-zinc-800 bg-transparent text-indigo-600 dark:text-indigo-500 focus:ring-indigo-600 dark:focus:ring-indigo-500" + /> +
+
+ +

+ {option.subLabel} +

+
+
+ ))}
diff --git a/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js b/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js index 62a02bdd5..d8cd3dfd2 100644 --- a/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js +++ b/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js @@ -45,7 +45,11 @@ const ImportCollectionLocation = ({ onClose, handleSubmit, collectionName }) => const onSubmit = () => formik.handleSubmit(); return ( - +