mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +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>
392 lines
16 KiB
TypeScript
392 lines
16 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useState } from 'react'
|
|
import { useForm, useWatch } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Alert,
|
|
AlertDescription,
|
|
AlertTitle,
|
|
Form,
|
|
FormControl,
|
|
FormDescription,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
Input,
|
|
Switch,
|
|
} from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import * as z from 'zod'
|
|
|
|
import { FormActions } from '@/components/ui/Forms/FormActions'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import type {
|
|
EnvironmentTargets,
|
|
Integration,
|
|
IntegrationProjectConnection,
|
|
} from '@/data/integrations/integrations.types'
|
|
import { useVercelConnectionUpdateMutation } from '@/data/integrations/vercel-connection-update-mutate'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { DOCS_URL } from '@/lib/constants'
|
|
|
|
const VercelIntegrationConnectionForm = ({
|
|
disabled,
|
|
connection,
|
|
integration,
|
|
}: {
|
|
disabled?: boolean
|
|
connection: IntegrationProjectConnection
|
|
integration: Integration
|
|
}) => {
|
|
// NOTE(kamil): Ignore sync targets for Vercel Marketplace as it's not synchronized using integration,
|
|
// but through a separate marketplace mechanism. It's not theoretically necessary, but we might have some stale data.
|
|
const { data: org } = useSelectedOrganizationQuery()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const isBranchingEnabled = project?.is_branch_enabled === true
|
|
const envSyncTargets =
|
|
org?.managed_by === 'vercel-marketplace' ? [] : (connection.env_sync_targets ?? [])
|
|
|
|
const FormSchema = z.object({
|
|
environmentVariablesProduction: z.boolean().default(envSyncTargets.includes('production')),
|
|
environmentVariablesPreview: z.boolean().default(envSyncTargets.includes('preview')),
|
|
environmentVariablesDevelopment: z.boolean().default(envSyncTargets.includes('development')),
|
|
publicEnvVarPrefix: z.string().optional(),
|
|
})
|
|
|
|
const form = useForm<z.infer<typeof FormSchema>>({
|
|
resolver: zodResolver(FormSchema),
|
|
defaultValues: {
|
|
environmentVariablesProduction: envSyncTargets.includes('production'),
|
|
environmentVariablesPreview: envSyncTargets.includes('preview'),
|
|
environmentVariablesDevelopment: envSyncTargets.includes('development'),
|
|
publicEnvVarPrefix: connection.public_env_var_prefix,
|
|
},
|
|
})
|
|
|
|
const [showConfirmation, setShowConfirmation] = useState(false)
|
|
const [pendingValues, setPendingValues] = useState<z.infer<typeof FormSchema> | null>(null)
|
|
|
|
const { mutate: updateVercelConnection, isPending } = useVercelConnectionUpdateMutation({
|
|
onSuccess: () => {
|
|
form.reset(form.getValues())
|
|
setShowConfirmation(false)
|
|
setPendingValues(null)
|
|
toast.success(`Updated Vercel connection`)
|
|
},
|
|
})
|
|
|
|
// Syncing the `preview` or `development` target sends this project's production credentials
|
|
// (anon and service role keys, database connection strings) to those Vercel environments. Watch
|
|
// the toggles so we can warn inline and gate the save behind a confirmation.
|
|
const [syncPreview, syncDevelopment] = useWatch({
|
|
control: form.control,
|
|
name: ['environmentVariablesPreview', 'environmentVariablesDevelopment'],
|
|
})
|
|
const isSyncingNonProdEnvs = syncPreview || syncDevelopment
|
|
|
|
const selectedNonProdTargets: string[] = []
|
|
if (pendingValues?.environmentVariablesPreview) selectedNonProdTargets.push('Preview')
|
|
if (pendingValues?.environmentVariablesDevelopment) selectedNonProdTargets.push('Development')
|
|
|
|
function performUpdate(data: z.infer<typeof FormSchema>) {
|
|
const targets: EnvironmentTargets[] = []
|
|
|
|
if (data.environmentVariablesProduction) targets.push('production')
|
|
if (data.environmentVariablesPreview) targets.push('preview')
|
|
if (data.environmentVariablesDevelopment) targets.push('development')
|
|
|
|
updateVercelConnection({
|
|
id: connection.id,
|
|
envSyncTargets: targets,
|
|
publicEnvVarPrefix: data.publicEnvVarPrefix?.trim(),
|
|
organizationIntegrationId: integration.id,
|
|
})
|
|
}
|
|
|
|
function onSubmit(data: z.infer<typeof FormSchema>) {
|
|
// Always confirm when Preview/Development sync is enabled to discourage leaking production
|
|
// credentials into preview deployments and steer users toward Branching instead.
|
|
if (data.environmentVariablesPreview || data.environmentVariablesDevelopment) {
|
|
setPendingValues(data)
|
|
setShowConfirmation(true)
|
|
return
|
|
}
|
|
|
|
performUpdate(data)
|
|
}
|
|
|
|
const vercelConnectionFormId = `vercel-connection-form-${connection.id}`
|
|
|
|
return (
|
|
<Form {...form}>
|
|
<form
|
|
id={vercelConnectionFormId}
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
className={'w-full space-y-6'}
|
|
>
|
|
<div className="px-6 py-4 flex flex-col gap-y-4">
|
|
<div className="flex flex-col gap-4">
|
|
{org?.managed_by === 'vercel-marketplace' ? (
|
|
<Alert>
|
|
<AlertTitle className="text-sm">Vercel Marketplace managed project</AlertTitle>
|
|
<AlertDescription className="text-xs">
|
|
This project is managed via Vercel Marketplace. Environment variables are
|
|
automatically synchronized for your connected Vercel projects. This integration
|
|
purpose is synchronizing preview deployments environment variables with our{' '}
|
|
<a
|
|
target="_blank"
|
|
rel="noreferrer noopener"
|
|
href={`${DOCS_URL}/guides/platform/branching`}
|
|
className="underline"
|
|
>
|
|
Branching
|
|
</a>{' '}
|
|
feature.
|
|
</AlertDescription>
|
|
</Alert>
|
|
) : (
|
|
<div>
|
|
<div className="space-y-1 mb-4">
|
|
<h5 className="text-foreground">Sync environment variables to Vercel</h5>
|
|
<p className="text-sm text-foreground-light">
|
|
Choose which Vercel environments receive this project's{' '}
|
|
<span className="text-foreground">production</span> credentials. Most projects
|
|
only need <code>production</code>.
|
|
</p>
|
|
<p className="text-sm text-foreground-light">
|
|
With{' '}
|
|
<InlineLink href={`/project/${project?.ref}/branches`}>Branching</InlineLink>{' '}
|
|
enabled, leave Preview and Development off: Branching gives each preview branch
|
|
its own database and syncs those credentials to your Vercel Preview deployments.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="space-y-4">
|
|
<FormField
|
|
control={form.control}
|
|
name="environmentVariablesProduction"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
label="Production"
|
|
description={
|
|
<>
|
|
Syncs to the Vercel <code>production</code> env.
|
|
</>
|
|
}
|
|
>
|
|
<FormControl>
|
|
<Switch
|
|
disabled={disabled}
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name="environmentVariablesPreview"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
label="Preview"
|
|
description={
|
|
<>
|
|
Syncs to the Vercel <code>preview</code> env.
|
|
</>
|
|
}
|
|
>
|
|
<FormControl>
|
|
<Switch
|
|
disabled={disabled}
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
<FormField
|
|
control={form.control}
|
|
name="environmentVariablesDevelopment"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
label="Development"
|
|
description={
|
|
<>
|
|
Syncs to the Vercel <code>development</code> env.
|
|
</>
|
|
}
|
|
>
|
|
<FormControl>
|
|
<Switch
|
|
disabled={disabled}
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
|
|
{isSyncingNonProdEnvs && (
|
|
<Admonition
|
|
type="warning"
|
|
title={
|
|
isBranchingEnabled
|
|
? 'Not recommended with Branching'
|
|
: 'These environments will use production credentials'
|
|
}
|
|
>
|
|
<p>
|
|
Preview and Development sync your production credentials, including the
|
|
service role key and database password, to those Vercel environments.
|
|
</p>
|
|
{isBranchingEnabled ? (
|
|
<p>
|
|
<InlineLink href={`/project/${project?.ref}/branches`}>
|
|
Branching
|
|
</InlineLink>{' '}
|
|
already provisions isolated credentials for each preview branch. With
|
|
Preview enabled, deployments use production credentials until a branch
|
|
finishes provisioning, which can affect production data. We recommend
|
|
leaving Preview and Development off.
|
|
</p>
|
|
) : (
|
|
<p>
|
|
To give preview deployments their own isolated credentials, use{' '}
|
|
<InlineLink href={`/project/${project?.ref}/branches`}>
|
|
Branching
|
|
</InlineLink>{' '}
|
|
instead.
|
|
</p>
|
|
)}
|
|
</Admonition>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<h5 className="mt-2 text-foreground">Customize public environment variable prefix</h5>
|
|
<div className="flex flex-col gap-4">
|
|
<FormField
|
|
control={form.control}
|
|
name="publicEnvVarPrefix"
|
|
render={({ field }) => (
|
|
<FormItem className="grid gap-2 md:grid md:grid-cols-12 space-y-0">
|
|
<FormLabel className="flex flex-col space-y-2 col-span-4 text-sm justify-center text-foreground-light">
|
|
Prefix
|
|
</FormLabel>
|
|
<FormControl className="col-span-8">
|
|
<Input
|
|
{...field}
|
|
className="w-full"
|
|
disabled={disabled}
|
|
placeholder="An empty prefix will result in no public env vars"
|
|
/>
|
|
</FormControl>
|
|
<FormDescription className="col-start-5 col-span-8 text-xs">
|
|
e.g.{' '}
|
|
{(
|
|
[
|
|
['NEXT_PUBLIC_', 'NEXT_PUBLIC_'],
|
|
['VITE_PUBLIC_', 'VITE_PUBLIC_'],
|
|
['PUBLIC_', 'PUBLIC_'],
|
|
] as const
|
|
).map(([label, value], index) => (
|
|
<span key={value}>
|
|
{index > 0 && <span>{', '}</span>}
|
|
<button
|
|
type="button"
|
|
tabIndex={disabled ? -1 : 0}
|
|
disabled={disabled}
|
|
className="font-mono text-xs rounded-sm bg-surface-200 px-1 py-0.5 hover:bg-surface-300 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
onClick={() => field.onChange(value)}
|
|
>
|
|
{label}
|
|
</button>
|
|
</span>
|
|
))}
|
|
, etc.
|
|
</FormDescription>
|
|
|
|
<FormMessage className="col-start-5 col-span-8" />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
</div>
|
|
|
|
{form.formState.isDirty ? (
|
|
<p className="mt-2 text-sm text-warning">
|
|
Note: Changing these settings will <strong>not</strong> trigger a resync of
|
|
environment variables.
|
|
</p>
|
|
) : (
|
|
<div className="mt-2 h-5 w-full" />
|
|
)}
|
|
|
|
<FormActions
|
|
disabled={disabled}
|
|
form={vercelConnectionFormId}
|
|
hasChanges={form.formState.isDirty}
|
|
isSubmitting={isPending}
|
|
handleReset={() => form.reset()}
|
|
/>
|
|
</div>
|
|
</form>
|
|
|
|
<ConfirmationModal
|
|
visible={showConfirmation}
|
|
variant="warning"
|
|
size="medium"
|
|
loading={isPending}
|
|
title="Sync production credentials?"
|
|
confirmLabel="Sync credentials"
|
|
confirmLabelLoading="Saving"
|
|
onCancel={() => {
|
|
setShowConfirmation(false)
|
|
setPendingValues(null)
|
|
}}
|
|
onConfirm={() => {
|
|
if (pendingValues) performUpdate(pendingValues)
|
|
}}
|
|
alert={{
|
|
title: 'These environments will use production credentials',
|
|
description:
|
|
'Including the project ref, API URL, anon and service role keys, and database connection strings.',
|
|
}}
|
|
>
|
|
<div className="space-y-3 text-sm text-foreground-light">
|
|
<p>
|
|
This syncs your production credentials to the{' '}
|
|
<span className="text-foreground">{selectedNonProdTargets.join(' and ')}</span>{' '}
|
|
environment{selectedNonProdTargets.length > 1 ? <span>s</span> : ''}{' '}
|
|
<span>of your connected Vercel project.</span>
|
|
</p>
|
|
{isBranchingEnabled ? (
|
|
<p>
|
|
Branching already provisions isolated credentials for each preview branch. With this
|
|
enabled, deployments use production credentials until a branch finishes provisioning,
|
|
which can affect production data. We recommend leaving it off.
|
|
</p>
|
|
) : (
|
|
<p>
|
|
To use isolated credentials for preview deployments instead, enable{' '}
|
|
<InlineLink href={`/project/${project?.ref}/branches`}>Branching</InlineLink>.
|
|
</p>
|
|
)}
|
|
</div>
|
|
</ConfirmationModal>
|
|
</Form>
|
|
)
|
|
}
|
|
|
|
export default VercelIntegrationConnectionForm
|