Menu and Navigation Architecture Guide
This guide describes the navigation and menu architecture in Waldur Homeport, covering routing, dynamic sidebar generation, and workspace management.
Architecture Overview
Waldur Homeport uses a state-based navigation system driven by UI-Router for React. The UI structure is organized into Workspaces (e.g., Project, Organization, Administration, Support).
Core Components
- Router:
src/router.tsinitializes the UI-Router. - States:
src/states.tsaggregates all module-specificroutes.ts. - Layout:
src/navigation/Layout.tsxdefines the main container. - Sidebar:
src/navigation/sidebar/UnifiedSidebar.tsxmanages all sidebar content. - Tabs:
src/navigation/TabsList.tsxmanages the header/tab-bar navigation.
State-based Routing
Routes are defined as "states" in module-specific files. Each state can have metadata in the data property:
1 2 3 4 5 6 7 8 9 10 11 12 | |
Dynamic Navigation (useTabs)
The application uses a dynamic approach to build menus. Instead of hardcoding every link, the useTabs.tsx hook inspects the registered router states to build a hierarchy.
How it works
- Root Detection: Finds the "root" state for the current path (e.g., the state with a
title). - Filtering: Collects states that are children of the root and meet visibility criteria (feature flags, permissions).
- Hierarchy: Groups states into parent-child relationships based on state naming (e.g.,
parent.child) or theparentproperty. - Active State: Tracks the current state to highlight items in the sidebar or tabs.
Sidebar Organization
The UnifiedSidebar.tsx component conditionally renders menu items based on the active workspace and user roles:
- OrganizationsListMenu: List of organizations the user can access.
- ProjectsListMenu: List of projects within the active organization.
- ResourcesMenu: High-level resource categories.
- AdminMenu: System management links (Staff/Support only).
- Public/Anonymous Menus: Links visible to unauthenticated users.
Key Sidebar Components
- MenuItem: A single clickable link with icon and badge.
- MenuAccordion: A collapsible group for nested items.
Workspaces
A "Workspace" is a logical context (like a specific Project or the entire Administration area).
- Workspaces are defined in route metadata (
workspace: 'admin'). - The
src/workspace/module provides selectors to get the current customer, project, or user roles. - The UI often resets or switches functionality based on the active workspace.
How-to: Adding a New Menu Item
Method A: Route-driven (Recommended for Configuration/Details)
- Add a new route in
routes.ts. - Ensure it has a correctly named
parent. - Provide a
breadcrumbfunction andpriorityindata. useTabswill automatically pick it up and display it in the appropriate sub-menu.
Method B: Explicit Component (For Top-level/Global links)
- Create a new menu component in
src/navigation/sidebar/. - Use the
MenuItemcomponent. - Import and add it to
UnifiedSidebar.tsx.
LLM Quick-start Patterns
When asking an LLM to modify navigation:
- Identify parents: "Add a child route to
admin-configuration." - Specify breadcrumbs: "The breadcrumb should be 'Invoices'."
- Reference workspace: "The user is currently in the 'Organization' workspace."
- Check visibility: "This item should only be visible if
isStaffis true."