mirror of
https://github.com/supabase/supabase.git
synced 2026-09-09 03:19:36 +08:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? UI / design-system consistency (accessibility). ## What is the current behavior? Keyboard focus rings are inconsistent across Studio and `packages/ui`: - Custom Button uses thick `outline` with per-variant colours (brand / grey / destructive / warning) - Form controls use muted grey rings (`ring-background-control`) - Tabs / NavMenu / Radio use soft brand `ring-ring` - Studio `.inset-focus` uses dark green `outline-brand-600` Related: [DEPR-354](https://linear.app/supabase/issue/DEPR-354). ## What is the new behavior? One shared focus recipe, exposed as Tailwind `@utility` classes in `packages/config/css/utilities.css`: | Utility | Use when | | --- | --- | | `focus-ring` | Buttons, inputs, most controls (offset ring) | | `focus-inset` | Dense/flush surfaces such as interactive table rows (renamed from `inset-focus`) | ```txt # focus-ring outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background ``` Applied on Button, shadcn form controls, Menu/NavMenu, Command palette trigger, Studio table rows, and related call sites. Documented in the design-system accessibility docs. Variants do not change focus ring colour. When the ring must appear on a different element than the focused one (e.g. Menu + ProductMenu `Link` via `group-focus-visible`, or InputGroup via `:has()`), keep an explicit ring stack. The utilities bake in `:focus-visible` on the same element. ## Additional context **Out of scope** - Full `packages/ui` / Studio / www sweep - Legacy Studio form-group green box-shadow cleanup - ESLint rule for bare `outline-none` ## Test plan Prefer Safari (“hard mode” for `tabIndex`). Expect one soft brand ring everywhere: not grey, not solid green outline. ### Design system - [ ] [Accessibility](https://design-system-git-dnywh-choreimprove-tab-focus-styles-supabase.vercel.app/design-system/docs/accessibility): recipe docs match what you see - [ ] [Button](https://design-system-git-dnywh-choreimprove-tab-focus-styles-supabase.vercel.app/design-system/docs/components/button): Tab primary / default / danger; same ring colour - [ ] [Table → Row-level navigation](https://design-system-git-dnywh-choreimprove-tab-focus-styles-supabase.vercel.app/design-system/docs/components/table#row-level-navigation): Tab an interactive row; inset outline (`focus-inset`) sits inside the row ### Studio - [ ] **Org home → table view** (`/organizations/_` or org projects): switch to the table layout, Tab onto a project row; inset outline sits inside the row (list/card view uses CardButton, not `focus-inset`) - [ ] **Project sidebar** (Database, Auth, Storage, …): Tab the main product nav links; ring follows the focused item (not the nested section menus like Tables / Roles) - [ ] **Storage → Files**: Tab a bucket row; same inset outline as org table rows - [ ] **Project Settings → General** (or Compute and Disk): Tab through inputs, checkboxes, switches, selects; same offset ring, no ring on mouse click - [ ] **Header ⌘K** (desktop width): Tab to the search control after Feedback; same soft brand `focus-ring` (was a thicker `ring-border-strong` before) - [ ] **Table Editor or SQL Editor tabs**: focus a tab, Tab to × if active; close shows a ring - [ ] **Light + dark**: ring stays visible against both backgrounds
219 lines
7.7 KiB
TypeScript
219 lines
7.7 KiB
TypeScript
import { EllipsisVertical, Pencil, Plus, Trash2 } from 'lucide-react'
|
|
import {
|
|
Badge,
|
|
Button,
|
|
Card,
|
|
CardContent,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
Skeleton,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
|
|
import type { JitUserRule } from './JitDbAccess.types'
|
|
import { getJitStatusDisplay } from './JitDbAccess.utils'
|
|
|
|
interface JitDbAccessRulesTableProps {
|
|
users: JitUserRule[]
|
|
isLoading?: boolean
|
|
canUpdate: boolean
|
|
disableActions?: boolean
|
|
allProjectMembersHaveRules?: boolean
|
|
onAddRule: () => void
|
|
onEditRule: (user: JitUserRule) => void
|
|
onDeleteRule: (user: JitUserRule) => void
|
|
}
|
|
|
|
export function JitDbAccessRulesTable({
|
|
users,
|
|
isLoading = false,
|
|
canUpdate,
|
|
disableActions = false,
|
|
allProjectMembersHaveRules = false,
|
|
onAddRule,
|
|
onEditRule,
|
|
onDeleteRule,
|
|
}: JitDbAccessRulesTableProps) {
|
|
const addDisabled = disableActions || !canUpdate || allProjectMembersHaveRules
|
|
const addRuleTooltip = !canUpdate
|
|
? 'Additional permissions required'
|
|
: allProjectMembersHaveRules
|
|
? 'All project members already have temporary access rules'
|
|
: undefined
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<Card>
|
|
<CardContent className="space-y-4 p-4">
|
|
<div className="flex items-center justify-between">
|
|
<div className="space-y-2">
|
|
<Skeleton className="h-4 w-32" />
|
|
<Skeleton className="h-4 w-64" />
|
|
</div>
|
|
<Skeleton className="h-9 w-24" />
|
|
</div>
|
|
<Skeleton className="h-32 w-full" />
|
|
</CardContent>
|
|
</Card>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Card>
|
|
<CardContent className="space-y-4 p-0">
|
|
<div className="flex items-center justify-between px-4 pb-2 pt-6">
|
|
<div>
|
|
<h3 className="text-sm text-foreground">Temporary access rules</h3>
|
|
<p className="text-sm text-foreground-light">
|
|
Manage member access, allowed roles, and expiry settings.
|
|
</p>
|
|
</div>
|
|
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="inline-flex">
|
|
<Button
|
|
variant="default"
|
|
icon={<Plus />}
|
|
onClick={onAddRule}
|
|
disabled={addDisabled}
|
|
>
|
|
Add rule
|
|
</Button>
|
|
</span>
|
|
</TooltipTrigger>
|
|
{addRuleTooltip && <TooltipContent side="bottom">{addRuleTooltip}</TooltipContent>}
|
|
</Tooltip>
|
|
</div>
|
|
|
|
<Table className="border-t">
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Member</TableHead>
|
|
<TableHead>Roles</TableHead>
|
|
<TableHead>Status</TableHead>
|
|
<TableHead className="w-1">
|
|
<span className="sr-only">Actions</span>
|
|
</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{users.length === 0 ? (
|
|
<TableRow className="[&>td]:hover:bg-inherit">
|
|
<TableCell colSpan={4}>
|
|
<p className="text-sm text-foreground">No rules yet</p>
|
|
<p className="text-sm text-foreground-lighter">
|
|
Add your first temporary access rule above
|
|
</p>
|
|
</TableCell>
|
|
</TableRow>
|
|
) : (
|
|
users.map((user) => {
|
|
const statusDisplay = getJitStatusDisplay(user.status)
|
|
const enabledGrants = user.grants.filter((grant) => grant.enabled)
|
|
const rowIsInteractive = canUpdate && !disableActions
|
|
|
|
return (
|
|
<TableRow
|
|
key={user.id}
|
|
className={rowIsInteractive ? 'relative focus-inset cursor-pointer' : undefined}
|
|
onClick={
|
|
rowIsInteractive
|
|
? (event) => {
|
|
if ((event.target as HTMLElement).closest('button')) return
|
|
onEditRule(user)
|
|
}
|
|
: undefined
|
|
}
|
|
onKeyDown={
|
|
rowIsInteractive
|
|
? (event) => {
|
|
if ((event.target as HTMLElement).closest('button')) return
|
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
event.preventDefault()
|
|
onEditRule(user)
|
|
}
|
|
}
|
|
: undefined
|
|
}
|
|
tabIndex={rowIsInteractive ? 0 : undefined}
|
|
>
|
|
<TableCell className="text-sm">
|
|
{user.name && <p>{user.name}</p>}
|
|
<p className="text-foreground-lighter">{user.email}</p>
|
|
</TableCell>
|
|
<TableCell className="text-sm text-foreground-light">
|
|
{enabledGrants.length} role{enabledGrants.length === 1 ? '' : 's'}
|
|
</TableCell>
|
|
<TableCell className="text-sm text-foreground-light">
|
|
{statusDisplay.badges.length > 0 ? (
|
|
<span className="flex flex-wrap gap-1.5">
|
|
{statusDisplay.badges.map((badge) => (
|
|
<Badge key={badge.label} variant={badge.variant}>
|
|
{badge.label}
|
|
</Badge>
|
|
))}
|
|
</span>
|
|
) : null}
|
|
</TableCell>
|
|
<TableCell className="text-right">
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
icon={<EllipsisVertical />}
|
|
aria-label="More actions"
|
|
variant="default"
|
|
size="tiny"
|
|
className="w-7 hit-area-2"
|
|
disabled={!canUpdate || disableActions}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" side="bottom" className="w-40">
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
onClick={(event) => {
|
|
event.stopPropagation()
|
|
onEditRule(user)
|
|
}}
|
|
disabled={!canUpdate || disableActions}
|
|
>
|
|
<Pencil size={14} className="text-foreground-lighter" />
|
|
Edit
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
onClick={(event) => {
|
|
event.stopPropagation()
|
|
onDeleteRule(user)
|
|
}}
|
|
disabled={!canUpdate || disableActions}
|
|
>
|
|
<Trash2 size={14} className="text-foreground-lighter" />
|
|
Delete
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</TableCell>
|
|
</TableRow>
|
|
)
|
|
})
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
</CardContent>
|
|
</Card>
|
|
)
|
|
}
|