Skip to content

Commit eb3e177

Browse files
committed
Refactor icon retrieval in AppSidebar to utilize LucideIcons; streamline fallback logic
1 parent 97c03fa commit eb3e177

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

apps/console/src/components/AppSidebar.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import { useLocation, Link } from 'react-router-dom';
3+
import * as LucideIcons from 'lucide-react';
34
import {
45
Sidebar,
56
SidebarHeader,
@@ -42,21 +43,27 @@ import {
4243
} from 'lucide-react';
4344
import appConfig from '../../objectstack.config';
4445

45-
// Icon Map
46-
const ICONS: Record<string, any> = {
47-
'dashboard': LayoutDashboard,
48-
'users': Users,
49-
'user': Users,
50-
'check-square': CheckSquare,
51-
'activity': Activity,
52-
'briefcase': Briefcase,
53-
'file-text': FileText,
54-
'database': Database,
55-
};
56-
46+
// Helper to get icon from Lucide
5747
function getIcon(name?: string) {
58-
if (!name) return Database;
59-
return ICONS[name] || Database;
48+
if (!name) return LucideIcons.Database;
49+
50+
// 1. Try direct match (e.g. if user passed "User")
51+
if ((LucideIcons as any)[name]) {
52+
return (LucideIcons as any)[name];
53+
}
54+
55+
// 2. Try converting kebab-case to PascalCase (e.g. "shopping-cart" -> "ShoppingCart")
56+
const pascalName = name
57+
.split('-')
58+
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
59+
.join('');
60+
61+
if ((LucideIcons as any)[pascalName]) {
62+
return (LucideIcons as any)[pascalName];
63+
}
64+
65+
// 3. Fallback
66+
return LucideIcons.Database;
6067
}
6168

6269
export function AppSidebar({ activeAppName, onAppChange }: { activeAppName: string, onAppChange: (name: string) => void }) {
@@ -89,10 +96,8 @@ export function AppSidebar({ activeAppName, onAppChange }: { activeAppName: stri
8996
{/* App Logo - use branding logo if available */}
9097
{logo ? (
9198
<img src={logo} alt={activeApp.label} className="size-6 object-contain" />
92-
) : activeApp.icon ? (
93-
React.createElement(getIcon(activeApp.icon), { className: "size-4" })
9499
) : (
95-
<Database className="size-4" />
100+
React.createElement(getIcon(activeApp.icon), { className: "size-4" })
96101
)}
97102
</div>
98103
<div className="grid flex-1 text-left text-sm leading-tight">

0 commit comments

Comments
 (0)