mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
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>
208 lines
8.7 KiB
TypeScript
208 lines
8.7 KiB
TypeScript
import { Link } from '@tanstack/react-router'
|
|
import { useFlag, useParams } from 'common'
|
|
import { ExternalLinkIcon } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import { Alert, AlertTitle, Button } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import {
|
|
PageSection,
|
|
PageSectionContent,
|
|
PageSectionDescription,
|
|
PageSectionMeta,
|
|
PageSectionSummary,
|
|
PageSectionTitle,
|
|
} from 'ui-patterns/PageSection'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { ProjectUpdateDisabledTooltip } from '../ProjectUpdateDisabledTooltip'
|
|
import { useOrgSettingsPanel } from '../useOrgSettingsPanel'
|
|
import { SpendCapSidePanel } from './SpendCapSidePanel'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import { NoPermission } from '@/components/ui/NoPermission'
|
|
import PartnerIcon from '@/components/ui/PartnerIcon'
|
|
import { PARTNER_TO_NAME } from '@/components/ui/PartnerManagedResource'
|
|
import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
import { BASE_PATH, DOCS_URL } from '@/lib/constants'
|
|
import { MANAGED_BY } from '@/lib/constants/infrastructure'
|
|
|
|
export const CostControl = () => {
|
|
const { slug } = useParams()
|
|
const { resolvedTheme } = useTheme()
|
|
const { setPanel } = useOrgSettingsPanel()
|
|
const { data: selectedOrganization } = useSelectedOrganizationQuery()
|
|
|
|
const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
|
|
|
|
const { isSuccess: isPermissionsLoaded, can: canReadSubscriptions } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.ORGANIZATION.BILLING_READ
|
|
)
|
|
|
|
const {
|
|
data: subscription,
|
|
error,
|
|
isPending: isLoading,
|
|
isSuccess,
|
|
isError,
|
|
} = useOrgSubscriptionQuery({ orgSlug: slug }, { enabled: canReadSubscriptions })
|
|
|
|
const currentPlan = subscription?.plan
|
|
const isUsageBillingEnabled = subscription?.usage_billing_enabled ?? false
|
|
|
|
const canChangeTier =
|
|
!projectUpdateDisabled && !['team', 'enterprise', 'platform'].includes(currentPlan?.id || '')
|
|
|
|
const costControlDisabled = selectedOrganization?.managed_by === MANAGED_BY.AWS_MARKETPLACE
|
|
|
|
return (
|
|
<>
|
|
<PageSection orientation="horizontal">
|
|
<PageSectionMeta>
|
|
<PageSectionSummary className="gap-6">
|
|
<div className="flex flex-col gap-1">
|
|
<PageSectionTitle>Cost Control</PageSectionTitle>
|
|
<PageSectionDescription>
|
|
Allow scaling beyond your plan's{' '}
|
|
<InlineLink href={`/org/${slug}/usage`}>included quota</InlineLink>.
|
|
</PageSectionDescription>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<p className="text-sm text-foreground-light m-0">More information</p>
|
|
<a
|
|
href={`${DOCS_URL}/guides/platform/cost-control#spend-cap`}
|
|
target="_blank"
|
|
rel="noreferrer noopener"
|
|
className="flex items-center space-x-2 opacity-50 hover:opacity-100 transition"
|
|
>
|
|
<span className="text-sm">Spend cap</span>
|
|
<ExternalLinkIcon size={16} strokeWidth={1.5} />
|
|
</a>
|
|
</div>
|
|
</PageSectionSummary>
|
|
</PageSectionMeta>
|
|
<PageSectionContent className="flex flex-col gap-6">
|
|
{isPermissionsLoaded && !canReadSubscriptions ? (
|
|
<NoPermission resourceText="update this organization's cost control" />
|
|
) : (
|
|
<>
|
|
{isLoading && (
|
|
<div className="space-y-2">
|
|
<ShimmeringLoader />
|
|
<ShimmeringLoader className="w-3/4" />
|
|
<ShimmeringLoader className="w-1/2" />
|
|
</div>
|
|
)}
|
|
|
|
{isError && <AlertError subject="Failed to retrieve subscription" error={error} />}
|
|
|
|
{isSuccess && costControlDisabled && (
|
|
<Alert className="flex flex-col items-center gap-y-2 border-0 rounded-none">
|
|
<PartnerIcon
|
|
organization={{ managed_by: selectedOrganization?.managed_by }}
|
|
showTooltip={false}
|
|
size="large"
|
|
/>
|
|
|
|
<AlertTitle className="text-sm">
|
|
The Spend Cap is not available for organizations managed by{' '}
|
|
{PARTNER_TO_NAME[selectedOrganization?.managed_by]}.
|
|
</AlertTitle>
|
|
</Alert>
|
|
)}
|
|
|
|
{isSuccess && !costControlDisabled && (
|
|
<div className="space-y-6">
|
|
{['team', 'enterprise', 'platform'].includes(currentPlan?.id || '') ? (
|
|
<>
|
|
<Admonition
|
|
type="default"
|
|
layout="horizontal"
|
|
title={`You will be charged for any additional usage on the ${
|
|
currentPlan?.name || ''
|
|
} plan`}
|
|
description={
|
|
<>
|
|
{currentPlan?.name || ''}{' '}
|
|
<span>
|
|
plan requires you to have spend cap off at all times. Your projects
|
|
will never become unresponsive. Only when your
|
|
</span>{' '}
|
|
<Link
|
|
to="/org/$slug/usage"
|
|
params={{ slug: slug ?? '_' }}
|
|
className="text-green-900 transition hover:text-green-1000"
|
|
>
|
|
included usage
|
|
</Link>{' '}
|
|
<span>is exceeded will you be charged for any additional usage.</span>
|
|
</>
|
|
}
|
|
/>
|
|
</>
|
|
) : (
|
|
<p className="text-sm text-foreground-light">
|
|
If you need to go beyond the included quota, simply switch off your spend cap
|
|
to pay for additional usage.
|
|
</p>
|
|
)}
|
|
|
|
<div className="flex flex-col md:flex-row gap-6">
|
|
<div>
|
|
<div className="rounded-md bg-surface-200 w-[160px] h-[96px] shadow-sm">
|
|
<img
|
|
alt=""
|
|
aria-hidden="true"
|
|
width={160}
|
|
height={96}
|
|
src={
|
|
isUsageBillingEnabled
|
|
? `${BASE_PATH}/img/spend-cap-off${
|
|
resolvedTheme?.includes('dark') ? '' : '--light'
|
|
}.png`
|
|
: `${BASE_PATH}/img/spend-cap-on${
|
|
resolvedTheme?.includes('dark') ? '' : '--light'
|
|
}.png`
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<p className="mb-1">
|
|
Spend cap is{' '}
|
|
{isUsageBillingEnabled ? <span>disabled</span> : <span>enabled</span>}
|
|
</p>
|
|
<p className="text-sm text-foreground-light">
|
|
{isUsageBillingEnabled ? (
|
|
<span>You will be charged for usage beyond the included quota.</span>
|
|
) : (
|
|
<span>
|
|
You won't be charged any extra for usage. However, your projects could
|
|
become unresponsive or enter read only mode if you exceed the included
|
|
quota.
|
|
</span>
|
|
)}
|
|
</p>
|
|
<ProjectUpdateDisabledTooltip projectUpdateDisabled={projectUpdateDisabled}>
|
|
<Button
|
|
className="mt-4 pointer-events-auto"
|
|
disabled={!canChangeTier}
|
|
onClick={() => setPanel('costControl')}
|
|
>
|
|
Change spend cap
|
|
</Button>
|
|
</ProjectUpdateDisabledTooltip>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</PageSectionContent>
|
|
</PageSection>
|
|
<SpendCapSidePanel />
|
|
</>
|
|
)
|
|
}
|