2022-03-18 00:13:35 +01:00
|
|
|
import each from 'lodash/each';
|
2022-03-17 22:29:10 +01:00
|
|
|
import find from 'lodash/find';
|
|
|
|
|
2022-03-18 00:13:35 +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;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const findItem = (items = [], itemUid) => {
|
|
|
|
return find(items, (i) => i.uid === itemUid);
|
|
|
|
};
|
|
|
|
|
2022-03-17 22:29:10 +01:00
|
|
|
export const findCollectionByUid = (collections, collectionUid) => {
|
|
|
|
return find(collections, (c) => c.uid === collectionUid);
|
|
|
|
};
|
2022-03-18 00:13:35 +01:00
|
|
|
|
|
|
|
export const findItemInCollection = (collection, itemUid) => {
|
|
|
|
let flattenedItems = flattenItems(collection.items);
|
|
|
|
|
|
|
|
return findItem(flattenedItems, itemUid);
|
|
|
|
}
|