Files
Joshen Lim 073cada53a Fix observability custom reports menu item (#47759)
## Context

More action button should be flushed to the right here
<img width="294" height="156" alt="image"
src="https://github.com/user-attachments/assets/65017960-3edb-4268-bb0e-1e2c26937d4b"
/>

## Changes involved
- Adjust `Menu.Item` in `packages/ui` to use a `div` instead of a `span`
- Was otherwise causing HTML validation issues as we were trying to nest
a `div` within a `span`
- Having a `div` is a bit more flexible as well since `Menu.Item`
expects `children` to be of any type (e.g a react node)

<img width="279" height="149" alt="image"
src="https://github.com/user-attachments/assets/12730cef-b077-4ef4-93c9-c21def939888"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Standardized the Observability menu component to use named exports,
ensuring consistent usage across the app.
* Updated the mobile observability menu registration to reference the
correct exported component.
* **Style**
* Refined Observability menu item layout, spacing, truncation, and
dropdown sizing for a cleaner presentation.
* Enhanced menu item rendering to allow custom `className` styling and
full-width content layout.
* **Accessibility**
* Added an aria-label to the “more actions” button for improved screen
reader support.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-09 17:08:11 +08:00

113 lines
3.0 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { Edit2, MoreVertical, Trash } from 'lucide-react'
import Link from 'next/link'
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
Menu,
} from 'ui'
import { ContentBase } from '@/data/content/content-query'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useProfile } from '@/lib/profile'
import type { Dashboards } from '@/types'
interface ReportMenuItemProps {
item: {
id?: string
name: string
description: string
key: string
url: string
hasDropdownActions: boolean
report: ContentBase & {
type: 'report'
content: Dashboards.Content
}
}
pageKey: string
onSelectEdit: () => void
onSelectDelete: () => void
}
export const ObservabilityMenuItem = ({
item,
pageKey,
onSelectEdit,
onSelectDelete,
}: ReportMenuItemProps) => {
const { profile } = useProfile()
const { can: canUpdateCustomReport } = useAsyncCheckPermissions(
PermissionAction.UPDATE,
'user_content',
{
resource: {
type: 'report',
visibility: item.report.visibility,
owner_id: item.report.owner_id,
},
subject: { id: profile?.id },
}
)
const menuItem = (
<Menu.Item active={item.key === pageKey} className="pr-2.5">
<div className="flex w-full items-center justify-between gap-1">
<p className="truncate w-full">{item.name}</p>
{canUpdateCustomReport && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
aria-label="More actions"
variant="text"
className="px-0.5 h-[20px] opacity-50 hover:opacity-100"
icon={<MoreVertical size={12} strokeWidth={2} />}
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
}}
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-44 *:gap-x-2">
<DropdownMenuItem
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
if (!item.id) return
onSelectEdit()
}}
>
<Edit2 size={12} />
<div>Rename report</div>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
if (!item.id) return
onSelectDelete()
}}
>
<Trash size={12} />
<div>Delete report</div>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)}
</div>
</Menu.Item>
)
return (
<Link key={item.key + '-menukey'} href={item.url} className="block">
{menuItem}
</Link>
)
}