fix #1208: add collection headers to code generated (#1316)

* fix collection headers in code generator
* remove logs
This commit is contained in:
Gustavo Fior 2024-01-04 05:25:13 -03:00 committed by GitHub
parent d62982d52d
commit d0c25d46c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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 {

View File

@ -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);
};