mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 15:19:08 +03:00
## Context This is largely just a mechanical change here: Opting to use lucide icons with the `Icon` suffix across all icon imports within `studio` - so that it’s clearer which components are icons + reduces the possibility of name collision with our own components - e.g <User /> vs <UserIcon /> Also added a eslint rule for this: <img width="1069" height="167" alt="image" src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc" /> And updated `AGENTS.md` as such: ``` Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced). ```
141 lines
4.8 KiB
TypeScript
141 lines
4.8 KiB
TypeScript
import { FilesBucket as FilesBucketIcon } from 'icons'
|
|
import { ChevronRightIcon } from 'lucide-react'
|
|
import { KeyboardEventHandler, MouseEventHandler } from 'react'
|
|
import { Badge, cn, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
|
|
import type { AllowedBucketType } from './types'
|
|
import { PUBLIC_BUCKET_TOOLTIP } from '@/components/interfaces/Storage/Storage.constants'
|
|
import { useBucketPolicyCount } from '@/components/interfaces/Storage/useBucketPolicyCount'
|
|
import { VirtualizedTableCell, VirtualizedTableRow } from '@/components/ui/VirtualizedTable'
|
|
import { Bucket } from '@/data/storage/buckets-query'
|
|
import { formatBytes } from '@/lib/helpers'
|
|
|
|
type BucketTableMode = 'standard' | 'virtualized'
|
|
|
|
type BucketTableRowProps = {
|
|
mode: BucketTableMode
|
|
bucket: Bucket
|
|
onSelectBucket: (bucket: Bucket) => void
|
|
allowedBucketType: AllowedBucketType
|
|
formattedGlobalUploadLimit: string
|
|
}
|
|
|
|
export const BucketTableRow = ({
|
|
mode,
|
|
bucket,
|
|
onSelectBucket,
|
|
allowedBucketType,
|
|
formattedGlobalUploadLimit,
|
|
}: BucketTableRowProps) => {
|
|
const { getPolicyCount } = useBucketPolicyCount()
|
|
|
|
const BucketTableRow = mode === 'standard' ? TableRow : VirtualizedTableRow
|
|
const BucketTableCell = mode === 'standard' ? TableCell : VirtualizedTableCell
|
|
|
|
const isDisabled = !(
|
|
allowedBucketType === 'all' ||
|
|
(allowedBucketType === 'public' && bucket.public) ||
|
|
(allowedBucketType === 'private' && !bucket.public)
|
|
)
|
|
|
|
const handleRowActivate: MouseEventHandler<HTMLTableRowElement> = (e) => {
|
|
e.preventDefault()
|
|
if (isDisabled) return
|
|
onSelectBucket(bucket)
|
|
}
|
|
|
|
const handleRowKeyDown: KeyboardEventHandler<HTMLTableRowElement> = (e) => {
|
|
if (isDisabled) return
|
|
if (e.key === 'Enter' || e.key === ' ') {
|
|
e.preventDefault()
|
|
onSelectBucket(bucket)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<BucketTableRow
|
|
key={bucket.id}
|
|
data-bucket-id={bucket.id}
|
|
className={cn(
|
|
'relative cursor-pointer h-16 group focus-inset',
|
|
isDisabled && 'opacity-50 [&>td]:hover:bg-transparent cursor-not-allowed'
|
|
)}
|
|
onClick={handleRowActivate}
|
|
onKeyDown={handleRowKeyDown}
|
|
tabIndex={isDisabled ? -1 : 0}
|
|
aria-disabled={isDisabled || undefined}
|
|
>
|
|
<BucketTableCell className="w-2 pr-1">
|
|
<FilesBucketIcon aria-label="bucket icon" size={16} className="text-foreground-muted" />
|
|
</BucketTableCell>
|
|
<BucketTableCell className="flex-1">
|
|
<div className="flex items-center gap-2.5">
|
|
<p className="whitespace-nowrap max-w-[512px] truncate">{bucket.id}</p>
|
|
{bucket.public && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Badge variant="warning" className="flex">
|
|
Public
|
|
</Badge>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="top">{PUBLIC_BUCKET_TOOLTIP}</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</BucketTableCell>
|
|
|
|
<BucketTableCell>
|
|
<p className="text-foreground-light">{getPolicyCount(bucket.id)}</p>
|
|
</BucketTableCell>
|
|
|
|
<BucketTableCell>
|
|
<p
|
|
className={`whitespace-nowrap ${bucket.file_size_limit ? 'text-foreground-light' : 'text-foreground-muted'}`}
|
|
>
|
|
{bucket.file_size_limit
|
|
? formatBytes(bucket.file_size_limit)
|
|
: `Unset (${formattedGlobalUploadLimit})`}
|
|
</p>
|
|
</BucketTableCell>
|
|
|
|
<BucketTableCell>
|
|
<p
|
|
className={
|
|
bucket.allowed_mime_types ? 'text-foreground-light' : 'text-foreground-muted'
|
|
}
|
|
>
|
|
{bucket.allowed_mime_types ? bucket.allowed_mime_types.join(', ') : 'Any'}
|
|
</p>
|
|
</BucketTableCell>
|
|
|
|
<BucketTableCell>
|
|
{!isDisabled && (
|
|
<>
|
|
<div className="flex justify-end items-center h-full">
|
|
<ChevronRightIcon
|
|
aria-hidden={true}
|
|
size={14}
|
|
className="text-foreground-muted/60"
|
|
/>
|
|
</div>
|
|
<button tabIndex={-1} className="sr-only">
|
|
Go to bucket details
|
|
</button>
|
|
</>
|
|
)}
|
|
</BucketTableCell>
|
|
</BucketTableRow>
|
|
</TooltipTrigger>
|
|
{isDisabled && (
|
|
<TooltipContent>
|
|
{allowedBucketType === 'public'
|
|
? 'Private buckets are not selectable for this action. Please select a public bucket.'
|
|
: 'Public buckets are not selectable for this action. Please select a private bucket.'}
|
|
</TooltipContent>
|
|
)}
|
|
</Tooltip>
|
|
)
|
|
}
|