Files
supabase/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx
Saxon Fletcher d2a3162bf1 Add high availability project creation controls (#48375)
## Summary

- Move High Availability into the standard project creation settings
above Compute, gated by the `instances.high_availability` entitlement.
- Mark the option as Alpha and explain that it is free during Alpha for
up to two projects.
- Enforce the supported HA configuration: `AWS_K8S`, Postgres 17 on the
`ga` release channel (no custom version is sent — the API resolves the
image), and the environment-specific local/staging region restrictions.
- Show eligible locations in a dedicated **High Availability Regions**
group.
- Preserve the existing Advanced Configuration availability rules and
additionally hide the section while HA is enabled.
- Restore the previous provider and Postgres settings when HA is
switched off.

## How to test
1. Go to create a new project
2. Ensure you have access to high availability (e.g. on local)
3. Toggle high availability on and note how the project form restricts
settings listed above

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added High Availability to project creation with Alpha warning
labeling and improved switch accessibility.
* Constrains region selection to compatible High Availability regions
and enforces HA-specific engine/release settings.
* Disables/hides custom PostgreSQL version selection when High
Availability is enabled (and omits HA custom request payloads).

* **Bug Fixes**
* Improved persistence of selected PostgreSQL version and region across
data reloads and configuration panel reopen/toggle.
* Restores region when form state temporarily drops values during
remounts.

* **Tests**
* Expanded end-to-end coverage for HA UI, region grouping, and
submit/payload restoration behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-07-30 16:36:54 +08:00

100 lines
3.8 KiB
TypeScript

import { useParams } from 'common'
import { useRef } from 'react'
import { UseFormReturn } from 'react-hook-form'
import { type CloudProvider } from 'shared-data'
import { FormControl, FormField, Input, useWatch } from 'ui'
import { CollapsibleCardSection } from 'ui-patterns/CollapsibleCardSection'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { CloudProviderSelector } from './CloudProviderSelector'
import { PostgresVersionSelector } from './PostgresVersionSelector'
import { CreateProjectForm } from './ProjectCreation.schema'
import Panel from '@/components/ui/Panel'
interface InternalOnlyConfigurationProps {
form: UseFormReturn<CreateProjectForm>
}
export const InternalOnlyConfiguration = ({ form }: InternalOnlyConfigurationProps) => {
const { slug } = useParams()
const showNonProdFields = process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
const highAvailability = useWatch({ control: form.control, name: 'highAvailability' })
// Held here (outside the collapsible content) so the selector's last valid
// selection survives the section being collapsed and reopened.
const lastValidPostgresVersionSelection = useRef('')
return (
<Panel.Content>
<CollapsibleCardSection
title="Internal-only Configuration"
description="These settings are only visible to internal staff"
>
<div className="flex flex-col gap-y-6">
<div className="flex flex-col gap-y-4">
<FormField
control={form.control}
name="postgresVersionSelection"
render={({ field }) => (
<PostgresVersionSelector
field={field}
form={form}
cloudProvider={form.getValues('cloudProvider') as CloudProvider}
organizationSlug={slug}
dbRegion={form.getValues('dbRegion')}
disabled={highAvailability}
lastValidSelectionRef={lastValidPostgresVersionSelection}
/>
)}
/>
</div>
{showNonProdFields && (
<div>
<p className="text-xs text-foreground-lighter mb-6">
The settings below are only applicable for local/staging projects
</p>
<div className="flex flex-col gap-y-4">
<CloudProviderSelector form={form} />
{!highAvailability && (
<FormField
control={form.control}
name="postgresVersion"
render={({ field }) => (
<FormItemLayout
label="Custom Postgres version"
layout="horizontal"
description="Specify a custom version of Postgres (defaults to the latest)."
>
<FormControl>
<Input placeholder="e.g 17.6.1.104" {...field} autoComplete="off" />
</FormControl>
</FormItemLayout>
)}
/>
)}
<FormField
control={form.control}
name="instanceType"
render={({ field }) => (
<FormItemLayout
label="Custom instance type"
layout="horizontal"
description="Specify a custom instance type."
>
<FormControl>
<Input placeholder="e.g t3.nano" {...field} autoComplete="off" />
</FormControl>
</FormItemLayout>
)}
/>
</div>
</div>
)}
</div>
</CollapsibleCardSection>
</Panel.Content>
)
}