mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-22 07:53:34 +01:00
refactor: findCollectionByUid
This commit is contained in:
parent
af44c0e434
commit
e833493bce
@ -88,9 +88,6 @@ const Collection = ({collection}) => {
|
||||
key={i.uid}
|
||||
item={i}
|
||||
collectionId={collection.id}
|
||||
actions={actions}
|
||||
dispatch={storeDispatch}
|
||||
activeRequestTabId={activeRequestTabId}
|
||||
/>
|
||||
}) : null}
|
||||
</div>
|
||||
|
@ -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);
|
||||
|
@ -42,3 +42,7 @@ export const updateRequestTabAsChanged = (requestTabs, itemId) => {
|
||||
currentTab.hasChanges = true;
|
||||
}
|
||||
};
|
||||
|
||||
export const findCollectionByUid = (collections, collectionUid) => {
|
||||
return find(collections, (c) => c.uid === collectionUid);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user