From d7ff4e7ee0d38ab9a0a6fbb4be50fc4df15319b0 Mon Sep 17 00:00:00 2001 From: Sitaram Rathi <57089237+srrathi@users.noreply.github.com> Date: Sat, 21 Sep 2024 09:31:38 +0530 Subject: [PATCH] added generate code button in query url bar (#3099) --- .../components/RequestPane/QueryUrl/index.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/bruno-app/src/components/RequestPane/QueryUrl/index.js b/packages/bruno-app/src/components/RequestPane/QueryUrl/index.js index 15334d2f7..f6d4ff308 100644 --- a/packages/bruno-app/src/components/RequestPane/QueryUrl/index.js +++ b/packages/bruno-app/src/components/RequestPane/QueryUrl/index.js @@ -5,10 +5,12 @@ import { requestUrlChanged, updateRequestMethod } from 'providers/ReduxStore/sli import { saveRequest } from 'providers/ReduxStore/slices/collections/actions'; import HttpMethodSelector from './HttpMethodSelector'; import { useTheme } from 'providers/Theme'; -import { IconDeviceFloppy, IconArrowRight } from '@tabler/icons'; +import { IconDeviceFloppy, IconArrowRight, IconCode } from '@tabler/icons'; import SingleLineEditor from 'components/SingleLineEditor'; import { isMacOS } from 'utils/common/platform'; import StyledWrapper from './StyledWrapper'; +import GenerateCodeItem from 'components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index'; +import toast from 'react-hot-toast'; const QueryUrl = ({ item, collection, handleRun }) => { const { theme, storedTheme } = useTheme(); @@ -20,6 +22,7 @@ const QueryUrl = ({ item, collection, handleRun }) => { const editorRef = useRef(null); const [methodSelectorWidth, setMethodSelectorWidth] = useState(90); + const [generateCodeItemModalOpen, setGenerateCodeItemModalOpen] = useState(false); useEffect(() => { const el = document.querySelector('.method-selector-container'); @@ -65,6 +68,15 @@ const QueryUrl = ({ item, collection, handleRun }) => { ); }; + const handleGenerateCode = (e) => { + e.stopPropagation(); + if (item.request.url !== '' || (item.draft?.request.url !== undefined && item.draft?.request.url !== '')) { + setGenerateCodeItemModalOpen(true); + } else { + toast.error('URL is required'); + } + }; + return (
@@ -90,6 +102,22 @@ const QueryUrl = ({ item, collection, handleRun }) => { item={item} />
+
{ + handleGenerateCode(e); + }} + > + + + Generate Code + +
{ @@ -111,6 +139,9 @@ const QueryUrl = ({ item, collection, handleRun }) => {
+ {generateCodeItemModalOpen && ( + setGenerateCodeItemModalOpen(false)} /> + )} ); };