From 4f64c2d59b3e334eec7165d1cfc3cf92e884a26b Mon Sep 17 00:00:00 2001 From: lohit Date: Wed, 22 May 2024 21:32:24 +0530 Subject: [PATCH] fix: collection import (#2353) --- package-lock.json | 61 +------------------ .../Sidebar/ImportCollection/index.js | 16 ++--- .../src/components/Sidebar/TitleBar/index.js | 4 +- .../bruno-app/src/components/Welcome/index.js | 8 ++- .../src/utils/importers/bruno-collection.js | 2 +- .../utils/importers/insomnia-collection.js | 2 +- .../src/utils/importers/openapi-collection.js | 2 +- packages/bruno-electron/src/ipc/collection.js | 2 +- 8 files changed, 21 insertions(+), 76 deletions(-) diff --git a/package-lock.json b/package-lock.json index a9f140c6f..76cfe4c18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19729,7 +19729,7 @@ }, "packages/bruno-electron": { "name": "bruno", - "version": "v1.17.0", + "version": "v1.18.0", "dependencies": { "@aws-sdk/credential-providers": "3.525.0", "@usebruno/common": "0.1.0", @@ -20762,21 +20762,6 @@ "node": ">=14.0.0" } }, - "packages/bruno-electron/node_modules/ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", - "dependencies": { - "fast-deep-equal": "^3.1.3", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, "packages/bruno-electron/node_modules/fs-extra": { "version": "10.1.0", "license": "MIT", @@ -20789,11 +20774,6 @@ "node": ">=12" } }, - "packages/bruno-electron/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" - }, "packages/bruno-graphql-docs": { "name": "@usebruno/graphql-docs", "version": "0.1.0", @@ -27012,40 +26992,6 @@ "tslib": "^2.5.0" } }, - "@usebruno/js": { - "version": "https://registry.npmjs.org/@usebruno/js/-/js-0.11.0.tgz", - "integrity": "sha512-csbKAnFtLTupG46aMIahRWeNW8/rdDeaZPtvr4kIzcHDPNmKNowcFcrIR4VSpceh47Ltpm8n0sgzrHzw8P8Yjg==", - "requires": { - "@usebruno/query": "0.1.0", - "ajv": "^8.12.0", - "ajv-formats": "^2.1.1", - "atob": "^2.1.2", - "axios": "^1.5.1", - "btoa": "^1.2.1", - "chai": "^4.3.7", - "chai-string": "^1.5.0", - "crypto-js": "^4.1.1", - "handlebars": "^4.7.8", - "json-query": "^2.2.2", - "lodash": "^4.17.21", - "moment": "^2.29.4", - "nanoid": "3.3.4", - "node-fetch": "2.*", - "node-vault": "^0.10.2", - "uuid": "^9.0.0" - } - }, - "ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", - "requires": { - "fast-deep-equal": "^3.1.3", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" - } - }, "fs-extra": { "version": "10.1.0", "requires": { @@ -27053,11 +26999,6 @@ "jsonfile": "^6.0.1", "universalify": "^2.0.0" } - }, - "json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" } } }, diff --git a/packages/bruno-app/src/components/Sidebar/ImportCollection/index.js b/packages/bruno-app/src/components/Sidebar/ImportCollection/index.js index e7c8d24d6..d829baf10 100644 --- a/packages/bruno-app/src/components/Sidebar/ImportCollection/index.js +++ b/packages/bruno-app/src/components/Sidebar/ImportCollection/index.js @@ -17,32 +17,32 @@ const ImportCollection = ({ onClose, handleSubmit }) => { }); const handleImportBrunoCollection = () => { importBrunoCollection() - .then((collection) => { - handleSubmit(collection); + .then(({ collection }) => { + handleSubmit({ collection }); }) .catch((err) => toastError(err, 'Import collection failed')); }; const handleImportPostmanCollection = () => { importPostmanCollection(options) - .then((collection) => { - handleSubmit(collection); + .then(({ collection, translationLog }) => { + handleSubmit({ collection, translationLog }); }) .catch((err) => toastError(err, 'Postman Import collection failed')); }; const handleImportInsomniaCollection = () => { importInsomniaCollection() - .then((collection) => { - handleSubmit(collection); + .then(({ collection }) => { + handleSubmit({ collection }); }) .catch((err) => toastError(err, 'Insomnia Import collection failed')); }; const handleImportOpenapiCollection = () => { importOpenapiCollection() - .then((collection) => { - handleSubmit(collection); + .then(({ collection }) => { + handleSubmit({ collection }); }) .catch((err) => toastError(err, 'OpenAPI v3 Import collection failed')); }; diff --git a/packages/bruno-app/src/components/Sidebar/TitleBar/index.js b/packages/bruno-app/src/components/Sidebar/TitleBar/index.js index 719f23804..7962da07f 100644 --- a/packages/bruno-app/src/components/Sidebar/TitleBar/index.js +++ b/packages/bruno-app/src/components/Sidebar/TitleBar/index.js @@ -23,7 +23,9 @@ const TitleBar = () => { const handleImportCollection = ({ collection, translationLog }) => { setImportedCollection(collection); - setImportedTranslationLog(translationLog); + if (translationLog) { + setImportedTranslationLog(translationLog); + } setImportCollectionModalOpen(false); setImportCollectionLocationModalOpen(true); }; diff --git a/packages/bruno-app/src/components/Welcome/index.js b/packages/bruno-app/src/components/Welcome/index.js index a5ec0dffd..7f60377b6 100644 --- a/packages/bruno-app/src/components/Welcome/index.js +++ b/packages/bruno-app/src/components/Welcome/index.js @@ -24,9 +24,11 @@ const Welcome = () => { ); }; - const handleImportCollection = (collection, translationLog) => { + const handleImportCollection = ({ collection, translationLog }) => { setImportedCollection(collection); - setImportedTranslationLog(translationLog); + if (translationLog) { + setImportedTranslationLog(translationLog); + } setImportCollectionModalOpen(false); setImportCollectionLocationModalOpen(true); }; @@ -53,7 +55,7 @@ const Welcome = () => { /> ) : null} -
+
bruno
diff --git a/packages/bruno-app/src/utils/importers/bruno-collection.js b/packages/bruno-app/src/utils/importers/bruno-collection.js index 8baa1a9e4..d96802c39 100644 --- a/packages/bruno-app/src/utils/importers/bruno-collection.js +++ b/packages/bruno-app/src/utils/importers/bruno-collection.js @@ -32,7 +32,7 @@ const importCollection = () => { .then(updateUidsInCollection) .then(transformItemsInCollection) .then(validateSchema) - .then((collection) => resolve(collection)) + .then((collection) => resolve({ collection })) .catch((err) => { console.log(err); reject(new BrunoError('Import collection failed')); diff --git a/packages/bruno-app/src/utils/importers/insomnia-collection.js b/packages/bruno-app/src/utils/importers/insomnia-collection.js index d75de5575..0a38a85e5 100644 --- a/packages/bruno-app/src/utils/importers/insomnia-collection.js +++ b/packages/bruno-app/src/utils/importers/insomnia-collection.js @@ -237,7 +237,7 @@ const importCollection = () => { .then(transformItemsInCollection) .then(hydrateSeqInCollection) .then(validateSchema) - .then((collection) => resolve(collection)) + .then((collection) => resolve({ collection })) .catch((err) => { console.error(err); reject(new BrunoError('Import collection failed: ' + err.message)); diff --git a/packages/bruno-app/src/utils/importers/openapi-collection.js b/packages/bruno-app/src/utils/importers/openapi-collection.js index 099132d87..1900f6e47 100644 --- a/packages/bruno-app/src/utils/importers/openapi-collection.js +++ b/packages/bruno-app/src/utils/importers/openapi-collection.js @@ -378,7 +378,7 @@ const importCollection = () => { .then(transformItemsInCollection) .then(hydrateSeqInCollection) .then(validateSchema) - .then((collection) => resolve(collection)) + .then((collection) => resolve({ collection })) .catch((err) => { console.error(err); reject(new BrunoError('Import collection failed: ' + err.message)); diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index bdba1bc42..648f893e4 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -431,7 +431,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection // Handle items of type 'js' if (item.type === 'js') { const filePath = path.join(currentPath, `${item.name}.js`); - fs.writeFileSync(filePath, item.raw); + fs.writeFileSync(filePath, item.fileContent); } }); };