Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add row clone button to headers tables #3650

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Wrapper = styled.div`
}

&:nth-child(3) {
width: 70px;
width: 85px;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -130,6 +141,10 @@ const Headers = ({ collection }) => {
className="mr-3 mousetrap"
onChange={(e) => handleHeaderValueChange(e, header, 'enabled')}
/>
<button tabIndex="-1" onClick={() => cloneHeader(header)}>
<IconCopy strokeWidth={1.5} size={20} />
</button>
&nbsp;
<button tabIndex="-1" onClick={() => handleRemoveHeader(header)}>
<IconTrash strokeWidth={1.5} size={20} />
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Wrapper = styled.div`
}

&:nth-child(3) {
width: 70px;
width: 85px;
}
}
}
Expand Down
23 changes: 21 additions & 2 deletions packages/bruno-app/src/components/FolderSettings/Headers/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -128,6 +143,10 @@ const Headers = ({ collection, folder }) => {
className="mr-3 mousetrap"
onChange={(e) => handleHeaderValueChange(e, header, 'enabled')}
/>
<button tabIndex="-1" onClick={() => handleRemoveHeader(header)}>
<IconCopy strokeWidth={1.5} size={20} />
</button>
&nbsp;
<button tabIndex="-1" onClick={() => handleRemoveHeader(header)}>
<IconTrash strokeWidth={1.5} size={20} />
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Wrapper = styled.div`
}

&:nth-child(3) {
width: 70px;
width: 85px;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -131,6 +146,10 @@ const RequestHeaders = ({ item, collection }) => {
className="mr-3 mousetrap"
onChange={(e) => handleHeaderValueChange(e, header, 'enabled')}
/>
<button tabIndex="-1" onClick={() => cloneHeader(header)}>
<IconCopy strokeWidth={1.5} size={20} />
</button>
&nbsp;
<button tabIndex="-1" onClick={() => handleRemoveHeader(header)}>
<IconTrash strokeWidth={1.5} size={20} />
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -1197,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;
Expand Down Expand Up @@ -1326,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);

Expand Down Expand Up @@ -1772,6 +1823,7 @@ export const {
deleteQueryParam,
updatePathParam,
addRequestHeader,
cloneRequestHeader,
updateRequestHeader,
deleteRequestHeader,
addFormUrlEncodedParam,
Expand All @@ -1796,6 +1848,7 @@ export const {
updateVar,
deleteVar,
addFolderHeader,
cloneFolderHeader,
updateFolderHeader,
deleteFolderHeader,
addFolderVar,
Expand All @@ -1805,6 +1858,7 @@ export const {
updateFolderResponseScript,
updateFolderTests,
addCollectionHeader,
cloneCollectionHeader,
updateCollectionHeader,
deleteCollectionHeader,
addCollectionVar,
Expand Down