Skip to content

Commit ba0ceb5

Browse files
committed
fix:permissions
1 parent 04d792a commit ba0ceb5

1 file changed

Lines changed: 16 additions & 60 deletions

File tree

‎components/app-sidebar.tsx‎

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import Link from "next/link"
44
import Image from "next/image"
55
import { usePathname } from "next/navigation"
66
import { useTranslation } from "react-i18next"
7-
import {
8-
Collapsible,
9-
CollapsibleContent,
10-
CollapsibleTrigger,
11-
} from "@/components/ui/collapsible"
7+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"
128
import { ScrollArea } from "@/components/ui/scroll-area"
139
import {
1410
Sidebar,
@@ -26,14 +22,12 @@ import {
2622
SidebarSeparator,
2723
useSidebar,
2824
} from "@/components/ui/sidebar"
29-
import {
30-
RiArrowRightSLine,
31-
RiExternalLinkLine,
32-
} from "@remixicon/react"
25+
import { RiArrowRightSLine, RiExternalLinkLine } from "@remixicon/react"
3326
import { getIconComponent } from "@/lib/icon-map"
3427
import navs from "@/config/navs"
3528
import logoImage from "@/assets/logo.svg"
3629
import type { NavItem } from "@/types/app-config"
30+
import { usePermissions } from "@/hooks/use-permissions"
3731

3832
const APP_NAME = "RustFS"
3933
const RELEASE_VERSION = process.env.NEXT_PUBLIC_VERSION ?? ""
@@ -67,9 +61,7 @@ export function AppSidebar() {
6761
const isCollapsed = state === "collapsed"
6862
const brandInitial = APP_NAME.charAt(0).toUpperCase() ?? "R"
6963

70-
// Phase 0: show all nav items (no auth/permission filtering yet)
71-
const isAdmin = true
72-
const canAccessPath = (_path: string) => true
64+
const { isAdmin, canAccessPath } = usePermissions()
7365

7466
const navGroups: NavItem[][] = []
7567
let current: NavItem[] = []
@@ -134,18 +126,8 @@ export function AppSidebar() {
134126
</div>
135127
) : (
136128
<div className="flex min-w-0 items-baseline gap-2 px-3 py-4">
137-
<Image
138-
src={logoImage}
139-
alt="RustFS"
140-
width={64}
141-
height={16}
142-
className="h-4 w-auto shrink-0"
143-
/>
144-
{RELEASE_VERSION ? (
145-
<span className="text-[10px] text-muted-foreground">
146-
v{RELEASE_VERSION}
147-
</span>
148-
) : null}
129+
<Image src={logoImage} alt="RustFS" width={64} height={16} className="h-4 w-auto shrink-0" />
130+
{RELEASE_VERSION ? <span className="text-[10px] text-muted-foreground">v{RELEASE_VERSION}</span> : null}
149131
</div>
150132
)}
151133
</Link>
@@ -174,9 +156,7 @@ export function AppSidebar() {
174156
className="gap-3"
175157
>
176158
<NavIcon name={item.icon} />
177-
<span className="flex-1 truncate">
178-
{getLabel(item)}
179-
</span>
159+
<span className="flex-1 truncate">{getLabel(item)}</span>
180160
<RiArrowRightSLine className="size-4 shrink-0 transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" />
181161
</SidebarMenuButton>
182162
</CollapsibleTrigger>
@@ -193,26 +173,15 @@ export function AppSidebar() {
193173
className="flex w-full items-center gap-2"
194174
>
195175
<NavIcon name={child.icon} />
196-
<span className="truncate">
197-
{getLabel(child)}
198-
</span>
176+
<span className="truncate">{getLabel(child)}</span>
199177
<RiExternalLinkLine className="ml-auto size-3 text-muted-foreground" />
200178
</a>
201179
</SidebarMenuSubButton>
202180
) : (
203-
<SidebarMenuSubButton
204-
asChild
205-
size="sm"
206-
isActive={isRouteActive(child)}
207-
>
208-
<Link
209-
href={normalizedTo(child)}
210-
className="flex w-full items-center gap-2"
211-
>
181+
<SidebarMenuSubButton asChild size="sm" isActive={isRouteActive(child)}>
182+
<Link href={normalizedTo(child)} className="flex w-full items-center gap-2">
212183
<NavIcon name={child.icon} />
213-
<span className="truncate">
214-
{getLabel(child)}
215-
</span>
184+
<span className="truncate">{getLabel(child)}</span>
216185
</Link>
217186
</SidebarMenuSubButton>
218187
)}
@@ -232,26 +201,15 @@ export function AppSidebar() {
232201
className="flex w-full items-center gap-3"
233202
>
234203
<NavIcon name={item.icon} />
235-
<span className="flex-1 truncate">
236-
{getLabel(item)}
237-
</span>
204+
<span className="flex-1 truncate">{getLabel(item)}</span>
238205
<RiExternalLinkLine className="size-3.5 text-muted-foreground" />
239206
</a>
240207
</SidebarMenuButton>
241208
) : (
242-
<SidebarMenuButton
243-
asChild
244-
isActive={isRouteActive(item)}
245-
tooltip={getLabel(item)}
246-
>
247-
<Link
248-
href={normalizedTo(item)}
249-
className="flex w-full items-center gap-3"
250-
>
209+
<SidebarMenuButton asChild isActive={isRouteActive(item)} tooltip={getLabel(item)}>
210+
<Link href={normalizedTo(item)} className="flex w-full items-center gap-3">
251211
<NavIcon name={item.icon} />
252-
<span className="flex-1 truncate">
253-
{getLabel(item)}
254-
</span>
212+
<span className="flex-1 truncate">{getLabel(item)}</span>
255213
</Link>
256214
</SidebarMenuButton>
257215
)}
@@ -261,9 +219,7 @@ export function AppSidebar() {
261219
))}
262220
</SidebarMenu>
263221
</SidebarGroupContent>
264-
{groupIndex !== navGroups.length - 1 ? (
265-
<SidebarSeparator className="mx-2" />
266-
) : null}
222+
{groupIndex !== navGroups.length - 1 ? <SidebarSeparator className="mx-2" /> : null}
267223
</SidebarGroup>
268224
))}
269225
</div>

0 commit comments

Comments
 (0)