From d0c25d46c94968c205b7afd63a349cda6a960656 Mon Sep 17 00:00:00 2001 From: Gustavo Fior Date: Thu, 4 Jan 2024 05:25:13 -0300 Subject: [PATCH] fix #1208: add collection headers to code generated (#1316) * fix collection headers in code generator * remove logs --- .../CollectionItem/GenerateCodeItem/CodeView/index.js | 10 +++++++++- packages/bruno-app/src/utils/collections/index.js | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/CodeView/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/CodeView/index.js index 5d81ae09..7ea7b170 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/CodeView/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/CodeView/index.js @@ -8,12 +8,20 @@ import { useSelector } from 'react-redux'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import toast from 'react-hot-toast'; import { IconCopy } from '@tabler/icons'; +import { findCollectionByItemUid } from '../../../../../../../utils/collections/index'; const CodeView = ({ language, item }) => { const { storedTheme } = useTheme(); const preferences = useSelector((state) => state.app.preferences); const { target, client, language: lang } = language; - const headers = item.draft ? get(item, 'draft.request.headers') : get(item, 'request.headers'); + const requestHeaders = item.draft ? get(item, 'draft.request.headers') : get(item, 'request.headers'); + const collection = findCollectionByItemUid( + useSelector((state) => state.collections.collections), + item.uid + ); + + const headers = [...collection?.root?.request?.headers, ...requestHeaders]; + let snippet = ''; try { diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index 05dd0fb4..bf828c55 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -91,6 +91,12 @@ export const findCollectionByPathname = (collections, pathname) => { return find(collections, (c) => c.pathname === pathname); }; +export const findCollectionByItemUid = (collections, itemUid) => { + return find(collections, (c) => { + return findItemInCollection(c, itemUid); + }); +}; + export const findItemByPathname = (items = [], pathname) => { return find(items, (i) => i.pathname === pathname); };