mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## 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>
51 lines
2.1 KiB
TypeScript
51 lines
2.1 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { useParams } from 'common'
|
|
|
|
import { formatCellAsAvailabilityZone, getPoolerStatus } from './HaTopology.utils'
|
|
import { AVAILABLE_REPLICA_REGIONS } from './InstanceConfiguration.constants'
|
|
import { haClusterPoolersQueryOptions } from '@/data/ha-admin/ha-cluster-poolers-query'
|
|
import { usePrimaryDatabase } from '@/data/read-replicas/replicas-query'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { getComputeSizeLabel } from '@/lib/compute-labels'
|
|
|
|
/**
|
|
* Subscribes to a single pooler's live state from the shared poolers query, so
|
|
* each node/edge updates on its own without re-laying-out the whole diagram.
|
|
*/
|
|
export const useHaPooler = ({ cell, name }: { cell?: string; name?: string }) => {
|
|
const { ref: projectRef } = useParams()
|
|
|
|
return useQuery({
|
|
...haClusterPoolersQueryOptions({ projectRef }),
|
|
select: (data) =>
|
|
(data.poolers ?? []).find((pooler) => pooler.id?.cell === cell && pooler.id?.name === name),
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Everything a pooler node card displays. Region and compute size aren't in
|
|
* multiadmin — region comes from the primary database row and compute size
|
|
* from the project. HA locks compute to one project-level size, so the
|
|
* project's size is correct for every node in the cluster.
|
|
*/
|
|
export const useHaPoolerCard = ({ cell, name }: { cell?: string; name?: string }) => {
|
|
const { ref: projectRef } = useParams()
|
|
const { projectHomepageShowInstanceSize } = useIsFeatureEnabled([
|
|
'project_homepage:show_instance_size',
|
|
])
|
|
|
|
const { database: primary } = usePrimaryDatabase({ projectRef })
|
|
const { data: pooler } = useHaPooler({ cell, name })
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
return {
|
|
status: pooler !== undefined ? getPoolerStatus(pooler) : undefined,
|
|
availabilityZone: formatCellAsAvailabilityZone(cell),
|
|
computeSize: projectHomepageShowInstanceSize
|
|
? getComputeSizeLabel(project?.infra_compute_size)
|
|
: undefined,
|
|
primaryRegion: AVAILABLE_REPLICA_REGIONS.find((r) => primary?.region.includes(r.region)),
|
|
}
|
|
}
|