Files
supabase/apps/studio/components/interfaces/ProjectCreation/SecurityOptions.tsx
Han Qiao 08efb963f9 chore(studio): add custom instance type input to project creation GENCOMP-76 (#45660)
## Summary
- Adds a "Custom instance type" input on the new-project modal, rendered
directly below the existing custom Postgres version field and gated
behind the same non-prod check.
- Wires the value through
`custom_supabase_internal_requests.ami.instance_type`, merged with the
existing AMI search-tag payload so both can be set independently.

<img width="312" height="133" alt="Screenshot 2026-05-07 at 12 32 41 PM"
src="https://github.com/user-attachments/assets/d4190a0f-0a54-46e6-ac0b-967548a3903f"
/>

## Test plan
- [x] On a non-prod build, open the new-project modal and confirm the
"Custom instance type" field appears below "Custom Postgres version".
- [ ] Submit with only an instance type set and verify the request body
includes `custom_supabase_internal_requests.instance_type` and no `ami`
block.
- [x] Submit with both fields set and verify both `ami.search_tags` and
`instance_type` are sent.
- [x] Submit with neither set and verify
`custom_supabase_internal_requests` is omitted.
- [x] Verify the field is hidden in prod builds.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

* **New Features**
  * Added instance type field to project-creation wizard.
* Added an internal-only configuration panel for advanced customization.

* **Refactor**
  * Simplified Advanced Configuration panel layout and behavior.

* **Documentation**
  * Updated documentation links to use internal reference URLs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-05-07 14:51:21 +08:00

149 lines
5.4 KiB
TypeScript

import { UseFormReturn } from 'react-hook-form'
import {
Checkbox,
cn,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
Tooltip,
TooltipContent,
TooltipTrigger,
useWatch,
} from 'ui'
import { Admonition } from 'ui-patterns'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { CreateProjectForm } from './ProjectCreation.schema'
import { InlineLink } from '@/components/ui/InlineLink'
import Panel from '@/components/ui/Panel'
import { useTrackDefaultPrivilegesExposure } from '@/hooks/misc/useDataApiRevokeOnCreateDefault'
import { DOCS_URL } from '@/lib/constants'
interface SecurityOptionsProps {
form: UseFormReturn<CreateProjectForm>
layout?: 'vertical' | 'horizontal'
}
export const SecurityOptions = ({ form, layout = 'horizontal' }: SecurityOptionsProps) => {
const dataApi = useWatch({ control: form.control, name: 'dataApi' })
useTrackDefaultPrivilegesExposure({ surface: 'main', dataApiEnabled: dataApi ?? true })
return (
<Panel.Content className="pb-8">
<FormItemLayout layout={layout} label="Security" isReactForm={false}>
<div className="flex flex-col gap-4">
<FormField
name="dataApi"
control={form.control}
render={({ field }) => (
<FormItem className="flex items-start gap-3">
<FormControl>
<Checkbox
checked={field.value}
disabled={field.disabled}
onCheckedChange={(value) => field.onChange(value === true)}
/>
</FormControl>
<div className="space-y-1">
<FormLabel className="text-sm text-foreground">Enable Data API</FormLabel>
<FormDescription className="text-foreground-lighter">
Autogenerate a RESTful API for your public schema. Recommended if using a client
library like{' '}
<InlineLink href={`${DOCS_URL}/reference/javascript/introduction`}>
supabase-js
</InlineLink>
.
</FormDescription>
</div>
</FormItem>
)}
/>
<FormField
name="dataApiDefaultPrivileges"
control={form.control}
render={({ field }) => (
<FormItem
className={cn(
'flex items-start gap-3',
!dataApi && 'opacity-50 cursor-not-allowed'
)}
>
<FormControl>
{dataApi ? (
<Checkbox
checked={field.value}
disabled={field.disabled}
onCheckedChange={(value) => field.onChange(value === true)}
/>
) : (
<Tooltip>
<TooltipTrigger asChild>
<span className="cursor-not-allowed">
<Checkbox checked={field.value} disabled />
</span>
</TooltipTrigger>
<TooltipContent side="top">
Enable the Data API to configure default privileges.
</TooltipContent>
</Tooltip>
)}
</FormControl>
<div className="space-y-1">
<FormLabel
className={cn('text-sm text-foreground', !dataApi && 'text-foreground-muted')}
>
Automatically expose new tables
</FormLabel>
<FormDescription className="text-foreground-lighter">
Grants privileges to Data API roles by default, exposing new tables.
<br />
<strong className="font-medium text-foreground-light">
We recommend disabling this to control access manually.
</strong>
</FormDescription>
</div>
</FormItem>
)}
/>
<FormField
name="enableRlsEventTrigger"
control={form.control}
render={({ field }) => (
<FormItem className="flex items-start gap-3">
<FormControl>
<Checkbox
checked={field.value}
disabled={field.disabled}
onCheckedChange={(value) => field.onChange(value === true)}
/>
</FormControl>
<div className="space-y-1">
<FormLabel className="text-sm text-foreground">Enable automatic RLS</FormLabel>
<FormDescription className="text-foreground-lighter">
Create an event trigger that automatically enables Row Level Security on all new
tables in the public schema.
</FormDescription>
</div>
</FormItem>
)}
/>
{!dataApi && (
<Admonition
type="warning"
title="Client libraries need Data API to query your database"
>
Disabling it means supabase-js and similar libraries can't query or mutate data.
</Admonition>
)}
</div>
</FormItemLayout>
</Panel.Content>
)
}