function transformFlatHierarchy({ map, rootTitle, rootType, columns }) {
let obj = {
name: rootTitle || 'root',
type: rootType || 'root',
_type: 'level'
};
let depth = 0;
function process(item, key, map, parent, depth) {
if (!parent.children) parent.children = [];
if (key === '' && !(item instanceof Map)) {
debugger;
parent.children = parent.children.concat(item);
return;
} else if (key == '' && item instanceof Map) {
debugger;
item.forEach((d, k, m) => process(d, k, m, parent, depth + 1));
return;
}
const child = {
name: key,
_type: 'level',
type: columns && columns[depth]
};
parent.children.push(child);
if (item instanceof Map) {
item.forEach((item, key, map) =>
process(item, key, map, child, depth + 1)
);
} else {
child.children = item;
}
}
map.forEach((item, key, map) => process(item, key, map, obj, depth));
return obj;
}