mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 4 of a 6-PR stack migrating all `next/link` imports in `apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known external URLs) and removing `compat/next/link.tsx`. | Part | PR | Scope | | --- | --- | --- | | 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and `components/ui/**` | | 2 | #54305 | `components/layouts/**` and top-level shell components | | 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime | | **4** | **#54307 ← this PR** | **Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute** | | 5 | #54308 | Remaining `components/interfaces/**` (Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.) | | 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and update basePath tests/docs | Migrates `components/interfaces/{Integrations,Settings,Observability,LogDrains,Issues,Linter,Reports,QueryPerformance,QuerySources,ConfigDrift,DiskManagement,Compute}/` off `next/link`. **Changed:** - Replaced `next/link` across all 72 files in Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, and Compute interfaces - Updated legacy permanent-redirect hrefs (`/settings/database` → `/database/settings`, `/settings/vault/secrets` → `/integrations/vault/secrets`, `/reports/database#database-size-report` → `/observability/database#database-size-report`) to canonical routes - Flattened legacy nested `<Link><a>...</a></Link>` markup in `DatabaseReadOnlyAlert.tsx` and dropped `passHref` in `Integrations/Queues/QueueTab.tsx` - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `ObservabilityOverviewFooter.tsx` to `InlineLink` + `DOCS_URL`, and applied `InlineLinkClassName` to the typed billing links in `DatabaseReadOnlyAlert.tsx` per review feedback - Removed `vi.mock('next/link', ...)` from `Settings/General/Project.test.tsx` and `MobileIssuesNavigation.platform.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Navigate across Integrations (marketplace, cron, queues, wrappers, Vercel/GitHub), Settings (database, infrastructure, read replicas, logs), Observability, Issues, and Compute pages - [ ] Verify Logs Preview → Logs Explorer links preserve multi-line SQL queries in search params - [ ] Verify billing and database-size links preserve query parameters and hash fragments --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
240 lines
7.4 KiB
TypeScript
240 lines
7.4 KiB
TypeScript
import { ChevronRightIcon, HelpCircleIcon } from 'lucide-react'
|
|
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'
|
|
import { DynamicLink } from '@/components/ui/DynamicLink'
|
|
|
|
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-default',
|
|
}
|
|
|
|
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">
|
|
<DynamicLink
|
|
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}
|
|
</DynamicLink>
|
|
</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}`}
|
|
>
|
|
<HelpCircleIcon 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
|
|
>
|
|
<DynamicLink href={reportUrl}>
|
|
<ChevronRightIcon size={14} strokeWidth={1.5} />
|
|
</DynamicLink>
|
|
</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>
|
|
)
|
|
}
|