mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 23:43:15 +01:00
feat: reducer logic for add-request
This commit is contained in:
parent
1b3d9e5854
commit
233a078b73
@ -39,14 +39,18 @@ const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTab
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addRequest = () => {
|
||||||
|
dispatch({
|
||||||
|
type: actions.ADD_REQUEST,
|
||||||
|
itemId: item.id,
|
||||||
|
collectionId: collectionId
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
let indents = range(item.depth);
|
let indents = range(item.depth);
|
||||||
|
|
||||||
const onDropdownCreate = (ref) => dropdownTippyRef.current = ref;
|
const onDropdownCreate = (ref) => dropdownTippyRef.current = ref;
|
||||||
|
|
||||||
const stopEventPropogation = (event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledWrapper className="flex flex-col">
|
<StyledWrapper className="flex flex-col">
|
||||||
<div
|
<div
|
||||||
@ -87,8 +91,7 @@ const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTab
|
|||||||
<div>
|
<div>
|
||||||
<div className="dropdown-item" onClick={(e) => {
|
<div className="dropdown-item" onClick={(e) => {
|
||||||
dropdownTippyRef.current.hide();
|
dropdownTippyRef.current.hide();
|
||||||
stopEventPropogation(e);
|
addRequest();
|
||||||
console.log('Clicked');
|
|
||||||
}}>
|
}}>
|
||||||
Add Request
|
Add Request
|
||||||
</div>
|
</div>
|
||||||
@ -102,7 +105,7 @@ const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTab
|
|||||||
<div>
|
<div>
|
||||||
{item.items && item.items.length ? item.items.map((i) => {
|
{item.items && item.items.length ? item.items.map((i) => {
|
||||||
return <CollectionItem
|
return <CollectionItem
|
||||||
key={i.name}
|
key={i.id}
|
||||||
item={i}
|
item={i}
|
||||||
collectionId={collectionId}
|
collectionId={collectionId}
|
||||||
actions={actions}
|
actions={actions}
|
||||||
|
@ -3,11 +3,13 @@ const SIDEBAR_COLLECTION_ITEM_CLICK = "SIDEBAR_COLLECTION_ITEM_CLICK";
|
|||||||
const REQUEST_TAB_CLICK = "REQUEST_TAB_CLICK";
|
const REQUEST_TAB_CLICK = "REQUEST_TAB_CLICK";
|
||||||
const REQUEST_TAB_CLOSE = "REQUEST_TAB_CLOSE";
|
const REQUEST_TAB_CLOSE = "REQUEST_TAB_CLOSE";
|
||||||
const RESPONSE_RECEIVED = "RESPONSE_RECEIVED";
|
const RESPONSE_RECEIVED = "RESPONSE_RECEIVED";
|
||||||
|
const ADD_REQUEST = "ADD_REQUEST";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
SIDEBAR_COLLECTION_CLICK,
|
SIDEBAR_COLLECTION_CLICK,
|
||||||
SIDEBAR_COLLECTION_ITEM_CLICK,
|
SIDEBAR_COLLECTION_ITEM_CLICK,
|
||||||
REQUEST_TAB_CLICK,
|
REQUEST_TAB_CLICK,
|
||||||
REQUEST_TAB_CLOSE,
|
REQUEST_TAB_CLOSE,
|
||||||
RESPONSE_RECEIVED
|
RESPONSE_RECEIVED,
|
||||||
|
ADD_REQUEST
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
|
import {nanoid} from 'nanoid';
|
||||||
import find from 'lodash/find';
|
import find from 'lodash/find';
|
||||||
import filter from 'lodash/filter';
|
import filter from 'lodash/filter';
|
||||||
import actions from './actions';
|
import actions from './actions';
|
||||||
@ -85,6 +86,44 @@ const reducer = (state, action) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case actions.ADD_REQUEST: {
|
||||||
|
return produce(state, (draft) => {
|
||||||
|
const collection = find(draft.collections, (c) => c.id === action.collectionId);
|
||||||
|
console.log('a');
|
||||||
|
|
||||||
|
if(collection) {
|
||||||
|
let flattenedItems = flattenItems(collection.items);
|
||||||
|
let item = findItem(flattenedItems, action.itemId);
|
||||||
|
console.log('b');
|
||||||
|
|
||||||
|
if(item) {
|
||||||
|
console.log('c');
|
||||||
|
if(!isItemARequest(item)) {
|
||||||
|
console.log('d');
|
||||||
|
item.items.push({
|
||||||
|
"id": nanoid(),
|
||||||
|
"depth": 2,
|
||||||
|
"name": "Capsules 2",
|
||||||
|
"request": {
|
||||||
|
"url": "https://api.spacex.land/graphql/",
|
||||||
|
"method": "POST",
|
||||||
|
"headers": [],
|
||||||
|
"body": {
|
||||||
|
"mimeType": "application/graphql",
|
||||||
|
"graphql": {
|
||||||
|
"query": "{\n launchesPast(limit: 10) {\n mission_name\n launch_date_local\n launch_site {\n site_name_long\n }\n links {\n article_link\n video_link\n }\n rocket {\n rocket_name\n first_stage {\n cores {\n flight\n core {\n reuse_count\n status\n }\n }\n }\n second_stage {\n payloads {\n payload_type\n payload_mass_kg\n payload_mass_lbs\n }\n }\n }\n ships {\n name\n home_port\n image\n }\n }\n}",
|
||||||
|
"variables": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user