fix-/#419

This commit is contained in:
not-known-person 2023-10-06 22:00:20 -04:00
parent 65e448b1eb
commit 945f1eb74a
3 changed files with 26 additions and 16 deletions

6
package-lock.json generated
View File

@ -16776,7 +16776,7 @@
}, },
"packages/bruno-cli": { "packages/bruno-cli": {
"name": "@usebruno/cli", "name": "@usebruno/cli",
"version": "0.11.0", "version": "0.12.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@usebruno/js": "0.6.0", "@usebruno/js": "0.6.0",
@ -16822,7 +16822,7 @@
}, },
"packages/bruno-electron": { "packages/bruno-electron": {
"name": "bruno", "name": "bruno",
"version": "v0.19.0", "version": "v0.20.0",
"dependencies": { "dependencies": {
"@usebruno/js": "0.6.0", "@usebruno/js": "0.6.0",
"@usebruno/lang": "0.5.0", "@usebruno/lang": "0.5.0",
@ -20107,7 +20107,7 @@
"axios": "^1.5.1", "axios": "^1.5.1",
"chai": "^4.3.7", "chai": "^4.3.7",
"chalk": "^3.0.0", "chalk": "^3.0.0",
"decomment": "*", "decomment": "^0.9.5",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"fs-extra": "^10.1.0", "fs-extra": "^10.1.0",
"handlebars": "^4.7.8", "handlebars": "^4.7.8",

View File

@ -9,7 +9,7 @@ import { findEnvironmentInCollection } from 'utils/collections';
const interpolateUrl = ({ url, envVars, collectionVariables, processEnvVars }) => { const interpolateUrl = ({ url, envVars, collectionVariables, processEnvVars }) => {
if (!url || !url.length || typeof url !== 'string') { if (!url || !url.length || typeof url !== 'string') {
return str; return;
} }
const template = handlebars.compile(url, { noEscape: true }); const template = handlebars.compile(url, { noEscape: true });
@ -74,9 +74,8 @@ const languages = [
]; ];
const GenerateCodeItem = ({ collection, item, onClose }) => { 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); const environment = findEnvironmentInCollection(collection, collection.activeEnvironmentUid);
let envVars = {}; let envVars = {};
if (environment) { if (environment) {
const vars = get(environment, 'variables', []); const vars = get(environment, 'variables', []);
@ -92,7 +91,6 @@ const GenerateCodeItem = ({ collection, item, onClose }) => {
collectionVariables: collection.collectionVariables, collectionVariables: collection.collectionVariables,
processEnvVars: collection.processEnvVariables processEnvVars: collection.processEnvVariables
}); });
const [selectedLanguage, setSelectedLanguage] = useState(languages[0]); const [selectedLanguage, setSelectedLanguage] = useState(languages[0]);
return ( return (
<Modal size="lg" title="Generate Code" handleCancel={onClose} hideFooter={true}> <Modal size="lg" title="Generate Code" handleCancel={onClose} hideFooter={true}>
@ -121,10 +119,16 @@ const GenerateCodeItem = ({ collection, item, onClose }) => {
language={selectedLanguage} language={selectedLanguage}
item={{ item={{
...item, ...item,
request: { request:
item.request.url !== ''
? {
...item.request, ...item.request,
url: interpolatedUrl url: interpolatedUrl
} }
: {
...item.draft.request,
url: interpolatedUrl
}
}} }}
/> />
) : ( ) : (

View File

@ -21,7 +21,7 @@ import { isItemARequest, isItemAFolder, itemIsOpenedInTabs } from 'utils/tabs';
import { doesRequestMatchSearchText, doesFolderHaveItemsMatchSearchText } from 'utils/collections/search'; import { doesRequestMatchSearchText, doesFolderHaveItemsMatchSearchText } from 'utils/collections/search';
import { getDefaultRequestPaneTab } from 'utils/collections'; import { getDefaultRequestPaneTab } from 'utils/collections';
import { hideHomePage } from 'providers/ReduxStore/slices/app'; import { hideHomePage } from 'providers/ReduxStore/slices/app';
import toast from 'react-hot-toast';
import StyledWrapper from './StyledWrapper'; import StyledWrapper from './StyledWrapper';
const CollectionItem = ({ item, collection, searchText }) => { const CollectionItem = ({ item, collection, searchText }) => {
@ -148,7 +148,15 @@ const CollectionItem = ({ item, collection, searchText }) => {
const sortFolderItems = (items = []) => { const sortFolderItems = (items = []) => {
return items.sort((a, b) => a.name.localeCompare(b.name)); 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 requestItems = sortRequestItems(filter(item.items, (i) => isItemARequest(i)));
const folderItems = sortFolderItems(filter(item.items, (i) => isItemAFolder(i))); const folderItems = sortFolderItems(filter(item.items, (i) => isItemAFolder(i)));
@ -279,9 +287,7 @@ const CollectionItem = ({ item, collection, searchText }) => {
<div <div
className="dropdown-item" className="dropdown-item"
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); handleGenerateCode(e);
dropdownTippyRef.current.hide();
setGenerateCodeItemModalOpen(true);
}} }}
> >
Generate Code Generate Code