Files
supabase/apps/studio/components/interfaces/ConnectSheet/ConnectStepsSection.utils.ts
Joshen Lim b1b2cf3e6b Update checks for showing ipv4 callout (#51018)
## Context

Updates checks for showing IPv4 add on callouts, should only be visible
if the project's provider is AWS

Involves updating 3 files:
- `ConnectionPooling.tsx` - adds check for cloud provider + enabled
features
- `ConnectStepsSection.tsx` - adds check for cloud provider + enabled
features
- `Ipv4StatusPanel.tsx` - realised this is dead code, so deleted

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

* **Updates**
* IPv4 add-on notices in connection setup and connection pooling appear
only for AWS projects with IPv4 enabled, when the existing connection
and configuration requirements are met.
* **Removals**
* The standalone IPv4 status panel has been removed from the connection
setup flow.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-29 20:30:14 +08:00

97 lines
2.4 KiB
TypeScript

import type { ConnectMode, ConnectState } from './Connect.types'
type FieldValue = ConnectState[string]
/**
* Resolves a content path template by replacing {{key}} placeholders with state values.
* Empty segments are filtered out to handle optional state values like frameworkVariant.
*
* Examples:
* - '{{framework}}/{{frameworkVariant}}/{{library}}' with state {framework: 'nextjs', frameworkVariant: 'app', library: 'supabasejs'}
* → 'nextjs/app/supabasejs'
* - '{{orm}}' with state {orm: 'prisma'}
* → 'prisma'
* - 'steps/install' (no templates)
* → 'steps/install'
*/
export function resolveContentPath(template: string, state: ConnectState): string {
return template
.replace(/\{\{(\w+)\}\}/g, (_, key) => String(state[key] ?? ''))
.split('/')
.filter(Boolean)
.join('/')
}
export function shouldShowIpv4AddonNotice({
isAws,
isIpv4Enabled,
isPlatform,
mode,
connectionMethod,
useSharedPooler,
hasIpv4Addon,
isHighAvailability,
}: {
isAws: boolean
isIpv4Enabled: boolean
isPlatform: boolean
mode: ConnectMode
connectionMethod: FieldValue
useSharedPooler: FieldValue
hasIpv4Addon: boolean
isHighAvailability: boolean
}): boolean {
// The IPv4 add-on does not apply to Multigres connections
if (
!isPlatform ||
!isAws ||
!isIpv4Enabled ||
mode !== 'direct' ||
hasIpv4Addon ||
isHighAvailability
)
return false
return connectionMethod === 'direct' || (connectionMethod === 'transaction' && !useSharedPooler)
}
export function shouldShowSessionPoolerNotice({
isPlatform,
mode,
connectionMethod,
}: {
isPlatform: boolean
mode: ConnectMode
connectionMethod: FieldValue
}): boolean {
return isPlatform && mode === 'direct' && connectionMethod === 'session'
}
export function shouldShowSelfHostedMcpNotice({
isSelfHosted,
mode,
}: {
isSelfHosted: boolean
mode: ConnectMode
}): boolean {
return isSelfHosted && mode === 'mcp'
}
export function shouldFetchDataApiConfig({ mode }: { mode: ConnectMode }): boolean {
return mode === 'framework'
}
export function shouldShowDataApiDisabledWarning({
mode,
isDataApiEnabled,
isPending,
isError,
}: {
mode: ConnectMode
isDataApiEnabled: boolean
isPending: boolean
isError: boolean
}): boolean {
if (isPending || isError || isDataApiEnabled) return false
return shouldFetchDataApiConfig({ mode })
}