-const flatTree = (depth: number, items?: any): [] => {
- return items ? items.reduce((prev: any, next: any) => {
- const { items } = next;
+const flatTree = (itemsIdMap: Map<string, any>, depth: number, items?: any): [] => {
+ return items ? items
+ .map((item: any) => addToItemsIdMap(item, itemsIdMap))
+ .reduce((prev: Array<any>, next: any) => {
+ const { items } = next;
+ prev.push({ ...next, depth });
+ prev.push(...(next.open ? flatTree(itemsIdMap, depth + 1, items) : []));
+ return prev;
+ }, []) : [];
+};