Files
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

272 lines
12 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { useParams } from 'common'
import { Button } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { DynamicLink } from '@/components/ui/DynamicLink'
import { InlineLink } from '@/components/ui/InlineLink'
import {
ProjectUpgradeEligibilityValidationError,
ProjectUpgradeEligibilityWarning,
} from '@/data/config/project-upgrade-eligibility-query'
import { DOCS_URL } from '@/lib/constants'
import { pluralize } from '@/lib/helpers'
export const ReadReplicasWarning = ({ latestPgVersion }: { latestPgVersion: string }) => {
const { ref } = useParams()
return (
<Admonition
type="note"
showIcon={false}
title="A newer version of Postgres is available"
description={`You will need to remove all read replicas prior to upgrading your Postgres version to the latest available (${latestPgVersion}).`}
actions={
<Button asChild>
<Link to="/project/$ref/settings/infrastructure" params={{ ref: ref ?? '_' }}>
Manage read replicas
</Link>
</Button>
}
/>
)
}
const getValidationErrorTitle = (error: ProjectUpgradeEligibilityValidationError): string => {
switch (error.type) {
case 'objects_depending_on_pg_cron':
return (error.dependents ?? []).join(', ') || 'Objects depending on pg_cron'
case 'indexes_referencing_ll_to_earth':
return `${error.schema_name}.${error.index_name}`
case 'function_using_obsolete_lang':
return `${error.schema_name}.${error.function_name}`
case 'unsupported_extension':
return error.extension_name
case 'unsupported_fdw_handler':
return error.fdw_name
case 'unlogged_table_with_persistent_sequence':
return `${error.schema_name}.${error.table_name}`
case 'user_defined_objects_in_internal_schemas':
return `${error.schema_name}.${error.obj_name}`
case 'active_replication_slot':
return error.slot_name
case 'table_using_reg_type':
return `${error.schema_name}.${error.table_name}`
case 'project_hibernating':
return 'Project is hibernating'
case 'x86_architecture':
return 'Project is running on x86 architecture'
}
}
const getValidationErrorDescription = (error: ProjectUpgradeEligibilityValidationError): string => {
switch (error.type) {
case 'objects_depending_on_pg_cron':
return 'Remove objects that depend on pg_cron'
case 'indexes_referencing_ll_to_earth':
return `Drop or recreate the index on table ${error.schema_name}.${error.table_name} that references ll_to_earth()`
case 'function_using_obsolete_lang':
return `Update the function to use a supported language instead of ${error.lang_name}`
case 'unsupported_extension':
return 'Remove the unsupported extension'
case 'unsupported_fdw_handler':
return `Update or remove the FDW using the obsolete handler ${error.fdw_handler_name}`
case 'unlogged_table_with_persistent_sequence':
return `Convert the sequence ${error.sequence_name} to unlogged or convert the table to logged`
case 'user_defined_objects_in_internal_schemas':
return `Move the ${error.obj_type} to your own schema`
case 'active_replication_slot':
return 'Drop the active replication slot'
case 'table_using_reg_type':
return `Change the type of column ${error.column_name}, which uses the unsupported type ${error.type_name}`
case 'project_hibernating':
return 'The project is currently hibernating and will wake on next supported request'
case 'x86_architecture':
return 'The project is running on x86 architecture and cannot be upgraded'
}
}
const ValidationErrorItem = ({ error }: { error: ProjectUpgradeEligibilityValidationError }) => {
const { ref: projectRef } = useParams()
const title = getValidationErrorTitle(error)
const description = getValidationErrorDescription(error)
const getManageLink = (): string | null => {
const encode = encodeURIComponent
switch (error.type) {
case 'function_using_obsolete_lang':
return `/project/${projectRef}/database/functions?schema=${encode(error.schema_name)}&search=${encode(error.function_name)}`
case 'unsupported_extension':
return `/project/${projectRef}/database/extensions?filter=${encode(error.extension_name)}`
case 'indexes_referencing_ll_to_earth':
return `/project/${projectRef}/database/indexes?schema=${encode(error.schema_name)}&search=${encode(error.index_name)}`
case 'table_using_reg_type':
case 'unlogged_table_with_persistent_sequence':
return `/project/${projectRef}/database/tables?schema=${encode(error.schema_name)}&search=${encode(error.table_name)}`
case 'user_defined_objects_in_internal_schemas':
if (error.obj_type === 'function') {
return `/project/${projectRef}/database/functions?schema=${encode(error.schema_name)}&search=${encode(error.obj_name)}`
}
if (error.obj_type === 'table') {
return `/project/${projectRef}/database/tables?schema=${encode(error.schema_name)}&search=${encode(error.obj_name)}`
}
return null
case 'active_replication_slot':
return null
case 'unsupported_fdw_handler':
return `/project/${projectRef}/integrations`
case 'objects_depending_on_pg_cron':
return null
default:
return null
}
}
const manageLink = getManageLink()
return (
<li className="py-3 last:pb-0 flex flex-row gap-x-3 justify-between items-center">
<div className="flex flex-col gap-y-0.5 flex-1 min-w-0">
<h6 className="overflow-hidden text-ellipsis whitespace-nowrap min-w-0 text-sm font-normal text-foreground">
{title}
</h6>
<p className="text-foreground-lighter text-xs">{description}</p>
</div>
{manageLink && (
<Button size="tiny" asChild>
<DynamicLink href={manageLink}>Manage</DynamicLink>
</Button>
)}
</li>
)
}
const isEtlReplicationSlot = (error: ProjectUpgradeEligibilityValidationError) =>
error.type === 'active_replication_slot' && error.slot_name.startsWith('supabase_etl_')
const isEtlApplySlot = (error: ProjectUpgradeEligibilityValidationError) =>
error.type === 'active_replication_slot' && error.slot_name.startsWith('supabase_etl_apply')
const PipelinesValidationErrorItem = ({ pipelineCount }: { pipelineCount: number }) => {
const { ref: projectRef } = useParams()
const description =
pipelineCount > 0
? `Stop all pipelines before upgrading (${pipelineCount} active ${pluralize(pipelineCount, 'pipeline')})`
: 'Stop all pipelines before upgrading'
return (
<li className="py-3 last:pb-0 flex flex-row gap-x-3 justify-between items-center">
<div className="flex flex-col gap-y-0.5 flex-1 min-w-0">
<h6 className="text-sm font-normal text-foreground">Active pipelines must be stopped</h6>
<p className="text-foreground-lighter text-xs">{description}</p>
</div>
<Button size="tiny" asChild>
<Link to="/project/$ref/database/pipelines" params={{ ref: projectRef ?? '_' }}>
Manage
</Link>
</Button>
</li>
)
}
export const ValidationErrorsWarning = ({
validationErrors,
}: {
validationErrors: ProjectUpgradeEligibilityValidationError[]
}) => {
if (validationErrors.length === 0) return null
// Pipelines create several replication slots; surface them as a single issue, counting
// pipelines via their apply slot (one per pipeline)
const hasEtlSlots = validationErrors.some(isEtlReplicationSlot)
const pipelineCount = validationErrors.filter(isEtlApplySlot).length
const otherErrors = validationErrors.filter((error) => !isEtlReplicationSlot(error))
return (
<Admonition type="note" showIcon={false} title="A newer version of Postgres is available">
<div className="flex flex-col">
<p>
The following issues must be resolved before upgrading.{' '}
<InlineLink href={`${DOCS_URL}/guides/platform/upgrading`}>Learn more</InlineLink>
</p>
<ul className="border-t border-border-muted flex flex-col divide-y divide-border-muted [&>li]:before:hidden pl-0!">
{otherErrors.map((error, idx) => (
<ValidationErrorItem key={`${error.type}-${idx}`} error={error} />
))}
{hasEtlSlots && <PipelinesValidationErrorItem pipelineCount={pipelineCount} />}
</ul>
</div>
</Admonition>
)
}
// The API can return warning types this bundle doesn't know about yet, regardless of the
// generated types, so each helper below needs a default case.
const getWarningTitle = (warning: ProjectUpgradeEligibilityWarning): string => {
switch (warning.type) {
case 'pg_graphql_introspection_change':
return 'GraphQL introspection will be disabled by default after upgrade'
case 'ltree_reindex_required':
return 'ltree indexes must be reindexed after this upgrade'
case 'operator_estimator_gate':
return 'Custom operators may need attention after this upgrade'
case 'btree_gist_nan_reindex':
return 'btree_gist indexes on float columns must be reindexed after this upgrade'
default:
return 'Review the upgrade notes before upgrading'
}
}
const getWarningDescription = (warning: ProjectUpgradeEligibilityWarning): string => {
switch (warning.type) {
case 'pg_graphql_introspection_change':
return 'After upgrading, queries to `__schema` and `__type` will return an error unless introspection is explicitly re-enabled on the schema. Regular data queries are not affected.'
case 'ltree_reindex_required':
return 'After upgrading, ltree indexes on this database can return incomplete results until they are rebuilt. Run `REINDEX INDEX CONCURRENTLY` on the affected indexes — this runs online with no downtime.'
case 'operator_estimator_gate':
return 'After upgrading, recreating an operator that references a non-built-in selectivity estimator (for example during a restore or branch) requires superuser and may fail. Most projects are not affected.'
case 'btree_gist_nan_reindex':
return 'After upgrading, btree_gist indexes on float columns can return wrong results for rows containing NaN until they are rebuilt. If those columns may contain NaN values, run `REINDEX INDEX CONCURRENTLY` on the affected indexes — this runs online with no downtime.'
default:
return 'This upgrade may affect your project.'
}
}
const getWarningLink = (warning: ProjectUpgradeEligibilityWarning): string => {
switch (warning.type) {
case 'pg_graphql_introspection_change':
return `${DOCS_URL}/guides/platform/upgrading#upgrading-to-pg_graphql-160`
case 'ltree_reindex_required':
return `${DOCS_URL}/guides/platform/upgrading#ltree-indexes-require-reindexing-after-upgrade`
case 'operator_estimator_gate':
return `${DOCS_URL}/guides/platform/upgrading#custom-operator-selectivity-estimators`
case 'btree_gist_nan_reindex':
return `${DOCS_URL}/guides/platform/upgrading#btree_gist-indexes-on-float-columns-require-reindexing-after-upgrade`
default:
return `${DOCS_URL}/guides/platform/upgrading#specific-upgrade-notes`
}
}
export const ValidationWarningsAdmonition = ({
warnings,
}: {
warnings: ProjectUpgradeEligibilityWarning[]
}) => {
if (warnings.length === 0) return null
return warnings.map((warning, idx) => (
<Admonition
key={`${warning.type}-${idx}`}
type="default"
title={getWarningTitle(warning)}
description={getWarningDescription(warning)}
>
<Button asChild className="mt-2">
<a href={getWarningLink(warning)} target="_blank" rel="noreferrer noopener">
Read upgrade notes
</a>
</Button>
</Admonition>
))
}