Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ sqlalchemy>=2.0.25
alembic>=1.13.1
asyncpg>=0.29.0
psycopg2-binary>=2.9.9
passlib[bcrypt]>=1.7.4
bcrypt>=4.0.0,<5.0.0
aiosqlite>=0.17.0

# Authentication & Security
passlib[bcrypt]>=1.7.4
# Pin bcrypt to 4.0.1 to avoid incompatibility with passlib 1.7.4
# See: https://github.com/pyca/bcrypt/issues/684
bcrypt==4.0.1
python-jose[cryptography]>=3.3.0
argon2-cffi>=23.1.0
cryptography>=3.4.0

# HTTP Client
httpx>=0.26.0
Expand Down Expand Up @@ -79,4 +84,13 @@ langchain-aws>=0.1.0
boto3>=1.34.0
azure-identity>=1.15.0
azure-core>=1.30.0
ollama>=0.1.0
ollama>=0.1.0

# ===========================================
# Testing
# ===========================================
pytest>=7.0.0
pytest-asyncio>=0.21.0
pytest-cov>=4.1.0
pytest-dotenv>=0.5.2
Faker>=18.0.0
160 changes: 74 additions & 86 deletions web/src/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { NavLink, Link } from 'react-router-dom';
import {
LayoutDashboard, FolderKanban, CheckSquare, MessageSquare, StickyNote,
Timer, Bot, Users, Shield, Settings, LogOut, Cpu, HardDrive
} from 'lucide-react';
import * as LucideIcons from 'lucide-react';
import { useAuth } from '../../context/AuthContext';
import { uiService, UIMenu, UIMenuItem } from '../../services/ui';
import './Sidebar.css';

// Map icon string names to actual components
const IconMap: Record<string, React.ElementType> = {
...LucideIcons
};

