From e833493bcec27f3b7458a1843a5a3cb1d8fe1d03 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 13 Mar 2022 22:52:14 +0530 Subject: [PATCH] refactor: findCollectionByUid --- .../Sidebar/Collections/Collection/index.js | 3 --- renderer/providers/Store/reducer.js | 21 ++++++++++--------- renderer/providers/Store/utils.js | 4 ++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/renderer/components/Sidebar/Collections/Collection/index.js b/renderer/components/Sidebar/Collections/Collection/index.js index 501324674..80b2bf0bd 100644 --- a/renderer/components/Sidebar/Collections/Collection/index.js +++ b/renderer/components/Sidebar/Collections/Collection/index.js @@ -88,9 +88,6 @@ const Collection = ({collection}) => { key={i.uid} item={i} collectionId={collection.id} - actions={actions} - dispatch={storeDispatch} - activeRequestTabId={activeRequestTabId} /> }) : null} diff --git a/renderer/providers/Store/reducer.js b/renderer/providers/Store/reducer.js index 93544ece6..62108a927 100644 --- a/renderer/providers/Store/reducer.js +++ b/renderer/providers/Store/reducer.js @@ -11,7 +11,8 @@ import { isItemARequest, itemIsOpenedInTabs, cloneItem, - updateRequestTabAsChanged + updateRequestTabAsChanged, + findCollectionByUid } from './utils'; const reducer = (state, action) => { @@ -42,7 +43,7 @@ const reducer = (state, action) => { case actions.SIDEBAR_COLLECTION_CLICK: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.id === action.id); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { collection.collapsed = !collection.collapsed; @@ -52,7 +53,7 @@ const reducer = (state, action) => { case actions.SIDEBAR_COLLECTION_ITEM_CLICK: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.id === action.collectionId); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { let flattenedItems = flattenItems(collection.items); @@ -82,7 +83,7 @@ const reducer = (state, action) => { case actions.SIDEBAR_COLLECTION_ADD_FOLDER: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.uid === action.collectionUid); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { collection.current.items.push({ @@ -116,7 +117,7 @@ const reducer = (state, action) => { case actions.REQUEST_URL_CHANGED: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.id === action.collectionId); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { let flattenedItems = flattenItems(collection.items); @@ -135,7 +136,7 @@ const reducer = (state, action) => { case actions.REQUEST_GQL_QUERY_CHANGED: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.id === action.collectionId); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { let flattenedItems = flattenItems(collection.items); @@ -190,7 +191,7 @@ const reducer = (state, action) => { case actions.SEND_REQUEST: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.id === action.collectionId); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { let flattenedItems = flattenItems(collection.items); @@ -210,7 +211,7 @@ const reducer = (state, action) => { case actions.SENDING_REQUEST: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.id === action.collectionId); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { let flattenedItems = flattenItems(collection.items); @@ -226,7 +227,7 @@ const reducer = (state, action) => { case actions.RESPONSE_RECEIVED: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.id === action.collectionId); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { let flattenedItems = flattenItems(collection.items); @@ -254,7 +255,7 @@ const reducer = (state, action) => { case actions.ADD_REQUEST: { return produce(state, (draft) => { - const collection = find(draft.collections, (c) => c.id === action.collectionId); + const collection = findCollectionByUid(draft.collections, action.collectionUid); if(collection) { let flattenedItems = flattenItems(collection.items); diff --git a/renderer/providers/Store/utils.js b/renderer/providers/Store/utils.js index 33541ddca..032a700df 100644 --- a/renderer/providers/Store/utils.js +++ b/renderer/providers/Store/utils.js @@ -42,3 +42,7 @@ export const updateRequestTabAsChanged = (requestTabs, itemId) => { currentTab.hasChanges = true; } }; + +export const findCollectionByUid = (collections, collectionUid) => { + return find(collections, (c) => c.uid === collectionUid); +};