Files
Alaister YoungandAlaister Young 680633ee4f [FE-5108] (part 5) refactor(studio): migrate remaining interfaces off next/link (#54308)
Part 5 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 | Integrations, Settings, Observability, LogDrains, Issues,
Linter, Reports, QueryPerformance, QuerySources, ConfigDrift,
DiskManagement, Compute |
| **5** | **#54308 ← this PR** | **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 the remaining `components/interfaces/**` directories off
`next/link`, leaving zero `next/link` component imports in
`apps/studio`.

**Changed:**

- Replaced `next/link` across all 73 remaining interface files
(`Organization`, `OrganizationInvite`, `Billing`, `Auth`, `Support`,
`ProjectHome`, `Home`, `Project`, `ProjectCreation`, `ProjectAPIDocs`,
`ApiAuthorization`, `App`, `ConnectSheet`, `SignIn`, `APIKeys`,
`Account`, `CliLogin`, `Docs`, `JwtSecrets`, `Platform`)
- Converted the sole remaining `UrlObject` link (`<Link href={{
pathname: '/sign-in-sso', query }}>`) in `SignInSSOForm.tsx` to `<Link
to="/sign-in-sso" search={query}>`
- Migrated `SupportLink.tsx` onto `DynamicLink`
(`createSupportFormUrl(...)`)
- Standardized external `target="_blank"` anchors with `rel="noreferrer
noopener"`, switched `OverviewMetrics.tsx` observability link to typed
`<Link to="/project/$ref/observability/auth">`, and adopted `InlineLink`
/ `InlineLinkClassName` on inline paragraph links per review feedback

Addresses
[FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link)

## To test

- [ ] Check Organization (billing, usage, team, documents, AWS
Marketplace), Auth (providers, templates, rate limits, users, OAuth
apps), Support form/links, Project Home, Connect sheet, and Sign-In/SSO
links
- [ ] Verify `SignInWithSSOButton` preserves query params when
navigating to `/sign-in-sso`
- [ ] Verify `SupportLink` pre-populates support form query parameters
cleanly

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-01 17:33:03 +08:00

148 lines
5.4 KiB
TypeScript

import { Link } from '@tanstack/react-router'
import { ChevronRightIcon } from 'lucide-react'
import { useMemo } from 'react'
import { HoverCard, HoverCardContent, HoverCardTrigger } from 'ui'
import { formatUsage } from '../helpers'
import { Metric } from './BillingBreakdown.constants'
import { UsageProjectName } from '@/components/interfaces/Organization/Usage/UsageProjectName'
import { ComputeUsageMetric, PricingMetric } from '@/data/analytics/org-daily-stats-query'
import type { OrgUsageResponse } from '@/data/usage/org-usage-query'
import { DOCS_URL } from '@/lib/constants'
import { formatCurrency } from '@/lib/helpers'
export interface ComputeMetricProps {
slug?: string
metric: Metric
usage: OrgUsageResponse
relativeToSubscription: boolean
className?: string
projectRef?: string | null
}
export const ComputeMetric = ({
slug,
metric,
usage,
relativeToSubscription,
className,
projectRef,
}: ComputeMetricProps) => {
const usageMeta = usage.usages.find((x) => x.metric === metric.key)
const usageLabel = useMemo(() => {
if (usageMeta?.pricing_free_units) {
return `${usageMeta?.usage?.toLocaleString() ?? 0} / ${
usageMeta?.pricing_free_units ?? 0
} hours`
} else {
return `${usageMeta?.usage?.toLocaleString() ?? 0} hours`
}
}, [usageMeta])
const sortedProjectAllocations = useMemo(() => {
if (!usageMeta || !usageMeta.project_allocations) return []
return usageMeta.project_allocations.sort((a, b) => b.usage - a.usage)
}, [usageMeta])
return (
<HoverCard openDelay={50} closeDelay={200}>
<HoverCardTrigger asChild>
<div className={className}>
<Link to="/org/$slug/usage" params={{ slug: slug ?? '_' }} hash={metric.anchor}>
<div className="group flex items-center space-x-2">
<p className="text-sm text-foreground-light group-hover:text-foreground transition cursor-pointer">
{metric.name}
</p>
<ChevronRightIcon strokeWidth={1.5} size={16} className="transition" />
</div>
</Link>
<span className="text-sm">{usageLabel}</span>&nbsp;
{relativeToSubscription && usageMeta?.cost && usageMeta.cost > 0 ? (
<span className="text-sm" translate="no">
({formatCurrency(usageMeta?.cost)})
</span>
) : null}
</div>
</HoverCardTrigger>
<HoverCardContent side="bottom" align="end" className="w-[500px]" animate="slide-in">
<div className="text-sm text-foreground space-y-2">
<p className="font-medium" translate="no">
{usageMeta?.unit_price_desc}
</p>
<div className="my-2">
{usageMeta?.metric === ComputeUsageMetric.COMPUTE_HOURS_BRANCH ? (
<p className="text-sm">
Each Preview branch is a separate environment with all Supabase services (Database,
Auth, Storage, etc.).{' '}
<a
href={`${DOCS_URL}/guides/platform/manage-your-usage/branching`}
target="_blank"
rel="noreferrer noopener"
className="transition text-primary hover:text-primary-hover underline"
>
Read more
</a>
</p>
) : (
<p className="text-sm">
Every project is a dedicated server and database. For every hour your project is
active, it incurs compute costs based on the compute size of your project. Paused
projects do not incur compute costs.{' '}
<a
href={`${DOCS_URL}/guides/platform/manage-your-usage/compute`}
target="_blank"
rel="noreferrer noopener"
className="transition text-primary hover:text-primary-hover underline"
>
Read more
</a>
</p>
)}
</div>
{usageMeta && sortedProjectAllocations.length > 0 && (
<table className="list-disc w-full">
<thead>
<tr>
<th className="text-left">Project</th>
<th className="text-right">Usage</th>
</tr>
</thead>
<tbody>
{sortedProjectAllocations.map((allocation) => (
<tr key={`${usageMeta.metric}_${allocation.ref}`}>
<td>
<UsageProjectName
name={allocation.name}
projectRef={allocation.ref}
selectedProjectRef={projectRef}
/>
</td>
<td className="text-right">
{formatUsage(usageMeta.metric as PricingMetric, allocation)}
</td>
</tr>
))}
<tr></tr>
</tbody>
<tfoot>
<tr>
<td className="py-2 border-t text-left">Total (Hours)</td>
<td className="py-2 border-t text-right">
{formatUsage(usageMeta.metric as PricingMetric, {
usage: usageMeta.usage_original,
})}
</td>
</tr>
</tfoot>
</table>
)}
</div>
</HoverCardContent>
</HoverCard>
)
}