interface SidebarProps {
isOpen: boolean;
setIsOpen: (isOpen: boolean) => void;
Expand All @@ -16,53 +19,28 @@ interface SidebarProps {

export function Sidebar({ isOpen, mobileOpen, setMobileOpen }: SidebarProps) {
const { hasRole, logout } = useAuth();

interface NavItem {
icon: React.ElementType;
label: string;
path: string;
roles?: string[];
}

interface NavSection {
title: string;
items: NavItem[];
roles?: string[];
}

const sections: NavSection[] = [
{
title: 'Main',
items: [
{ icon: LayoutDashboard, label: 'Dashboard', path: '/dashboard' },
{ icon: FolderKanban, label: 'Projects', path: '/projects' },
{ icon: CheckSquare, label: 'Tasks', path: '/tasks' },
{ icon: MessageSquare, label: 'Chat', path: '/chat' },
{ icon: StickyNote, label: 'Notes', path: '/notes' },
]
},
{
title: 'Tools',
items: [
{ icon: Timer, label: 'Time Tracking', path: '/tracking' },
{ icon: Bot, label: 'AI Agents', path: '/ai/agents', roles: ['ADMIN', 'Admin', 'AI_ENGINEER', 'SuperUser'] },
{ icon: Cpu, label: 'AI Models', path: '/ai/models', roles: ['ADMIN', 'Admin', 'SuperUser', 'STAFF'] },
{ icon: HardDrive, label: 'Local Models', path: '/ai/local-models', roles: ['ADMIN', 'Admin', 'SuperUser', 'STAFF'] },
]
},
{
title: 'Admin',
roles: ['ADMIN', 'Admin', 'SuperUser'],
items: [
{ icon: Users, label: 'Users', path: '/admin/users' },
{ icon: Shield, label: 'Roles & Permissions', path: '/admin/roles' },
]
}
];
const [menuData, setMenuData] = useState<UIMenu | null>(null);
const [loading, setLoading] = useState(true);

useEffect(() => {
const fetchMenu = async () => {
try {
const data = await uiService.getMenu('sidebar');
setMenuData(data);
} catch (error) {
console.error("Failed to load sidebar menu:", error);
// Fallback hardcoded menu could be added here if needed
} finally {
setLoading(false);
}
};

fetchMenu();
}, []);

const canAccess = (roles?: string[]) => {
if (!roles || roles.length === 0) return true;
return roles.some(role => hasRole(role));
return roles.some((role: string) => hasRole(role));
};

const handleLinkClick = () => {
Expand All @@ -71,6 +49,13 @@ export function Sidebar({ isOpen, mobileOpen, setMobileOpen }: SidebarProps) {
}
};

// Helper to render icon dynamically
const renderIcon = (iconName?: string) => {
if (!iconName) return <LucideIcons.Circle size={20} className="nav-icon" />;
const IconComponent = IconMap[iconName] || LucideIcons.HelpCircle;
return <IconComponent size={20} className="nav-icon" />;
};

return (
<>
{/* Mobile Overlay */}
Expand All @@ -85,47 +70,50 @@ export function Sidebar({ isOpen, mobileOpen, setMobileOpen }: SidebarProps) {
<img src="/logo.png" alt="WorkSynapse" className="logo-icon" style={{ background: 'transparent' }} />
<span className={`logo-text ${!isOpen ? 'hidden' : ''}`}>WorkSynapse</span>
</Link>

{/* Sidebar Toggle - Moved to Header */}
</div>

<div className="sidebar-content">
{sections.map((section, idx) => {
if (section.roles && !canAccess(section.roles)) return null;

return (
<div key={idx} className="nav-section">
<div className="nav-section-header">
<span className="section-title">{section.title}</span>
<div className="section-divider"></div>
{loading ? (
<div className="p-4 text-gray-400">Loading menu...</div>
) : (
menuData?.items.map((section) => {
// Top level items without parent are sections
if (section.roles && !canAccess(section.roles)) return null;

return (
<div key={section.id} className="nav-section">
<div className="nav-section-header">
<span className="section-title">{section.label}</span>
<div className="section-divider"></div>
</div>

<ul className="nav-list">
{section.children?.map(item => {
if (item.roles && !canAccess(item.roles)) return null;

return (
<li key={item.id}>
<NavLink
to={item.path || '#'}
className={({ isActive }) =>
`nav-item ${isActive ? 'active' : ''}`
}
onClick={handleLinkClick}
>
{renderIcon(item.icon)}
<span className="nav-label">{item.label}</span>

{/* Tooltip for collapsed state */}
{!isOpen && <div className="nav-tooltip">{item.label}</div>}
</NavLink>
</li>
);
})}
</ul>
</div>

<ul className="nav-list">
{section.items.map(item => {
if (item.roles && !canAccess(item.roles)) return null;

return (
<li key={item.path}>
<NavLink
to={item.path}
className={({ isActive }) =>
`nav-item ${isActive ? 'active' : ''}`
}
onClick={handleLinkClick}
>
<item.icon size={20} className="nav-icon" />
<span className="nav-label">{item.label}</span>

{/* Tooltip for collapsed state */}
{!isOpen && <div className="nav-tooltip">{item.label}</div>}
</NavLink>
</li>
);
})}
</ul>
</div>
);
})}
);
})
)}
</div>

<div className="sidebar-footer">
Expand Down
40 changes: 40 additions & 0 deletions web/src/services/ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* UI Service
* ==========
* Fetches dynamic UI configuration from the backend.
*/
import { api } from './apiClient';

// Interfaces matching the backend schemas
export interface UIMenuItem {
id: number;
label: string;
path?: string;
icon?: string;
order: number;
roles?: string[];
children?: UIMenuItem[];
}

export interface UIMenu {
id: number;
name: string;
description?: string;
items: UIMenuItem[];
}

export const uiService = {
/**
* Get a menu structure by name (e.g., 'sidebar')
*/
getMenu: async (name: string): Promise<UIMenu> => {
return api.get<UIMenu>(`/ui/menus/${name}`);
},

/**
* Get a page configuration by slug
*/
getPage: async (slug: string) => {
return api.get(`/ui/pages/${slug}`);
}
};
Loading