From 4fe14a1c4be6e81b9d2bf6a2eac386195d2d64e2 Mon Sep 17 00:00:00 2001 From: BenSnellgrove Date: Fri, 13 Dec 2024 23:37:28 +0000 Subject: [PATCH 1/2] Add clone row button for request header --- .../RequestHeaders/StyledWrapper.js | 2 +- .../RequestPane/RequestHeaders/index.js | 23 +++++++++++++++++-- .../ReduxStore/slices/collections/index.js | 22 ++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/components/RequestPane/RequestHeaders/StyledWrapper.js b/packages/bruno-app/src/components/RequestPane/RequestHeaders/StyledWrapper.js index 9f723cb81c..15db29b35a 100644 --- a/packages/bruno-app/src/components/RequestPane/RequestHeaders/StyledWrapper.js +++ b/packages/bruno-app/src/components/RequestPane/RequestHeaders/StyledWrapper.js @@ -25,7 +25,7 @@ const Wrapper = styled.div` } &:nth-child(3) { - width: 70px; + width: 85px; } } } diff --git a/packages/bruno-app/src/components/RequestPane/RequestHeaders/index.js b/packages/bruno-app/src/components/RequestPane/RequestHeaders/index.js index 9aa3b621f4..c7785ac1c3 100644 --- a/packages/bruno-app/src/components/RequestPane/RequestHeaders/index.js +++ b/packages/bruno-app/src/components/RequestPane/RequestHeaders/index.js @@ -1,10 +1,15 @@ import React from 'react'; import get from 'lodash/get'; import cloneDeep from 'lodash/cloneDeep'; -import { IconTrash } from '@tabler/icons'; +import { IconCopy, IconTrash } from '@tabler/icons'; import { useDispatch } from 'react-redux'; import { useTheme } from 'providers/Theme'; -import { addRequestHeader, updateRequestHeader, deleteRequestHeader } from 'providers/ReduxStore/slices/collections'; +import { + addRequestHeader, + cloneRequestHeader, + updateRequestHeader, + deleteRequestHeader +} from 'providers/ReduxStore/slices/collections'; import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions'; import SingleLineEditor from 'components/SingleLineEditor'; import StyledWrapper from './StyledWrapper'; @@ -53,6 +58,16 @@ const RequestHeaders = ({ item, collection }) => { ); }; + const cloneHeader = (header) => { + dispatch( + cloneRequestHeader({ + header: header, + itemUid: item.uid, + collectionUid: collection.uid + }) + ); + }; + const handleRemoveHeader = (header) => { dispatch( deleteRequestHeader({ @@ -131,6 +146,10 @@ const RequestHeaders = ({ item, collection }) => { className="mr-3 mousetrap" onChange={(e) => handleHeaderValueChange(e, header, 'enabled')} /> + +   diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index b7ef2f86e5..e246d270f5 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -656,6 +656,27 @@ export const collectionsSlice = createSlice({ } } }, + cloneRequestHeader: (state, action) => { + const collection = findCollectionByUid(state.collections, action.payload.collectionUid); + + if (collection) { + const item = findItemInCollection(collection, action.payload.itemUid); + + if (item && isItemARequest(item)) { + if (!item.draft) { + item.draft = cloneDeep(item); + } + item.draft.request.headers = item.draft.request.headers || []; + item.draft.request.headers.push({ + uid: uuid(), + name: action.payload.header.name, + value: action.payload.header.value, + description: action.payload.header.description, + enabled: action.payload.header.enabled + }); + } + } + }, updateRequestHeader: (state, action) => { const collection = findCollectionByUid(state.collections, action.payload.collectionUid); @@ -1772,6 +1793,7 @@ export const { deleteQueryParam, updatePathParam, addRequestHeader, + cloneRequestHeader, updateRequestHeader, deleteRequestHeader, addFormUrlEncodedParam, From 133ca79147ba426ac832a540d1f896f33bfd5cf2 Mon Sep 17 00:00:00 2001 From: BenSnellgrove Date: Fri, 13 Dec 2024 23:53:32 +0000 Subject: [PATCH 2/2] Add same feature for folder and collection for consistency --- .../Headers/StyledWrapper.js | 2 +- .../CollectionSettings/Headers/index.js | 17 +++++++++- .../FolderSettings/Headers/StyledWrapper.js | 2 +- .../FolderSettings/Headers/index.js | 23 +++++++++++-- .../ReduxStore/slices/collections/index.js | 32 +++++++++++++++++++ 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/packages/bruno-app/src/components/CollectionSettings/Headers/StyledWrapper.js b/packages/bruno-app/src/components/CollectionSettings/Headers/StyledWrapper.js index 9f723cb81c..15db29b35a 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Headers/StyledWrapper.js +++ b/packages/bruno-app/src/components/CollectionSettings/Headers/StyledWrapper.js @@ -25,7 +25,7 @@ const Wrapper = styled.div` } &:nth-child(3) { - width: 70px; + width: 85px; } } } diff --git a/packages/bruno-app/src/components/CollectionSettings/Headers/index.js b/packages/bruno-app/src/components/CollectionSettings/Headers/index.js index 9ae6e1e074..3b42280278 100644 --- a/packages/bruno-app/src/components/CollectionSettings/Headers/index.js +++ b/packages/bruno-app/src/components/CollectionSettings/Headers/index.js @@ -1,11 +1,12 @@ import React from 'react'; import get from 'lodash/get'; import cloneDeep from 'lodash/cloneDeep'; -import { IconTrash } from '@tabler/icons'; +import { IconTrash, IconCopy } from '@tabler/icons'; import { useDispatch } from 'react-redux'; import { useTheme } from 'providers/Theme'; import { addCollectionHeader, + cloneCollectionHeader, updateCollectionHeader, deleteCollectionHeader } from 'providers/ReduxStore/slices/collections'; @@ -54,6 +55,16 @@ const Headers = ({ collection }) => { ); }; + const cloneHeader = (header) => { + dispatch( + cloneCollectionHeader({ + header: header, + itemUid: item.uid, + collectionUid: collection.uid + }) + ); + }; + const handleRemoveHeader = (header) => { dispatch( deleteCollectionHeader({ @@ -130,6 +141,10 @@ const Headers = ({ collection }) => { className="mr-3 mousetrap" onChange={(e) => handleHeaderValueChange(e, header, 'enabled')} /> + +   diff --git a/packages/bruno-app/src/components/FolderSettings/Headers/StyledWrapper.js b/packages/bruno-app/src/components/FolderSettings/Headers/StyledWrapper.js index 9f723cb81c..15db29b35a 100644 --- a/packages/bruno-app/src/components/FolderSettings/Headers/StyledWrapper.js +++ b/packages/bruno-app/src/components/FolderSettings/Headers/StyledWrapper.js @@ -25,7 +25,7 @@ const Wrapper = styled.div` } &:nth-child(3) { - width: 70px; + width: 85px; } } } diff --git a/packages/bruno-app/src/components/FolderSettings/Headers/index.js b/packages/bruno-app/src/components/FolderSettings/Headers/index.js index 0f6e05f1fa..90a419b327 100644 --- a/packages/bruno-app/src/components/FolderSettings/Headers/index.js +++ b/packages/bruno-app/src/components/FolderSettings/Headers/index.js @@ -1,10 +1,15 @@ import React from 'react'; import get from 'lodash/get'; import cloneDeep from 'lodash/cloneDeep'; -import { IconTrash } from '@tabler/icons'; +import { IconTrash, IconCopy } from '@tabler/icons'; import { useDispatch } from 'react-redux'; import { useTheme } from 'providers/Theme'; -import { addFolderHeader, updateFolderHeader, deleteFolderHeader } from 'providers/ReduxStore/slices/collections'; +import { + addFolderHeader, + cloneFolderHeader, + updateFolderHeader, + deleteFolderHeader +} from 'providers/ReduxStore/slices/collections'; import { saveFolderRoot } from 'providers/ReduxStore/slices/collections/actions'; import SingleLineEditor from 'components/SingleLineEditor'; import StyledWrapper from './StyledWrapper'; @@ -51,6 +56,16 @@ const Headers = ({ collection, folder }) => { ); }; + const cloneHeader = (header) => { + dispatch( + cloneFolderHeader({ + header: header, + itemUid: item.uid, + collectionUid: collection.uid + }) + ); + }; + const handleRemoveHeader = (header) => { dispatch( deleteFolderHeader({ @@ -128,6 +143,10 @@ const Headers = ({ collection, folder }) => { className="mr-3 mousetrap" onChange={(e) => handleHeaderValueChange(e, header, 'enabled')} /> + +   diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index e246d270f5..827d891cb6 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -1218,6 +1218,21 @@ export const collectionsSlice = createSlice({ set(folder, 'root.request.headers', headers); } }, + cloneFolderHeader: (state, action) => { + const collection = findCollectionByUid(state.collections, action.payload.collectionUid); + const folder = collection ? findItemInCollection(collection, action.payload.folderUid) : null; + if (folder) { + const headers = get(folder, 'root.request.headers', []); + headers.push({ + uid: uuid(), + name: action.payload.header.name, + value: action.payload.header.value, + description: action.payload.header.description, + enabled: action.payload.header.enabled + }); + set(folder, 'root.request.headers', headers); + } + }, updateFolderHeader: (state, action) => { const collection = findCollectionByUid(state.collections, action.payload.collectionUid); const folder = collection ? findItemInCollection(collection, action.payload.folderUid) : null; @@ -1347,6 +1362,21 @@ export const collectionsSlice = createSlice({ set(collection, 'root.request.headers', headers); } }, + cloneCollectionHeader: (state, action) => { + const collection = findCollectionByUid(state.collections, action.payload.collectionUid); + + if (collection) { + const headers = get(collection, 'root.request.headers', []); + headers.push({ + uid: uuid(), + name: action.payload.header.name, + value: action.payload.header.value, + description: action.payload.header.description, + enabled: action.payload.header.enabled + }); + set(collection, 'root.request.headers', headers); + } + }, updateCollectionHeader: (state, action) => { const collection = findCollectionByUid(state.collections, action.payload.collectionUid); @@ -1818,6 +1848,7 @@ export const { updateVar, deleteVar, addFolderHeader, + cloneFolderHeader, updateFolderHeader, deleteFolderHeader, addFolderVar, @@ -1827,6 +1858,7 @@ export const { updateFolderResponseScript, updateFolderTests, addCollectionHeader, + cloneCollectionHeader, updateCollectionHeader, deleteCollectionHeader, addCollectionVar,