Files
supabase/apps/studio/components/interfaces/Observability/ServiceHealthTable.tsx
Danny White e3d7267845 fix(studio): chip away explicit-tabindex ratchet debt (#48040)
## What kind of change does this PR introduce?

A11y cleanup follow-up to #47984 /
[DEPR-626](https://linear.app/supabase/issue/DEPR-626).

## What is the current behavior?

Studio had 82 ratcheted `supabase/require-explicit-tabindex` violations
(raw `<button>` / `role="button"` without explicit `tabIndex`).

## What is the new behavior?

- Explicit `tabIndex={0}` (or disabled → `-1`) on those Studio call
sites across nav, `components/ui`, Database, Storage, and the remainder
- Ratchet baseline cleared (**82 → 0**) and the rule **removed from the
Studio ratchet** (debt is gone; ratchet is temporary)
- Rule remains a shared **`warn`** for now — promoting to `error` (and
sweeping www/docs/design-system) is a follow-up
- Also fixed the learn/ui-library call sites that surfaced while
experimenting with error promotion
- Small follow-ups where making controls focusable exposed gaps:
accessible names, disabled/focus consistency, focus-ring polish on
To-test surfaces, home section `KeyboardSensor`, and an E2E locator
tightened after `aria-label="Remove column"`

Prefer migrating to `Button` from `ui` in future touch-ups; this PR
takes the minimal path so Studio debt can stay at zero.

## Additional context

Batches landed together so baseline conflicts stayed simple while
chipping away:

- Hotspots / nav (FirstLevelNav, Marketplace, AttachmentUpload, Column,
Tabs, …)
- `components/ui` shared
- Database + Storage
- Remainder

**Out of scope / intentional deferrals**

- Promoting `supabase/require-explicit-tabindex` to a lint **error**
(follow-up after www/docs/design-system sweeps)
- Tabs/Radio roving, tooltips, context menus, in-menu items
- Full keyboard-accessible tab-close UX (close stays hover +
`tabIndex={-1}`; context menu still closes tabs)
- Data API docs links (`/project/<ref>/api` redirect)

**Reviewer notes**

- Rule only flags raw `<button>` / `role="button"` without a `tabIndex`
prop. `Button` from `ui` already bakes this in
- `tabIndex={-1}` is intentional for disabled controls, in-menu /
roving-focus children, and hover-only tab close
- For dnd-kit grips, put `tabIndex` **after** `{...attributes}` so it
isn’t overwritten (TS2783)

### To test

Use **Safari** with macOS Keyboard navigation **off** (System Settings →
Keyboard). Chrome once for a sanity pass. For each surface below: Tab
until the control is focused, then activate with Enter/Space where
relevant.

1. **API Docs side panel** (Table Editor → open a table → **API docs**)
- Floating API Docs panel — **not** `/project/<ref>/api` (that redirects
to Data API docs; language ToggleGroup uses arrow keys; links are out of
scope)
- Left nav buttons — Tab through several and activate one; active
highlight / navigation still works

2. **Integrations → Marketplace**
- Enable **Integrations layout** feature preview first (avatar menu →
Feature previews)
   - `/org/<slug>/integrations` or project integrations marketplace
   - “Clear all”, grid/list toggles — Tab + activate

3. **Table Editor → create a table → Columns**
- Drag handles only appear while **creating** (not when editing an
existing table)
   - Tab to grip / remove (X) / sensitive-data eye if shown

4. **Project Home** — section drag handles
   - Tab to a grip (visible focus ring)
- Optional: Space to pick up, arrows to move, Space/Esc to drop
(KeyboardSensor added)
   - Mouse dnd still works

5. **Storage → Policies** — expand/collapse bucket list chevron
(design-system focus ring, no stuck grey open bg)

6. **Support form** (Help → Support) — attachment remove (×) and
add-attachment control when visible

Disabled controls should be **skipped** by Tab.

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

* **Accessibility Improvements**
* Improved keyboard navigation throughout Studio by explicitly managing
focus (`tabIndex`) across many interactive controls (menus, tabs,
tables, charts, dialogs, navigation, and form actions).
* Disabled or non-interactive controls are now removed from the tab
order (or made unfocusable), while available actions remain reachable.
* Ensured `type="button"` on relevant controls to prevent unintended
submissions, and refined keyboard focus behavior for various toggles and
copy/remove actions.
* **Chores**
* Updated the ESLint rule baseline configuration to match the new focus
behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-21 08:22:43 +10:00

240 lines
7.4 KiB
TypeScript

import { ChevronRight, HelpCircle } from 'lucide-react'
import Link from 'next/link'
import {
Button,
Card,
CardContent,
cn,
Skeleton,
Tooltip,
TooltipContent,
TooltipTrigger,
type ChartConfig,
} from 'ui'
import { ChartEmptyState, ChartLoadingState } from 'ui-patterns/Chart'
import { LogsBarChart } from 'ui-patterns/LogsBarChart'
import type { LogsBarChartDatum } from '../ProjectHome/ProjectUsage.metrics'
import type { UnifiedLogType } from '../UnifiedLogs/UnifiedLogs.utils'
import { getHealthStatus, type ServiceKey } from './ObservabilityOverview.utils'
type ServiceConfig = {
key: ServiceKey
name: string
description: string
reportUrl?: string
logType: UnifiedLogType
logsUrl: string
}
type ServiceData = {
total: number
errorRate: number
errorCount: number
warningCount: number
eventChartData: LogsBarChartDatum[]
isLoading: boolean
}
export type ServiceHealthTableProps = {
services: ServiceConfig[]
serviceData: Record<string, ServiceData>
onBarClick: (service: ServiceConfig) => (datum: LogsBarChartDatum) => void
datetimeFormat: string
}
const colorClassMap: Record<string, string> = {
muted: 'bg-gray-500',
destructive: 'bg-destructive',
warning: 'bg-warning',
brand: 'bg-brand',
}
const LEVEL_CHART_CONFIG: ChartConfig = {
error_count: { label: 'Errors' },
warning_count: { label: 'Warnings' },
ok_count: { label: 'Infos' },
}
const SERVICE_DESCRIPTIONS: Record<ServiceKey, string> = {
db: 'PostgreSQL database health and performance',
auth: 'Authentication and user management',
functions: 'Serverless Edge Functions execution',
storage: 'Object storage for files and assets',
realtime: 'WebSocket connections and broadcasts',
data_api: 'Incoming API requests routed through the edge network',
postgrest: 'Auto-generated REST API for your database',
}
const formatPercent = (value: number) =>
value >= 1 ? `${value.toFixed(1)}%` : `${value.toFixed(2)}%`
const getSubtitle = (data: ServiceData) => {
if (data.total === 0) return ''
const errorRate = data.errorRate
const warningRate = data.total > 0 ? (data.warningCount / data.total) * 100 : 0
if (errorRate > 0) return `${formatPercent(errorRate)} errors`
if (warningRate > 0) return `${formatPercent(warningRate)} warnings`
return `${data.total.toLocaleString()} requests`
}
type ServiceCellProps = {
service: ServiceConfig
data: ServiceData
onBarClick: (datum: LogsBarChartDatum) => void
datetimeFormat: string
className?: string
}
const ServiceCell = ({
service,
data,
onBarClick,
datetimeFormat,
className,
}: ServiceCellProps) => {
const reportUrl = service.reportUrl || service.logsUrl
const { color } = getHealthStatus(data.errorRate, data.total)
const description = SERVICE_DESCRIPTIONS[service.key] || service.description
return (
<div
className={cn(
'group relative px-card pt-2 pb-4 hover:bg-surface-200 transition-colors',
className
)}
>
<div className="flex items-center justify-between mb-3 gap-2">
<div className="flex items-center gap-1.5 min-w-0">
<div
className={cn(
'w-1.5 h-1.5 rounded-full shrink-0',
colorClassMap[color] || 'bg-gray-500'
)}
/>
<h3 className="text-foreground-light font-mono uppercase text-xs truncate m-0">
<Link
href={reportUrl}
className="after:absolute after:inset-0 after:content-[''] focus-visible:outline-none focus-visible:after:ring-2 focus-visible:after:ring-foreground-light focus-visible:after:ring-offset-2 focus-visible:after:rounded-sm"
>
{service.name}
</Link>
</h3>
{description && (
<Tooltip>
<TooltipTrigger asChild>
<button
type="button"
tabIndex={0}
className="relative z-10 text-foreground-lighter hover:text-foreground-light transition-colors shrink-0"
aria-label={`About ${service.name}`}
>
<HelpCircle size={12} />
</button>
</TooltipTrigger>
<TooltipContent side="top" className="max-w-xs">
<p>{description}</p>
</TooltipContent>
</Tooltip>
)}
</div>
<div className="flex items-center gap-1.5">
{data.isLoading ? (
<Skeleton className="h-3 w-20 mt-0.5" />
) : (
<span
className={cn(
'text-xs truncate',
data.total === 0 ? 'text-foreground-lighter' : 'text-foreground'
)}
>
{getSubtitle(data)}
</span>
)}
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="text"
size="tiny"
className="relative z-10 px-1 text-foreground-lighter group-hover:text-foreground transition-colors shrink-0"
aria-label={`Go to ${service.name} report`}
asChild
>
<Link href={reportUrl}>
<ChevronRight size={14} strokeWidth={1.5} />
</Link>
</Button>
</TooltipTrigger>
<TooltipContent side="top">Go to {service.name} report</TooltipContent>
</Tooltip>
</div>
</div>
<div className="relative z-10 h-16">
{data.isLoading ? (
<ChartLoadingState className="h-full" />
) : (
<LogsBarChart
isFullHeight
hideDateRange
hideXAxis
data={data.eventChartData}
chartConfig={LEVEL_CHART_CONFIG}
DateTimeFormat={datetimeFormat}
onBarClick={onBarClick}
EmptyState={<ChartEmptyState className="h-full" description="No traffic" />}
/>
)}
</div>
</div>
)
}
export const ServiceHealthTable = ({
services,
serviceData,
onBarClick,
datetimeFormat,
}: ServiceHealthTableProps) => {
return (
<div>
<h2 className="heading-section mb-4">Service Health</h2>
<Card className="overflow-auto">
<CardContent className="p-0">
<div className="grid grid-cols-1 md:grid-cols-2">
{services.map((service, index) => {
const data = serviceData[service.key]
if (!data) return null
const isFirst = index === 0
const isLeftColumn = !isFirst && (index - 1) % 2 === 0
const restCount = services.length - 1
const lastRowCount = restCount % 2 === 0 ? 2 : 1
const isInLastRow = !isFirst && index >= services.length - lastRowCount
return (
<ServiceCell
key={service.key}
service={service}
data={data}
onBarClick={onBarClick(service)}
datetimeFormat={datetimeFormat}
className={cn(
'border-default border-b',
isFirst && 'md:col-span-2',
isInLastRow && 'md:border-b-0',
isLeftColumn && 'md:border-r'
)}
/>
)
})}
<div className="bg-background/20" aria-hidden="true" />
</div>
</CardContent>
</Card>
</div>
)
}