Files
supabase/apps/studio/lib/compute-labels.ts
Lukas BernertandClaude Fable 5 de32f3130b fix(studio): show compute size labels on infrastructure surfaces (#52170)
## Problem

We don't want to mention raw AWS instance type names. Instead only
display the actual instance size name (e.g. "Small", "Medium", ...).

Fixes PROD-673

## Solution

Add a `getComputeSizeLabel` helper (`apps/studio/lib/compute-labels.ts`)
that maps `infra_compute_size` to its display label (`medium` →
"Medium", `2xlarge` → "2XL", …) and returns `undefined` for unknown
values so callers render nothing instead of a raw value.

Studio elements changed:

- Read replica details: "Compute Size" field
(`/project/<project_id>/settings/infrastructure/replica/<replica_id>`)
- Infrastructure diagram: primary and replica node cards
(`generateNodes` now receives the label; replicas always match the
primary's compute size) (`/project/_/settings/infrastructure`)
- Map view: "AWS • {size}" line in the region popup
(`/project/<project_id>`)
- HA pooler node cards (`useHaPoolerCard`)

Also removes the `size` field from the create-replica request (API
ignores it).

Unit tests cover the new helper, including the unknown-value case. The
existing `project_homepage:show_instance_size` feature flag keeps gating
the label as before.

## Review instructions

1. Open a project's Infrastructure settings page
(`/project/_/settings/infrastructure`).
2. Check the diagram node cards and (for projects with replicas) the map
view popup: compute shows as "Small"/"Medium"-style labels matching the
project's compute badge.
3. Open a read replica's details page: the "Compute Size" field shows
the same label.
4. Open the add-replica dialog and submit: the request body contains
only `read_replica_region`.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-10-27 14:47:27 +01:00

50 lines
1.8 KiB
TypeScript

/** Compute sizes below Large run on shared compute; Large and up are dedicated. */
const SHARED_COMPUTE_SIZES = ['pico', 'nano', 'micro', 'small', 'medium']
export const isSharedComputeSize = (size: string) =>
SHARED_COMPUTE_SIZES.includes(size.toLowerCase().replace(/^ci_/, ''))
/**
* User-facing CPU description for a compute size. Branches on the size itself,
* not on `meta.cpu_cores` — the platform is dropping that field.
*/
export const getComputeCpuLabel = (size: string, vcpuCount?: number) => {
if (isSharedComputeSize(size)) return 'Shared compute'
return typeof vcpuCount === 'number' ? `Dedicated · ${vcpuCount} vCPUs` : 'Dedicated compute'
}
const COMPUTE_SIZE_LABELS: Record<string, string> = {
pico: 'Pico',
nano: 'Nano',
micro: 'Micro',
small: 'Small',
medium: 'Medium',
large: 'Large',
xlarge: 'XL',
'2xlarge': '2XL',
'4xlarge': '4XL',
'8xlarge': '8XL',
'12xlarge': '12XL',
'16xlarge': '16XL',
'24xlarge': '24XL',
'24xlarge_optimized_memory': '24XL - Optimized Memory',
'24xlarge_optimized_cpu': '24XL - Optimized CPU',
'24xlarge_high_memory': '24XL - High Memory',
'48xlarge': '48XL',
'48xlarge_optimized_memory': '48XL - Optimized Memory',
'48xlarge_optimized_cpu': '48XL - Optimized CPU',
'48xlarge_high_memory': '48XL - High Memory',
}
/**
* User-facing label for a project's compute size (`infra_compute_size`),
* e.g. 'medium' → "Medium", '2xlarge' → "2XL".
*
* Always label compute from `infra_compute_size` — it is the authoritative
* project-level size. `databases[].size` holds an internal identifier that
* is not shown in the UI. Unknown values return undefined so callers render
* nothing instead of a raw value.
*/
export const getComputeSizeLabel = (size: string | null | undefined): string | undefined =>
size ? COMPUTE_SIZE_LABELS[size.toLowerCase().replace(/^ci_/, '')] : undefined