forked from extern/bruno
feat: delete request headers
This commit is contained in:
parent
cb96a175df
commit
ad971d9877
@ -4,7 +4,7 @@ import cloneDeep from 'lodash/cloneDeep';
|
|||||||
import { IconTrash } from '@tabler/icons';
|
import { IconTrash } from '@tabler/icons';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { requestChanged } from 'providers/ReduxStore/slices/tabs';
|
import { requestChanged } from 'providers/ReduxStore/slices/tabs';
|
||||||
import { addRequestHeader, updateRequestHeader } from 'providers/ReduxStore/slices/collections';
|
import { addRequestHeader, updateRequestHeader, deleteRequestHeader } from 'providers/ReduxStore/slices/collections';
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
|
|
||||||
const RequestHeaders = ({item, collection}) => {
|
const RequestHeaders = ({item, collection}) => {
|
||||||
@ -45,11 +45,20 @@ const RequestHeaders = ({item, collection}) => {
|
|||||||
dispatch(updateRequestHeader({
|
dispatch(updateRequestHeader({
|
||||||
header: header,
|
header: header,
|
||||||
itemUid: item.uid,
|
itemUid: item.uid,
|
||||||
collectionUid: collection.uid,
|
collectionUid: collection.uid
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveHeader = (index) => {
|
const handleRemoveHeader = (header) => {
|
||||||
|
dispatch(requestChanged({
|
||||||
|
itemUid: item.uid,
|
||||||
|
collectionUid: collection.uid
|
||||||
|
}));
|
||||||
|
dispatch(deleteRequestHeader({
|
||||||
|
headerUid: header.uid,
|
||||||
|
itemUid: item.uid,
|
||||||
|
collectionUid: collection.uid
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -98,12 +107,11 @@ const RequestHeaders = ({item, collection}) => {
|
|||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="mr-3"
|
|
||||||
checked={header.enabled}
|
checked={header.enabled}
|
||||||
className="mousetrap"
|
className="mr-3 mousetrap"
|
||||||
onChange={(e) => handleHeaderValueChange(e, header, 'enabled')}
|
onChange={(e) => handleHeaderValueChange(e, header, 'enabled')}
|
||||||
/>
|
/>
|
||||||
<button onClick={() => handleRemoveHeader(index)}>
|
<button onClick={() => handleRemoveHeader(header)}>
|
||||||
<IconTrash strokeWidth={1.5} size={20}/>
|
<IconTrash strokeWidth={1.5} size={20}/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import find from 'lodash/find';
|
import find from 'lodash/find';
|
||||||
|
import filter from 'lodash/filter';
|
||||||
import each from 'lodash/each';
|
import each from 'lodash/each';
|
||||||
import cloneDeep from 'lodash/cloneDeep';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
import { createSlice } from '@reduxjs/toolkit'
|
import { createSlice } from '@reduxjs/toolkit'
|
||||||
@ -11,7 +12,8 @@ import {
|
|||||||
cloneItem,
|
cloneItem,
|
||||||
transformCollectionToSaveToIdb,
|
transformCollectionToSaveToIdb,
|
||||||
addDepth,
|
addDepth,
|
||||||
deleteItemInCollection
|
deleteItemInCollection,
|
||||||
|
isItemARequest
|
||||||
} from 'utils/collections';
|
} from 'utils/collections';
|
||||||
|
|
||||||
// todo: errors should be tracked in each slice and displayed as toasts
|
// todo: errors should be tracked in each slice and displayed as toasts
|
||||||
@ -123,7 +125,7 @@ export const collectionsSlice = createSlice({
|
|||||||
if(collection) {
|
if(collection) {
|
||||||
const item = findItemInCollection(collection, action.payload.itemUid);
|
const item = findItemInCollection(collection, action.payload.itemUid);
|
||||||
|
|
||||||
if(item) {
|
if(item && isItemARequest(item)) {
|
||||||
if(!item.draft) {
|
if(!item.draft) {
|
||||||
item.draft = cloneItem(item);
|
item.draft = cloneItem(item);
|
||||||
}
|
}
|
||||||
@ -137,7 +139,7 @@ export const collectionsSlice = createSlice({
|
|||||||
if(collection) {
|
if(collection) {
|
||||||
const item = findItemInCollection(collection, action.payload.itemUid);
|
const item = findItemInCollection(collection, action.payload.itemUid);
|
||||||
|
|
||||||
if(item) {
|
if(item && isItemARequest(item)) {
|
||||||
if(!item.draft) {
|
if(!item.draft) {
|
||||||
item.draft = cloneItem(item);
|
item.draft = cloneItem(item);
|
||||||
}
|
}
|
||||||
@ -158,7 +160,7 @@ export const collectionsSlice = createSlice({
|
|||||||
if(collection) {
|
if(collection) {
|
||||||
const item = findItemInCollection(collection, action.payload.itemUid);
|
const item = findItemInCollection(collection, action.payload.itemUid);
|
||||||
|
|
||||||
if(item) {
|
if(item && isItemARequest(item)) {
|
||||||
if(!item.draft) {
|
if(!item.draft) {
|
||||||
item.draft = cloneItem(item);
|
item.draft = cloneItem(item);
|
||||||
}
|
}
|
||||||
@ -171,6 +173,20 @@ export const collectionsSlice = createSlice({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
deleteRequestHeader: (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 = cloneItem(item);
|
||||||
|
}
|
||||||
|
item.draft.request.headers = filter(item.draft.request.headers, (h) => h.uid !== action.payload.headerUid);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -188,7 +204,8 @@ export const {
|
|||||||
collectionFolderClicked,
|
collectionFolderClicked,
|
||||||
requestUrlChanged,
|
requestUrlChanged,
|
||||||
addRequestHeader,
|
addRequestHeader,
|
||||||
updateRequestHeader
|
updateRequestHeader,
|
||||||
|
deleteRequestHeader
|
||||||
} = collectionsSlice.actions;
|
} = collectionsSlice.actions;
|
||||||
|
|
||||||
export const loadCollectionsFromIdb = () => (dispatch) => {
|
export const loadCollectionsFromIdb = () => (dispatch) => {
|
||||||
|
@ -130,3 +130,11 @@ export const deleteItemInCollection = (itemUid, collection) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isItemARequest = (item) => {
|
||||||
|
return item.hasOwnProperty('request') && ['http-request', 'graphql-request'].includes(item.type);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isItemAFolder = (item) => {
|
||||||
|
return !item.hasOwnProperty('request') && item.type === 'folder';
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user