Files
supabase/apps/studio/components/interfaces/ConfigDrift/ConfigurationDriftPage.tsx
Alaister YoungandAlaister Young df798783e1 [FE-5108] (part 4) refactor(studio): migrate integrations, settings & observability off next/link (#54307)
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>
2026-12-01 17:02:11 +08:00

366 lines
13 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { useParams } from 'common'
import { ArrowRightIcon, CheckCircle2Icon, FileWarningIcon, PlusIcon } from 'lucide-react'
import { Button, Card, GithubIcon, Skeleton } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { CollapsibleCardSection } from 'ui-patterns/CollapsibleCardSection'
import { EmptyStatePresentational } from 'ui-patterns/EmptyStatePresentational'
import {
createConfigurationDriftRows,
groupMatchedConfigFields,
groupUnmanagedConfigFields,
type ConfigSectionGroup,
type ConfigurationDriftRow,
} from './ConfigurationDriftPage.utils'
import { AlertError } from '@/components/ui/AlertError'
import { DynamicLink } from '@/components/ui/DynamicLink'
import { NoPermission } from '@/components/ui/NoPermission'
import { useSelectedGitHubConfigDrift } from '@/hooks/misc/useGitHubConfigDrift'
export function ConfigurationDriftPageSkeleton() {
return (
<div className="space-y-6" aria-label="Loading configuration drift" aria-busy="true">
<div className="space-y-3 rounded-lg border border-border bg-surface-100 px-4 py-3">
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex min-w-0 items-center gap-3">
<Skeleton className="h-8 w-8 shrink-0 rounded-md" />
<Skeleton className="h-4 w-44 max-w-[60vw]" />
</div>
<div className="flex w-full items-center gap-2 sm:w-auto">
<Skeleton className="h-7 flex-1 rounded-md sm:w-28 sm:flex-none" />
<Skeleton className="h-7 flex-1 rounded-md sm:w-20 sm:flex-none" />
</div>
</div>
<div className="grid gap-3 border-t border-border pt-3 sm:grid-cols-2 lg:grid-cols-3">
{['w-28', 'w-44', 'w-52'].map((width) => (
<div key={width} className="space-y-2">
<Skeleton className="h-3 w-20" />
<Skeleton className={`h-3 ${width}`} />
</div>
))}
</div>
<div className="border-t border-border pt-3">
<Skeleton className="h-3 w-40" />
<Skeleton className="mt-2 h-3 w-72 max-w-full" />
<div className="mt-3 overflow-hidden rounded-md border border-border">
<div className="flex items-center gap-2 bg-surface-100 px-3 py-2.5">
<Skeleton className="h-5 w-5 rounded-full" />
<Skeleton className="h-3 w-32" />
</div>
<div className="space-y-2 border-t border-border bg-[#0d0d0d] px-4 py-4">
<Skeleton className="h-3 w-24" />
<Skeleton className="h-3 w-52 max-w-full" />
<Skeleton className="h-3 w-40 max-w-full" />
</div>
</div>
</div>
</div>
<Card className="overflow-hidden">
<div className="flex min-h-[77px] items-start gap-3 border-b border-border px-4 py-4 sm:px-5">
<Skeleton className="mt-0.5 h-5 w-5 shrink-0 rounded" />
<div className="flex-1 space-y-2">
<Skeleton className="h-4 w-48 max-w-full" />
<Skeleton className="h-3 w-[460px] max-w-full" />
</div>
</div>
<div className="border-b border-border bg-surface-100 px-4 py-3 sm:px-5">
<Skeleton className="h-3 w-32" />
</div>
<div className="px-4 py-4 sm:px-5">
<div className="flex items-start justify-between gap-4">
<div className="space-y-2">
<Skeleton className="h-4 w-36" />
<Skeleton className="h-3 w-52 max-w-[55vw]" />
</div>
<Skeleton className="h-7 w-24 shrink-0 rounded-md" />
</div>
<div className="mt-4 grid gap-3 md:grid-cols-2">
{[0, 1].map((panel) => (
<div
key={panel}
className="min-h-[84px] space-y-3 rounded-md border border-border p-3"
>
<Skeleton className="h-3 w-28" />
<Skeleton className="h-3 w-4/5" />
</div>
))}
</div>
</div>
<div className="flex flex-col gap-2 border-t border-border bg-surface-100 px-4 py-4 sm:flex-row sm:px-5">
<Skeleton className="h-[58px] flex-1 rounded-md" />
<Skeleton className="h-[58px] flex-1 rounded-md" />
</div>
</Card>
</div>
)
}
function ConfigurationDriftItem({
row,
configFileName,
}: {
row: ConfigurationDriftRow
configFileName: string
}) {
const valueDiff = row.valueDiff
return (
<article className="border-t border-border px-4 py-4 first:border-t-0 sm:px-5">
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
<div className="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-1">
<h3 className="text-sm font-medium text-foreground">{row.settingLabel}</h3>
<code className="max-w-full truncate text-xs" title={row.configPath}>
{row.configPath}
</code>
<span className="text-xs text-warning">Drift</span>
</div>
<Button
asChild
type="button"
size="tiny"
className="w-full shrink-0 sm:w-auto"
icon={<ArrowRightIcon className="h-3.5 w-3.5" />}
>
<DynamicLink href={row.settingHref}>Open setting</DynamicLink>
</Button>
</div>
<div className="mt-4 grid gap-3 md:grid-cols-2">
<div className="min-w-0 rounded-md border border-border bg-surface-100 p-3">
<p className="mb-2 text-xs font-medium text-foreground-light">
Current environment · active
</p>
<pre className="whitespace-pre-wrap break-all font-mono text-xs leading-5 text-foreground">
{valueDiff.dashboardValue}
</pre>
</div>
<div className="min-w-0 rounded-md border border-border bg-surface-100 p-3">
<p className="mb-2 text-xs font-medium text-foreground-light">
{configFileName} · intended
</p>
<pre className="whitespace-pre-wrap break-all font-mono text-xs leading-5 text-foreground">
{valueDiff.configValue}
</pre>
</div>
</div>
</article>
)
}
export function ConfigurationDriftResults({
rows,
configFileName,
}: {
rows: ConfigurationDriftRow[]
configFileName: string
}) {
const driftCount = rows.length
const issueSummary = `${driftCount} ${driftCount === 1 ? 'setting differs' : 'settings differ'}`
return (
<Card className="overflow-hidden">
<div className="flex items-start gap-3 border-b border-border px-4 py-4 sm:px-5">
<div className="flex items-start gap-3">
<FileWarningIcon className="mt-0.5 h-5 w-5 shrink-0 -translate-x-0.5 text-warning" />
<div className="min-w-0">
<h2 className="text-sm font-medium">{issueSummary}</h2>
<p className="mt-1 text-sm text-foreground-light">
Current environment values differ from {configFileName}. Update the setting to
resolve.
</p>
</div>
</div>
</div>
<div>
{rows.map((row) => (
<ConfigurationDriftItem key={row.configPath} row={row} configFileName={configFileName} />
))}
</div>
</Card>
)
}
function ConfigFieldSection({
title,
description,
groups,
}: {
title: string
description: string
groups: ConfigSectionGroup[]
}) {
const fieldCount = groups.reduce((count, group) => count + group.rows.length, 0)
if (fieldCount === 0) return null
return (
<Card className="px-4 py-4 sm:px-5">
<CollapsibleCardSection title={`${title} (${fieldCount})`} description={description}>
<div className="space-y-4">
{groups.map((group) => (
<div key={group.section}>
<h3 className="mb-2 text-xs font-medium uppercase tracking-wide text-foreground-muted">
{group.sectionLabel}
</h3>
<ul className="divide-y divide-border rounded-md border border-border">
{group.rows.map((row) => (
<li
key={row.configPath}
className="flex items-center justify-between gap-4 px-3 py-2 text-sm"
>
<span className="text-foreground-light">{row.label}</span>
<code
data-code-style="plain"
className="max-w-[60%] truncate text-xs text-foreground-muted"
title={row.value}
>
{row.value}
</code>
</li>
))}
</ul>
</div>
))}
</div>
</CollapsibleCardSection>
</Card>
)
}
export function ConfigurationDriftPage() {
const { ref: projectRef = '' } = useParams()
const {
summary,
isReady,
isPermissionDenied,
isPending,
isFetching,
isError,
error,
errorSource,
configFileName,
refetch,
} = useSelectedGitHubConfigDrift()
const driftRows = createConfigurationDriftRows(summary.driftedFields, projectRef)
const comparableSettingCount = summary.matchedFields.length + driftRows.length
const matchedGroups = groupMatchedConfigFields(summary.matchedFields)
const unmanagedGroups = groupUnmanagedConfigFields(summary.unmanagedFields)
if (isPending) {
return <ConfigurationDriftPageSkeleton />
}
if (isPermissionDenied) {
return <NoPermission resourceText="check this project's configuration drift" />
}
if (isError) {
const isConfigFileError = errorSource === 'config-file'
const subject = isConfigFileError
? configFileName
? `Could not read ${configFileName}`
: 'Could not read the config file'
: 'Could not check configuration drift'
const description = isConfigFileError
? 'Fix the listed values on the selected GitHub branch, then refresh.'
: 'Refresh to compare the supported settings with the selected GitHub branch again.'
return (
<AlertError
projectRef={projectRef}
subject={subject}
description={description}
error={error}
additionalActions={
<Button size="small" loading={isFetching} onClick={() => refetch()}>
Refresh
</Button>
}
/>
)
}
if (!isReady) {
return (
<EmptyStatePresentational
icon={GithubIcon}
title="Github integration required"
description={
<p className="mt-1 text-sm text-foreground-light">
This feature requires a GitHub integration to enable the project to be managed by a
config file.
</p>
}
>
<Link to="/project/$ref/settings/integrations" params={{ ref: projectRef ?? '_' }}>
<Button size="tiny" variant="primary" icon={<PlusIcon size={14} />}>
Connect a GitHub repo
</Button>
</Link>
</EmptyStatePresentational>
)
}
const configFile = configFileName ?? 'config file'
return (
<main className="space-y-6">
<Admonition
type="warning"
title={`${configFileName ?? 'The config file'} will overwrite these settings on next deploy`}
description={
<>
This project is connected to GitHub. The next commit redeploys{' '}
<code className="text-xs">{configFile}</code> and overwrites changes made here. To keep
these changes, run <code className="text-xs">supabase config pull</code> locally.
</>
}
/>
{comparableSettingCount === 0 ? (
<Card className="flex min-h-44 items-center justify-center px-6 text-center">
<div className="max-w-lg">
<GithubIcon className="mx-auto mb-3 h-6 w-6 text-foreground-muted" />
<h2 className="text-sm font-medium">No comparable settings found</h2>
<p className="mt-1 text-sm text-foreground-light">
This branch does not define any supported, non-secret settings that can be compared
with the current environment.
</p>
</div>
</Card>
) : driftRows.length === 0 ? (
<Card className="flex min-h-44 items-center justify-center px-6 text-center">
<div className="max-w-lg">
<CheckCircle2Icon className="mx-auto mb-3 h-6 w-6 text-primary" />
<h2 className="text-sm font-medium">All compared settings match</h2>
<p className="mt-1 text-sm text-foreground-light">
The current environment matches all {summary.matchedFields.length} comparable settings
in this branch.
</p>
</div>
</Card>
) : (
<ConfigurationDriftResults rows={driftRows} configFileName={configFile} />
)}
<ConfigFieldSection
title={`Matching ${configFile}`}
description={`These settings already match between the current environment and ${configFile}.`}
groups={matchedGroups}
/>
<ConfigFieldSection
title={`Not tracked in ${configFile}`}
description={`These settings aren't declared in ${configFile}, so they can't drift — shown here for visibility only.`}
groups={unmanagedGroups}
/>
</main>
)
}