refactor: findCollectionByUid

This commit is contained in:
Anoop M D 2022-03-13 22:52:14 +05:30
parent af44c0e434
commit e833493bce
3 changed files with 15 additions and 13 deletions

View File

@ -88,9 +88,6 @@ const Collection = ({collection}) => {
key={i.uid} key={i.uid}
item={i} item={i}
collectionId={collection.id} collectionId={collection.id}
actions={actions}
dispatch={storeDispatch}
activeRequestTabId={activeRequestTabId}
/> />
}) : null} }) : null}
</div> </div>

View File

@ -11,7 +11,8 @@ import {
isItemARequest, isItemARequest,
itemIsOpenedInTabs, itemIsOpenedInTabs,
cloneItem, cloneItem,
updateRequestTabAsChanged updateRequestTabAsChanged,
findCollectionByUid
} from './utils'; } from './utils';
const reducer = (state, action) => { const reducer = (state, action) => {
@ -42,7 +43,7 @@ const reducer = (state, action) => {
case actions.SIDEBAR_COLLECTION_CLICK: { case actions.SIDEBAR_COLLECTION_CLICK: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.id); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
collection.collapsed = !collection.collapsed; collection.collapsed = !collection.collapsed;
@ -52,7 +53,7 @@ const reducer = (state, action) => {
case actions.SIDEBAR_COLLECTION_ITEM_CLICK: { case actions.SIDEBAR_COLLECTION_ITEM_CLICK: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.collectionId); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
let flattenedItems = flattenItems(collection.items); let flattenedItems = flattenItems(collection.items);
@ -82,7 +83,7 @@ const reducer = (state, action) => {
case actions.SIDEBAR_COLLECTION_ADD_FOLDER: { case actions.SIDEBAR_COLLECTION_ADD_FOLDER: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.uid === action.collectionUid); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
collection.current.items.push({ collection.current.items.push({
@ -116,7 +117,7 @@ const reducer = (state, action) => {
case actions.REQUEST_URL_CHANGED: { case actions.REQUEST_URL_CHANGED: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.collectionId); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
let flattenedItems = flattenItems(collection.items); let flattenedItems = flattenItems(collection.items);
@ -135,7 +136,7 @@ const reducer = (state, action) => {
case actions.REQUEST_GQL_QUERY_CHANGED: { case actions.REQUEST_GQL_QUERY_CHANGED: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.collectionId); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
let flattenedItems = flattenItems(collection.items); let flattenedItems = flattenItems(collection.items);
@ -190,7 +191,7 @@ const reducer = (state, action) => {
case actions.SEND_REQUEST: { case actions.SEND_REQUEST: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.collectionId); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
let flattenedItems = flattenItems(collection.items); let flattenedItems = flattenItems(collection.items);
@ -210,7 +211,7 @@ const reducer = (state, action) => {
case actions.SENDING_REQUEST: { case actions.SENDING_REQUEST: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.collectionId); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
let flattenedItems = flattenItems(collection.items); let flattenedItems = flattenItems(collection.items);
@ -226,7 +227,7 @@ const reducer = (state, action) => {
case actions.RESPONSE_RECEIVED: { case actions.RESPONSE_RECEIVED: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.collectionId); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
let flattenedItems = flattenItems(collection.items); let flattenedItems = flattenItems(collection.items);
@ -254,7 +255,7 @@ const reducer = (state, action) => {
case actions.ADD_REQUEST: { case actions.ADD_REQUEST: {
return produce(state, (draft) => { return produce(state, (draft) => {
const collection = find(draft.collections, (c) => c.id === action.collectionId); const collection = findCollectionByUid(draft.collections, action.collectionUid);
if(collection) { if(collection) {
let flattenedItems = flattenItems(collection.items); let flattenedItems = flattenItems(collection.items);

View File

@ -42,3 +42,7 @@ export const updateRequestTabAsChanged = (requestTabs, itemId) => {
currentTab.hasChanges = true; currentTab.hasChanges = true;
} }
}; };
export const findCollectionByUid = (collections, collectionUid) => {
return find(collections, (c) => c.uid === collectionUid);
};