mirror of
https://github.com/supabase/supabase.git
synced 2026-06-17 21:23:59 +08:00
## Problem Our `<Button>` component breaks the default `button` contract by redefining the `type` prop to set its variant (`primary`, `default`, etc) instead of the button type (`submit`, `button`, etc). This is confusing and forces to write more code when using it with shadcn components that expect/inject the standard button props. ## Solution - rename the `type` prop to `variant` - rename the `htmlType` prop to `type` - propagate the changes where necessary - format code ## How to test As this is just prop renaming, if it builds it's ok --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
112 lines
3.0 KiB
TypeScript
112 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}>
|
|
<div className="flex w-full items-center justify-between gap-1">
|
|
<span className="truncate">{item.name}</span>
|
|
|
|
{canUpdateCustomReport && (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="text"
|
|
className="px-1 opacity-50 hover:opacity-100"
|
|
icon={<MoreVertical size={12} strokeWidth={2} />}
|
|
onClick={(e) => {
|
|
e.preventDefault()
|
|
e.stopPropagation()
|
|
}}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="start" className="w-32 *: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>
|
|
)
|
|
}
|