PHP 8.2.30
Preview: organizeMenusIntoHierarchy.js Size: 664 B
//proc/thread-self/root/home/byroehnu/easetack.com/resources/js/utils/organizeMenusIntoHierarchy.js

export default function organizeMenusIntoHierarchy(flatMenus) {
    const menuHierarchy = [];

    const menuMap = new Map();

    // First, create a map of menus by their IDs
    flatMenus.forEach(menu => {
        menuMap.set(menu.id, { ...menu, children: [] });
    });

    // Then, build the hierarchy
    flatMenus.forEach(menu => {
        if (menu.parent_id !== null) {
            const parentMenu = menuMap.get(menu.parent_id);
            if (parentMenu) {
                parentMenu.children.push(menuMap.get(menu.id));
            }
        } else {
            menuHierarchy.push(menuMap.get(menu.id));
        }
    });

    return menuHierarchy;
}

Directory Contents

Dirs: 0 × Files: 7

Name Size Perms Modified Actions
1.10 KB lrw-rw-rw- 2025-05-01 06:16:19
Edit Download
378 B lrw-rw-rw- 2025-04-09 10:29:01
Edit Download
206 B lrw-rw-rw- 2025-04-08 04:12:57
Edit Download
664 B lrw-rw-rw- 2025-04-08 04:12:57
Edit Download
1.04 KB lrw-rw-rw- 2025-04-08 04:12:57
Edit Download
156 B lrw-rw-rw- 2025-04-08 04:12:57
Edit Download
253 B lrw-rw-rw- 2025-04-08 04:12:57
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).