2021-12-03 20:37:38 +01:00
|
|
|
import each from 'lodash/each';
|
|
|
|
import find from 'lodash/find';
|
2022-01-23 13:38:01 +01:00
|
|
|
import cloneDeep from 'lodash/cloneDeep';
|
2021-12-03 20:37:38 +01:00
|
|
|
|
|
|
|
export const flattenItems = (items = []) => {
|
|
|
|
const flattenedItems = [];
|
|
|
|
|
|
|
|
const flatten = (itms, flattened) => {
|
|
|
|
each(itms, (i) => {
|
|
|
|
flattened.push(i);
|
|
|
|
|
|
|
|
if(i.items && i.items.length) {
|
|
|
|
flatten(i.items, flattened);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
flatten(items, flattenedItems);
|
|
|
|
|
|
|
|
return flattenedItems;
|
|
|
|
};
|
|
|
|
|
2022-03-13 22:13:36 +01:00
|
|
|
export const findItem = (items = [], itemUid) => {
|
|
|
|
return find(items, (i) => i.uid === itemUid);
|
2021-12-03 20:37:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export const isItemARequest = (item) => {
|
|
|
|
return item.hasOwnProperty('request');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const itemIsOpenedInTabs = (item, tabs) => {
|
2022-03-13 22:13:36 +01:00
|
|
|
return find(tabs, (t) => t.uid === item.uid);
|
2021-12-03 20:37:38 +01:00
|
|
|
};
|
2022-01-23 13:38:01 +01:00
|
|
|
|
|
|
|
export const cloneItem = (item) => {
|
|
|
|
return cloneDeep(item);
|
|
|
|
};
|
|
|
|
|
2022-03-13 22:13:36 +01:00
|
|
|
export const updateRequestTabAsChanged = (requestTabs, itemUid) => {
|
|
|
|
let currentTab = find(requestTabs, (rt) => rt.uid == itemUid);
|
2022-01-23 13:38:01 +01:00
|
|
|
if(currentTab) {
|
|
|
|
currentTab.hasChanges = true;
|
|
|
|
}
|
|
|
|
};
|
2022-03-13 18:22:14 +01:00
|
|
|
|
|
|
|
export const findCollectionByUid = (collections, collectionUid) => {
|
|
|
|
return find(collections, (c) => c.uid === collectionUid);
|
|
|
|
};
|