Nested Side Navigation Items - Implementation Ticket
Historical design/implementation plan. It is retained as background, not a statement that every proposed feature is available. Use the current component/project guides and the deployed editor before following its recipes.
Overview
Add support for nested navigation shortcuts (e.g., GXPrint → Print Connections, Jobs Monitor, Analytics) with both backend support for data storage/processing and frontend UI for management and rendering.
Key Architecture Decision: Use efficient single-query pattern with in-memory tree building rather than multiple relationship queries.
Requirements Summary
Goal
Enable custom nested side navigation items where a parent (like "GXPrint") can contain children:
- Print Connections
- Jobs Monitor
- Analytics
Data Model Changes
- Add optional
parent_idfield toproject_navigation_shortcutstable - Support
subitemsarray in plugin plan JSON with same entity shape as top-level items - Use tree-building utility to convert flat arrays to nested structures in memory
Type Definition (TypeScript-style)
type ParamValue =
| { type: "project_id" }
| { key: string; type: "generated"; identifier: string };
type SideNavParam = { key: string; value: ParamValue };
type SideNavItem = {
icon?: string;
color?: string;
label: string;
order?: number;
route?: string;
params?: SideNavParam[];
is_top_level?: boolean;
subitems?: SideNavItem[]; // NEW - recursive structure
};
Example JSON (GXPrint)
[
{
"icon": "printer",
"color": "#ffffff",
"label": "GXPrint",
"order": 6,
"is_top_level": true,
"subitems": [
{
"icon": "link",
"color": "#ffffff",
"label": "Print Connections",
"order": 1,
"route": "dashboard.project.gxprint.connections.index",
"params": [{ "key": "project", "value": { "type": "project_id" } }]
},
{
"icon": "activity",
"color": "#ffffff",
"label": "Jobs Monitor",
"order": 2,
"route": "dashboard.project.gxprint.jobs.index",
"params": [{ "key": "project", "value": { "type": "project_id" } }]
},
{
"icon": "bar-chart-2",
"color": "#ffffff",
"label": "Analytics",
"order": 3,
"route": "dashboard.project.gxprint.analytics.index",
"params": [{ "key": "project", "value": { "type": "project_id" } }]
}
]
}
]
Backend Implementation
Phase 1: Database Schema
File: New migration add_parent_id_to_project_navigation_shortcuts
Changes:
Schema::table('project_navigation_shortcuts', function (Blueprint $table) {
$table->unsignedBigInteger('parent_id')->nullable()->after('project_id');
$table->foreign('parent_id')
->references('id')
->on('project_navigation_shortcuts')
->onDelete('cascade');
$table->index('parent_id');
});
Rationale:
parent_idnullable for backward compatibility (existing flat shortcuts)- Cascade delete ensures children are removed when parent is deleted
- Index improves query performance for filtering operations
Phase 2: Tree-Building Utility
File: app/Helpers/TreeBuilder.php (NEW)
Purpose: Convert flat arrays with parent_id to nested tree structures efficiently.
Implementation:
<?php
namespace App\Helpers;
class TreeBuilder
{
/**
* Build tree structure from flat array with parent_id
*
* @param array $items Flat array of items
* @param mixed $parentId Parent ID to filter by (null for root)
* @param string $parentKey Key name for parent reference
* @param string $childrenKey Key name for children array
* @return array Tree structure
*/
public static function buildTree(
array $items,
$parentId = null,
string $parentKey = 'parent_id',
string $childrenKey = 'children'
): array {
$tree = [];
foreach ($items as $item) {
if ($item[$parentKey] === $parentId) {
// Recursively find children
$children = self::buildTree($items, $item['id'], $parentKey, $childrenKey);
if (!empty($children)) {
$item[$childrenKey] = $children;
}
$tree[] = $item;
}
}
// Sort by order field (stable sort)
usort($tree, fn($a, $b) => ($a['order'] ?? 999) <=> ($b['order'] ?? 999));
return $tree;
}
}
Benefits:
- Single pass through flat array (efficient)
- Reusable for any hierarchical data
- Configurable key names
- Respects
orderfield at each level
Test File: tests/Unit/Helpers/TreeBuilderTest.php
Phase 3: Model Updates
File: app/Models/ProjectNavigationShortcut.php
Changes:
// Add to $fillable array
protected $fillable = [
'label',
'navigation_path',
'icon',
'color',
'order',
'is_active',
'is_top_level',
'parent_id' // NEW
];
// Update validation rules
public static function createRules(): array
{
return [
'label' => 'string|required',
'navigation_path' => 'string|required',
'icon' => 'string|nullable',
'color' => 'string|nullable',
'order' => 'integer|nullable',
'is_active' => 'boolean|nullable',
'is_top_level' => 'boolean|nullable',
'parent_id' => 'nullable|exists:project_navigation_shortcuts,id', // NEW
];
}
public static function updateRules(): array
{
return [
// ... existing rules ...
'parent_id' => 'nullable|exists:project_navigation_shortcuts,id', // NEW
];
}
File: app/Models/Project.php
Add Accessor for Tree-Structured Shortcuts:
/**
* Get top shortcuts as tree structure
* Uses single query + in-memory tree building (no N+1 queries)
*/
public function getTopShortcutsTreeAttribute()
{
// Get all shortcuts that should appear in top nav (single query)
$flatShortcuts = $this->shortcuts()
->where('is_active', true)
->where(function($query) {
// Get top-level items OR children of top-level items
$query->where('is_top_level', true)
->orWhereHas('parent', function($q) {
$q->where('is_top_level', true);
});
})
->get()
->toArray();
// Build tree from flat array
return \App\Helpers\TreeBuilder::buildTree($flatShortcuts, null);
}
// Optional: Add relationship for query builder (though not used for loading)
public function parent()
{
return $this->belongsTo(ProjectNavigationShortcut::class, 'parent_id');
}
Note: Keep existing shortcuts() and topShortcuts() methods unchanged for backward compatibility.
Phase 4: Plugin Plan Processing
File: app/Models/PluginPlan.php
Location: Lines 162-184 in applyToProject() method
Current Code (to replace):
foreach ($this->navigation_shortcuts as $shortcut) {
// ... create shortcut logic ...
$project->shortcuts()->create($newShortcut);
}
New Code:
// Replace direct loop with recursive method call
$this->processNavigationShortcuts($this->navigation_shortcuts, $project, $team, null);
Add New Private Method:
/**
* Recursively process navigation shortcuts and their subitems
*
* @param array $shortcuts Array of shortcuts to process
* @param Project $project Project to attach to
* @param Team $team Team for route building
* @param int|null $parentId Parent shortcut ID (null for top level)
*/
private function processNavigationShortcuts($shortcuts, $project, $team, $parentId = null)
{
foreach ($shortcuts as $shortcut) {
$newShortcut = [
'icon' => $shortcut['icon'] ?? null,
'label' => $shortcut['label'] ?? 'Shortcut',
'order' => $shortcut['order'] ?? 0,
'color' => $shortcut['color'] ?? '#ffffff',
'is_top_level' => $shortcut['is_top_level'] ?? false,
'parent_id' => $parentId, // NEW - link to parent
];
// Build navigation_path if route provided
if (isset($shortcut['route']) && isset($shortcut['params'])) {
$params = ['team' => $team->slug];
foreach ($shortcut['params'] as $param) {
if ($param['value']['type'] == 'generated') {
$params[$param['key']] = $this->object[$param['value']['identifier']][$param['value']['key']];
} else {
$params[$param['key']] = $project->slug;
}
}
$newShortcut['navigation_path'] = route($shortcut['route'], $params, false);
}
// Create the shortcut
$created = $project->shortcuts()->create($newShortcut);
// Recursively process subitems if they exist
if (!empty($shortcut['subitems']) && is_array($shortcut['subitems'])) {
$this->processNavigationShortcuts(
$shortcut['subitems'],
$project,
$team,
$created->id // Pass parent ID to children
);
}
}
}
Key Changes:
- Recursive processing of
subitemsarray - Each child gets parent's ID via
parent_id - Same route/param processing logic as before
- Maintains order at each nesting level
Frontend Implementation
Phase 5: Side Navigation Rendering
File: resources/js/Dashboard/Layouts/Partials/AppNavigation.js
Location: Lines 1479-1501
Add Recursive Mapping Function (before getNavItems):
/**
* Recursively map shortcut objects to navigation items
* Transforms backend structure to frontend nav structure
*/
function mapShortcutToNavItem(shortcut) {
const navItem = {
title: shortcut.label,
icon: shortcut.icon,
classList: shortcut.classList || [],
href: shortcut.navigation_path,
};
// Recursively map children if they exist
if (shortcut.children && shortcut.children.length > 0) {
navItem.children = shortcut.children.map(mapShortcutToNavItem);
}
return navItem;
}
Update Shortcuts Processing Section:
if (listKey === "project-nav" &&
project &&
project.top_shortcuts &&
project.top_shortcuts.length > 0) {
let parsedItems = [filteredItems.shift()]; // Dashboard item
// Map shortcuts with recursive children support
let topShortcuts = project.top_shortcuts.map(mapShortcutToNavItem);
parsedItems = parsedItems.concat(topShortcuts, filteredItems);
return parsedItems;
}
Key Changes:
- Replace inline flat mapping with recursive
mapShortcutToNavItemfunction - Children are automatically mapped at any nesting depth
- Existing
BaseNavItemandBaseNavSubItemcomponents already support this structure
Phase 6: Admin UI - Projects/Show.vue
File: resources/js/Dashboard/Pages/Admin/Projects/Show.vue
Location: Dashboard Shortcuts tab (lines 78-235)
Step 6a: Add "Has Children" Column
Update headers array (after line 127):
headers: [
{ key: "label", title: "Label", sortable: false, align: "start" },
{ key: "icon", title: "Icon", sortable: false, align: "start" },
{ key: "navigation_path", title: "Path", sortable: false, align: "start" },
{
key: "has_children",
title: "Has Children",
sortable: false,
align: "start",
// Custom render function
format: (item) => item.children?.length > 0 ? "Yes" : ""
},
{ key: "created_at", title: "Created", sortable: false, align: "start" },
{
key: "update_action",
title: "Show in Side Nav",
align: "start",
field: { type: "boolean", name: "is_active" },
},
{
key: "update_action",
title: "Top Level",
align: "start",
field: { type: "boolean", name: "is_top_level" },
},
{ key: "actions" },
]
Step 6b: Add Toggle and Nested Table in Expandable
Update expandable configuration (after line 164):
expandable: {
updateConfig: {
update: {
route: "dashboard.project.navigation-shortcuts.update",
params: { project: props.project.slug },
key: "navigation_shortcut",
},
},
title: "Edit Shortcut",
permissions: ["super_admin"],
cards: [
{
type: "fields_list",
fieldsList: [
{
colsMd: 6,
type: "text",
name: "label",
label: "Label",
},
{
colsMd: 6,
type: "icon-selector",
name: "icon",
label: "Icon",
},
{
type: "text",
name: "navigation_path",
label: "Path",
},
{
type: "boolean",
name: "_show_children_table", // Local UI state only (not persisted)
label: "Is Parent Nav Item",
// Disabled if children already exist
disabled: (item) => item.children?.length > 0
},
],
},
// NEW: Nested data table for managing child navigation items
{
type: "data_table",
tableTitle: "Child Navigation Items",
listKey: "children", // Access children array from parent shortcut
// Only show if toggle is on OR children already exist
condition: (item) => {
return item._show_children_table === true || item.children?.length > 0;
},
headers: [
{ key: "label", title: "Label", sortable: false },
{ key: "icon", title: "Icon", sortable: false },
{ key: "navigation_path", title: "Path", sortable: false },
{ key: "created_at", title: "Created", sortable: false },
{ key: "actions" },
],
options: {
id: "child-shortcuts-table",
delete: {
route: "dashboard.project.navigation-shortcuts.destroy",
params: { project: props.project.slug },
key: "navigation_shortcut",
},
update: {
route: "dashboard.project.navigation-shortcuts.update",
params: { project: props.project.slug },
key: "navigation_shortcut",
},
// Level 3: Nested expandable for editing child items
expandable: {
updateConfig: {
update: {
route: "dashboard.project.navigation-shortcuts.update",
params: { project: props.project.slug },
key: "navigation_shortcut",
},
},
title: "Edit Child Shortcut",
permissions: ["super_admin"],
cards: [
{
type: "fields_list",
fieldsList: [
{
colsMd: 6,
type: "text",
name: "label",
label: "Label",
},
{
colsMd: 6,
type: "icon-selector",
name: "icon",
label: "Icon",
},
{
type: "text",
name: "navigation_path",
label: "Path",
},
],
},
],
},
},
// Create config for adding child shortcuts
createConfig: {
create: {
route: "dashboard.project.navigation-shortcuts.store",
params: { project: props.project.slug },
// Pass parent_id in payload
additionalData: (parentItem) => ({
parent_id: parentItem.id
})
},
itemName: "Child Shortcut",
cards: [
{
cols: 12,
fieldsList: [
{
type: "text",
name: "label",
label: "Label",
},
{
type: "text",
name: "icon",
label: "Icon",
},
{
type: "text",
name: "navigation_path",
label: "Path",
},
],
},
],
},
},
],
}
Visual Flow:
Dashboard Shortcuts Table (Level 1)
│
├─ Expand Row → Edit Shortcut Modal (Level 2)
│ ├─ Edit form fields for shortcut
│ ├─ Toggle: "Is Parent Nav Item" (shows/hides nested table)
│ └─ Nested Data Table: Child Shortcuts
│ ├─ Same columns (label, icon, path, etc.)
│ ├─ Add/Edit/Delete child shortcuts
│ └─ Each child row → Expandable (Level 3, for editing)
│
└─ "Has Children" column shows "Yes" if subitems exist
Data Flow Summary
┌─────────────────────────────────────────────────────────────┐
│ 1. PLUGIN PLAN JSON │
│ navigation_shortcuts with subitems array │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 2. PluginPlan::processNavigationShortcuts() │
│ Recursively creates shortcuts with parent_id │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 3. DATABASE (Flat Structure) │
│ | id | parent_id | label | order | is_top_level | │
│ | 1 | NULL | "GXPrint" | 6 | true | │
│ | 2 | 1 | "Connections"| 1 | false | │
│ | 3 | 1 | "Jobs" | 2 | false | │
│ | 4 | 1 | "Analytics" | 3 | false | │
└─────────────────────────────────────────────────────────────┘
↓
┌─────── ──────────────────────────────────────────────────────┐
│ 4. Project::getTopShortcutsTreeAttribute() │
│ Single query → TreeBuilder::buildTree() → Nested struct │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 5. INERTIA PROPS (to Vue) │
│ project.top_shortcuts = [ │
│ { │
│ id: 1, │
│ label: "GXPrint", │
│ children: [ │
│ { id: 2, label: "Connections", ... }, │
│ { id: 3, label: "Jobs", ... }, │
│ { id: 4, label: "Analytics", ... } │
│ ] │
│ } │
│ ] │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 6. AppNavigation.js::mapShortcutToNavItem() │
│ Recursively maps to {title, icon, href, children} │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 7. BaseNavItem + BaseNavSubItem Components │
│ Renders dropdown with nested children (already supports) │
└─────────────────────────────────────────────────────────────┘
Key Performance Note: Only ONE database query is executed. Tree building happens in-memory using TreeBuilder utility.
Testing Checklist
Backend Tests
-
TreeBuilderTest::testFlatArray()- Flat array returns root items -
TreeBuilderTest::testNestedItems()- 2-3 levels of nesting -
TreeBuilderTest::testMixedOrder()- Respectsorderfield at each level -
TreeBuilderTest::testEmptyArray()- Returns empty array - Plugin plan processing with
subitemscreates correct parent_id - Database cascade delete (deleting parent removes children)
- Validation rules accept valid
parent_id - Validation rules reject invalid
parent_id
Frontend Tests
- Shortcuts without children render as before (backward compatibility)
- Shortcuts with children render dropdown in side nav
- Clicking parent opens dropdown with children
- Nested data table appears in Edit Shortcut modal
- Toggle "Is Parent Nav Item" shows/hides nested table
- Toggle disabled when children exist
- Create child shortcut includes
parent_id - Edit child shortcut works in nested expandable
- Delete parent cascades to children (UI updates)
- "Has Children" column shows "Yes" correctly
Integration Tests
- GXPrint example from ticket renders correctly
- Navigation paths generated correctly for children
- Ordering respects
orderfield at each nesting level - Parent without route renders as non-clickable section header
- Multiple top-level parents with children work simultaneously
- Visual regression: existing projects without nested items unchanged
Edge Cases
- Parent with
routeand children (clickable parent + dropdown) - Parent without
route(section header only) - Deep nesting (3+ levels) - should work but document recommended max depth
- Shortcuts with
ordermissing fall back to natural array order - Mixed: some flat shortcuts, some with children
Files to Create/Modify
New Files (3)
database/migrations/YYYY_MM_DD_HHMMSS_add_parent_id_to_project_navigation_shortcuts.phpapp/Helpers/TreeBuilder.phptests/Unit/Helpers/TreeBuilderTest.php
Modified Files (5)
app/Models/ProjectNavigationShortcut.php- Addparent_idto fillable and validationapp/Models/Project.php- AddgetTopShortcutsTreeAttribute()accessorapp/Models/PluginPlan.php- AddprocessNavigationShortcuts()recursive methodresources/js/Dashboard/Layouts/Partials/AppNavigation.js- AddmapShortcutToNavItem()functionresources/js/Dashboard/Pages/Admin/Projects/Show.vue- Add nested data table and toggle
Acceptance Criteria
- ✅ Config supports optional
subitemsarray on any side-nav item - ✅ AppNavigation renders parent with collapsible children (at least one nesting level)
- ✅ Children inherit same behavior as parents: icon, label, route+params → href built by backend
- ✅ Ordering respects
orderfield; missing order preserves natural array order - ✅ Existing projects without
subitemsrender exactly as before (backward compatible) - ✅ GXPrint example renders as:
- GXPrint (parent, clickable dropdown)
- Print Connections
- Jobs Monitor
- Analytics
- GXPrint (parent, clickable dropdown)
- ✅ Admin UI supports:
- "Has Children" column in main table
- Toggle to show/hide nested child table
- Nested data table for managing children
- Full CRUD on child shortcuts
- Nested expandable for editing children
Notes & Scope
Architecture Benefits
- Single Query Performance: All shortcuts loaded in one query; tree built in-memory
- No N+1 Queries: Avoids relationship lazy-loading performance issues
- Reusable Utility:
TreeBuildercan be used for other hierarchical data - Clean Separation: Tree logic isolated from business logic
Out of Scope (Future Enhancements)
- Reordering with nested items: Current
ProjectNavigationShortcutReorderActiondoesn't account for parent context. Mark as TODO.- Future: Reordering should only affect siblings (same
parent_id) - Need to pass parent context to reorder action
- Future: Reordering should only affect siblings (same
- Drag-and-drop between parent/child: Requires more complex UI
- Max nesting depth enforcement: Currently unlimited; recommend documenting 1-2 levels as best practice
Styling/UX Assumptions
- Expand/collapse UI handled by existing
BaseNavItem/BaseNavSubItemcomponents - No custom styling required for nested dropdowns
- Nested data tables use same styling as parent table
Backward Compatibility Guarantees
- All changes are additive and non-breaking
parent_idis nullable - existing shortcuts continue working- Config consumers without
subitemsunaffected - No changes to existing API routes or responses
- Frontend components already support
childrenarrays
Implementation Order
Recommended sequence to minimize dependencies:
- Database + Tests → Migration, TreeBuilder, TreeBuilderTest
- Models → ProjectNavigationShortcut, Project accessor
- Plugin Plan → processNavigationShortcuts() method
- Frontend Nav → AppNavigation.js mapping function
- Admin UI → Projects/Show.vue nested table
- Integration Testing → End-to-end verification
- Documentation → Update plugin plan examples
Related Documentation
- Plugin Plans: See
database/seeders/templates/plugin_plans/*/plan.jsonfor examples - Side Navigation: AppLayoutSidebar.vue (repository reference:
/resources/js/Dashboard/Layouts/Partials/AppLayoutSidebar.vue) - Data Tables: ModDataTable.vue (repository reference:
/resources/js/Components/Mod/DataTable.vue) - Conditional Rendering: useConditionParams.js (repository reference:
/resources/js/Composables/useConditionParams.js)
Estimated Effort
- Backend Implementation: 4-6 hours
- Frontend Navigation: 2-3 hours
- Admin UI: 3-4 hours
- Testing: 3-4 hours
- Total: ~12-17 hours
Questions for Review
- Should we enforce a maximum nesting depth? (Recommend documenting 1-2 levels as best practice)
- Do we need to handle reordering for nested items in this ticket, or defer to future work?
- Should parents with children be clickable themselves, or only dropdown triggers?
- Answer: Support both - if parent has
route, it's clickable; if not, it's just a section header
- Answer: Support both - if parent has