# Admin Sidebar Navigation
## Overview
The admin sidebar provides navigation across all admin pages. It features collapsible sections with state persistence, active page indicators, and responsive mobile support.
**File Location:** `app/templates/admin/partials/sidebar.html`
---
## Sidebar Structure
The sidebar is organized into the following sections:
| Section | Collapsible | Pages |
|---------|-------------|-------|
| Dashboard | No | Dashboard |
| Platform Administration | Yes | Companies, Vendors, Users, Customers |
| Product Catalog | Yes | Marketplace Products, Vendor Products, Import |
| Content Management | Yes | Platform Homepage, Content Pages, Vendor Themes |
| Developer Tools | Yes | Components, Icons |
| Platform Health | Yes | Testing Hub, Code Quality, Background Tasks |
| Platform Monitoring | Yes | Import Jobs, Application Logs |
| Settings | Yes | General, Profile, API Keys, Notifications |
---
## Collapsible Sections
### How It Works
Sections can be expanded/collapsed by clicking the section header. The state is persisted to `localStorage` so sections remain open/closed across page navigation and browser sessions.
### State Management
**File:** `static/admin/js/init-alpine.js`
```javascript
// Default state: Platform Administration open, others closed
const defaultSections = {
platformAdmin: true,
productCatalog: false,
contentMgmt: false,
devTools: false,
platformHealth: false,
monitoring: false,
settingsSection: false
};
// State stored in localStorage under this key
const SIDEBAR_STORAGE_KEY = 'admin_sidebar_sections';
```
### Available Methods
| Method | Description |
|--------|-------------|
| `toggleSection(section)` | Toggle a section open/closed |
| `expandSectionForCurrentPage()` | Auto-expand section containing current page |
| `openSections.platformAdmin` | Check if Platform Administration is open |
| `openSections.productCatalog` | Check if Product Catalog is open |
| `openSections.contentMgmt` | Check if Content Management is open |
| `openSections.devTools` | Check if Developer Tools is open |
| `openSections.platformHealth` | Check if Platform Health is open |
| `openSections.monitoring` | Check if Platform Monitoring is open |
| `openSections.settingsSection` | Check if Settings is open |
### CSS Transitions
Sections animate smoothly using CSS transitions (no plugins required):
```html
```
### Chevron Icon Rotation
The chevron icon rotates 180 degrees when a section is expanded:
```html
```
---
## Page-to-Section Mapping
Pages are mapped to their parent sections for auto-expansion:
```javascript
const pageSectionMap = {
// Platform Administration
companies: 'platformAdmin',
vendors: 'platformAdmin',
users: 'platformAdmin',
customers: 'platformAdmin',
// Product Catalog
'marketplace-products': 'productCatalog',
'vendor-products': 'productCatalog',
marketplace: 'productCatalog',
// Content Management
'platform-homepage': 'contentMgmt',
'content-pages': 'contentMgmt',
'vendor-theme': 'contentMgmt',
// Developer Tools
components: 'devTools',
icons: 'devTools',
// Platform Health
testing: 'platformHealth',
'code-quality': 'platformHealth',
'background-tasks': 'platformHealth',
// Platform Monitoring
imports: 'monitoring',
logs: 'monitoring',
// Settings
settings: 'settingsSection',
profile: 'settingsSection',
'api-keys': 'settingsSection',
'notifications-settings': 'settingsSection'
};
```
---
## Complete Page Mapping
| Page | `currentPage` Value | Section | URL |
|------|---------------------|---------|-----|
| Dashboard | `'dashboard'` | (always visible) | `/admin/dashboard` |
| Companies | `'companies'` | Platform Administration | `/admin/companies` |
| Vendors | `'vendors'` | Platform Administration | `/admin/vendors` |
| Users | `'users'` | Platform Administration | `/admin/users` |
| Customers | `'customers'` | Platform Administration | `/admin/customers` |
| Marketplace Products | `'marketplace-products'` | Product Catalog | `/admin/marketplace-products` |
| Vendor Products | `'vendor-products'` | Product Catalog | `/admin/vendor-products` |
| Import | `'marketplace'` | Product Catalog | `/admin/marketplace` |
| Platform Homepage | `'platform-homepage'` | Content Management | `/admin/platform-homepage` |
| Content Pages | `'content-pages'` | Content Management | `/admin/content-pages` |
| Vendor Themes | `'vendor-theme'` | Content Management | `/admin/vendor-themes` |
| Components | `'components'` | Developer Tools | `/admin/components` |
| Icons | `'icons'` | Developer Tools | `/admin/icons` |
| Testing Hub | `'testing'` | Platform Health | `/admin/testing` |
| Code Quality | `'code-quality'` | Platform Health | `/admin/code-quality` |
| Background Tasks | `'background-tasks'` | Platform Health | `/admin/background-tasks` |
| Import Jobs | `'imports'` | Platform Monitoring | `/admin/imports` |
| Application Logs | `'logs'` | Platform Monitoring | `/admin/logs` |
| General Settings | `'settings'` | Settings | `/admin/settings` |
| Profile | `'profile'` | Settings | `/admin/profile` |
| API Keys | `'api-keys'` | Settings | `/admin/api-keys` |
| Notifications | `'notifications-settings'` | Settings | `/admin/notifications-settings` |
---
## Active Page Indicator
Each menu item shows a purple vertical bar when active:
```html
-
Vendors
```
### Setting currentPage in Components
Each page component must set `currentPage` to match the sidebar:
```javascript
function adminVendors() {
return {
...data(), // Inherit base (includes openSections)
currentPage: 'vendors', // Must match sidebar check
// ... rest of component
};
}
```
---
## Jinja2 Macros
The sidebar uses Jinja2 macros for DRY code:
### section_header
Creates a collapsible section header with chevron:
```jinja2
{% macro section_header(title, section_key) %}
{% endmacro %}
```
### section_content
Wraps section items with collapse animation:
```jinja2
{% macro section_content(section_key) %}
{% endmacro %}
```
### menu_item
Creates a menu item with active indicator:
```jinja2
{% macro menu_item(page_id, url, icon, label) %}
-
{{ label }}
{% endmacro %}
```
### Usage Example
```jinja2
{{ section_header('Platform Administration', 'platformAdmin') }}
{% call section_content('platformAdmin') %}
{{ menu_item('companies', '/admin/companies', 'office-building', 'Companies') }}
{{ menu_item('vendors', '/admin/vendors', 'shopping-bag', 'Vendors') }}
{% endcall %}
```
---
## Adding a New Page
### Step 1: Add Route
Add the route in `app/routes/admin_pages.py`:
```python
@router.get("/new-page", response_class=HTMLResponse, include_in_schema=False)
async def admin_new_page(
request: Request,
current_user: User = Depends(get_current_admin_from_cookie_or_header),
):
return templates.TemplateResponse(
"admin/new-page.html",
{"request": request, "user": current_user},
)
```
### Step 2: Create Template
Create `app/templates/admin/new-page.html`:
```jinja2
{% extends "admin/base.html" %}
{% block title %}New Page{% endblock %}
{% block alpine_data %}adminNewPage(){% endblock %}
{% block content %}
{% endblock %}
```
### Step 3: Create JavaScript Component
Create `static/admin/js/new-page.js`:
```javascript
function adminNewPage() {
return {
...data(),
currentPage: 'new-page', // Must match sidebar
// ...
};
}
```
### Step 4: Add to Sidebar
Edit `app/templates/admin/partials/sidebar.html`:
```jinja2
{# Add to appropriate section #}
{{ menu_item('new-page', '/admin/new-page', 'icon-name', 'New Page') }}
```
### Step 5: Update Page-Section Map (if in collapsible section)
Edit `static/admin/js/init-alpine.js`:
```javascript
const pageSectionMap = {
// ... existing mappings
'new-page': 'platformAdmin', // Add mapping
};
```
---
## Mobile Sidebar
The sidebar has a mobile version that slides in from the left:
- **Toggle:** Click hamburger menu in header
- **Close:** Click outside, press Escape, or navigate
- **State:** Controlled by `isSideMenuOpen`
```javascript
// In base data()
isSideMenuOpen: false,
toggleSideMenu() {
this.isSideMenuOpen = !this.isSideMenuOpen
},
closeSideMenu() {
this.isSideMenuOpen = false
}
```
---
## Testing Checklist
- [ ] Sections expand/collapse on header click
- [ ] Chevron rotates when section opens/closes
- [ ] Section state persists after page reload
- [ ] Section state persists across different pages
- [ ] Active page shows purple bar indicator
- [ ] Active page text is highlighted
- [ ] Mobile sidebar opens/closes correctly
- [ ] Collapsible sections work on mobile
- [ ] All navigation links work correctly