diff --git a/package-lock.json b/package-lock.json index c2229628..a7f0faa7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16776,7 +16776,7 @@ }, "packages/bruno-cli": { "name": "@usebruno/cli", - "version": "0.11.0", + "version": "0.12.0", "license": "MIT", "dependencies": { "@usebruno/js": "0.6.0", @@ -16822,7 +16822,7 @@ }, "packages/bruno-electron": { "name": "bruno", - "version": "v0.19.0", + "version": "v0.20.0", "dependencies": { "@usebruno/js": "0.6.0", "@usebruno/lang": "0.5.0", @@ -20107,7 +20107,7 @@ "axios": "^1.5.1", "chai": "^4.3.7", "chalk": "^3.0.0", - "decomment": "*", + "decomment": "^0.9.5", "form-data": "^4.0.0", "fs-extra": "^10.1.0", "handlebars": "^4.7.8", diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js index 509a529b..3b16d99c 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js @@ -9,7 +9,7 @@ import { findEnvironmentInCollection } from 'utils/collections'; const interpolateUrl = ({ url, envVars, collectionVariables, processEnvVars }) => { if (!url || !url.length || typeof url !== 'string') { - return str; + return; } const template = handlebars.compile(url, { noEscape: true }); @@ -74,9 +74,8 @@ const languages = [ ]; const GenerateCodeItem = ({ collection, item, onClose }) => { - const url = get(item, 'request.url') || ''; + const url = get(item, 'draft.request.url') !== undefined ? get(item, 'draft.request.url') : get(item, 'request.url'); const environment = findEnvironmentInCollection(collection, collection.activeEnvironmentUid); - let envVars = {}; if (environment) { const vars = get(environment, 'variables', []); @@ -92,7 +91,6 @@ const GenerateCodeItem = ({ collection, item, onClose }) => { collectionVariables: collection.collectionVariables, processEnvVars: collection.processEnvVariables }); - const [selectedLanguage, setSelectedLanguage] = useState(languages[0]); return ( @@ -121,10 +119,16 @@ const GenerateCodeItem = ({ collection, item, onClose }) => { language={selectedLanguage} item={{ ...item, - request: { - ...item.request, - url: interpolatedUrl - } + request: + item.request.url !== '' + ? { + ...item.request, + url: interpolatedUrl + } + : { + ...item.draft.request, + url: interpolatedUrl + } }} /> ) : ( diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js index a08b4fe1..f0cc8d36 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js @@ -21,7 +21,7 @@ import { isItemARequest, isItemAFolder, itemIsOpenedInTabs } from 'utils/tabs'; import { doesRequestMatchSearchText, doesFolderHaveItemsMatchSearchText } from 'utils/collections/search'; import { getDefaultRequestPaneTab } from 'utils/collections'; import { hideHomePage } from 'providers/ReduxStore/slices/app'; - +import toast from 'react-hot-toast'; import StyledWrapper from './StyledWrapper'; const CollectionItem = ({ item, collection, searchText }) => { @@ -148,7 +148,15 @@ const CollectionItem = ({ item, collection, searchText }) => { const sortFolderItems = (items = []) => { return items.sort((a, b) => a.name.localeCompare(b.name)); }; - + const handleGenerateCode = (e) => { + e.stopPropagation(); + dropdownTippyRef.current.hide(); + if (item.request.url !== '' || (item.draft?.request.url !== undefined && item.draft?.request.url !== '')) { + setGenerateCodeItemModalOpen(true); + } else { + toast.error('URL is required'); + } + }; const requestItems = sortRequestItems(filter(item.items, (i) => isItemARequest(i))); const folderItems = sortFolderItems(filter(item.items, (i) => isItemAFolder(i))); @@ -279,9 +287,7 @@ const CollectionItem = ({ item, collection, searchText }) => {
{ - e.stopPropagation(); - dropdownTippyRef.current.hide(); - setGenerateCodeItemModalOpen(true); + handleGenerateCode(e); }} > Generate Code