From 233a078b7339e27222af59d9e6c14cc6751e2712 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sat, 11 Dec 2021 03:59:44 +0530 Subject: [PATCH] feat: reducer logic for add-request --- .../Collection/CollectionItem/index.js | 17 ++++---- .../src/providers/Store/actions.js | 4 +- .../src/providers/Store/reducer.js | 39 +++++++++++++++++++ 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/packages/grafnode-components/src/components/Sidebar/Collections/Collection/CollectionItem/index.js b/packages/grafnode-components/src/components/Sidebar/Collections/Collection/CollectionItem/index.js index 40c96c26..48d52e55 100644 --- a/packages/grafnode-components/src/components/Sidebar/Collections/Collection/CollectionItem/index.js +++ b/packages/grafnode-components/src/components/Sidebar/Collections/Collection/CollectionItem/index.js @@ -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); const onDropdownCreate = (ref) => dropdownTippyRef.current = ref; - const stopEventPropogation = (event) => { - event.stopPropagation(); - }; - return (
{ dropdownTippyRef.current.hide(); - stopEventPropogation(e); - console.log('Clicked'); + addRequest(); }}> Add Request
@@ -102,7 +105,7 @@ const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTab
{item.items && item.items.length ? item.items.map((i) => { return { }); } + 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: { return state; }