in script.js [527:546]
function buildHierarchy(managementGroups) {
const idMap = {};
const root = [];
// Create a map of id to management group
managementGroups.forEach(mg => {
idMap[mg.id] = { ...mg, children: [] };
});
// Build the hierarchy
managementGroups.forEach(mg => {
if (mg.parent_id === null) {
root.push(idMap[mg.id]);
} else if (idMap[mg.parent_id]) {
idMap[mg.parent_id].children.push(idMap[mg.id]);
}
});
return root;
}