chore: finish workspace cleanup
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
HeartPulse,
|
||||
LayoutDashboard,
|
||||
ListChecks,
|
||||
LockKeyhole,
|
||||
Radio,
|
||||
Settings,
|
||||
ShieldAlert,
|
||||
@@ -49,7 +50,15 @@ type AppSidebarNavProps = {
|
||||
permissions: Permission[];
|
||||
};
|
||||
|
||||
type SidebarNavItem = NavItem & {
|
||||
canAccess: boolean;
|
||||
};
|
||||
|
||||
function canViewNavItem(item: NavItem, permissions: readonly Permission[]): boolean {
|
||||
if (permissions.includes("platform:manage")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.permission && !permissions.includes(item.permission)) {
|
||||
return false;
|
||||
}
|
||||
@@ -63,12 +72,13 @@ function canViewNavItem(item: NavItem, permissions: readonly Permission[]): bool
|
||||
|
||||
export function AppSidebarNav({ organizationSlug, permissions }: AppSidebarNavProps): React.ReactElement {
|
||||
const pathname = usePathname();
|
||||
const visibleNavGroups = navGroups
|
||||
.map((group) => ({
|
||||
...group,
|
||||
items: group.items.filter((item) => canViewNavItem(item, permissions)),
|
||||
}))
|
||||
.filter((group) => group.items.length > 0);
|
||||
const visibleNavGroups = navGroups.map((group): { label: string; items: SidebarNavItem[] } => ({
|
||||
...group,
|
||||
items: group.items.map((item) => ({
|
||||
...item,
|
||||
canAccess: canViewNavItem(item, permissions),
|
||||
})),
|
||||
}));
|
||||
|
||||
return (
|
||||
<nav className="min-h-0 flex-1 overflow-y-auto px-3 py-4" aria-label="主导航">
|
||||
@@ -80,29 +90,42 @@ export function AppSidebarNav({ organizationSlug, permissions }: AppSidebarNavPr
|
||||
{group.items.map((item) => {
|
||||
const Icon = iconMap[item.icon];
|
||||
const href = getWorkspaceHref(organizationSlug, item.path);
|
||||
const isActive = isWorkspacePathActive(pathname, item.path);
|
||||
const isActive = item.canAccess && isWorkspacePathActive(pathname, item.path);
|
||||
|
||||
return (
|
||||
<li key={item.path}>
|
||||
<Link
|
||||
href={href}
|
||||
aria-current={isActive ? "page" : undefined}
|
||||
className={cn(
|
||||
"group flex min-h-11 items-center gap-3 rounded-md px-3 text-sm transition-colors",
|
||||
isActive
|
||||
? "bg-primary text-primary-foreground shadow-sm"
|
||||
: "text-foreground hover:bg-secondary hover:text-primary",
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
{item.canAccess ? (
|
||||
<Link
|
||||
href={href}
|
||||
aria-current={isActive ? "page" : undefined}
|
||||
className={cn(
|
||||
"size-4 shrink-0 transition-colors",
|
||||
isActive ? "text-primary-foreground" : "text-muted-foreground group-hover:text-primary",
|
||||
"group flex min-h-11 items-center gap-3 rounded-md px-3 text-sm transition-colors",
|
||||
isActive
|
||||
? "bg-primary text-primary-foreground shadow-sm"
|
||||
: "text-foreground hover:bg-secondary hover:text-primary",
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="min-w-0 truncate font-medium">{item.label}</span>
|
||||
</Link>
|
||||
>
|
||||
<Icon
|
||||
className={cn(
|
||||
"size-4 shrink-0 transition-colors",
|
||||
isActive ? "text-primary-foreground" : "text-muted-foreground group-hover:text-primary",
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="min-w-0 truncate font-medium">{item.label}</span>
|
||||
</Link>
|
||||
) : (
|
||||
<span
|
||||
className="flex min-h-11 cursor-not-allowed items-center gap-3 rounded-md px-3 text-sm text-muted-foreground/70"
|
||||
aria-disabled="true"
|
||||
title="当前角色无权访问"
|
||||
>
|
||||
<Icon className="size-4 shrink-0 text-muted-foreground/60" aria-hidden="true" />
|
||||
<span className="min-w-0 flex-1 truncate font-medium">{item.label}</span>
|
||||
<LockKeyhole className="size-3.5 shrink-0 text-muted-foreground/55" aria-hidden="true" />
|
||||
<span className="sr-only">当前角色无权访问</span>
|
||||
</span>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
|
||||
Reference in New Issue
Block a user