mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
The Connect sheet only reports a copy for the Postgres connection string and one MCP setup step. The Connect dialog it replaced also reported framework, mobile framework and ORM snippet copies and every MCP client's copy (#40611); that tracking was not carried over (#44327) and the dialog was later removed (#47122). I restored it with the existing `connection_string_copied` event, and added the sheet's command copies and Copy prompt so the whole sheet is covered. **Changed:** - **Framework, mobile framework and ORM snippets**: copying any file tab in the configure step sends `connection_string_copied` with `connectionTab` (`App Frameworks`, `Mobile Frameworks` or `ORMs`), `selectedItem` (the framework or ORM label) and `source: studio`. A framework added to the sheet later is covered without touching its content file. - **Install commands**: the framework, ORM, shadcn and skills install commands send the same event with `connectionType: Install command`, so they can be told apart from snippet copies. - **Claude Code and Codex MCP**: the add-server, authenticate and verify commands send the event with `connectionTab: MCP`, the client label and `connectionType: Command Line`. - **Copy prompt**: sends the existing `ai_prompt_copied` event with a new `source` value, `connect_sheet`. **Note:** `lang` carries the client library key (for example `supabasejs`), as the old dialog sent it, so the restored series lines up with the data from before March. Filter on `connectionType` to count snippet copies only: `Framework snippet` for frameworks, absent for ORM snippets. In Direct mode the install and skills install commands send the event with `connectionTab: Connection String` and `lang: bash`; the Direct file examples and Server mode are unchanged. In MCP mode the skills install command sends nothing, so the `MCP` series only counts MCP setup copies. ## To test Tested on the PR preview, with the network tab filtered to the telemetry event request: - [x] Open a project, open Connect, keep Framework on Next.js and click Copy on a file tab in the configure step; expect one `connection_string_copied` with `connectionTab: App Frameworks`, `selectedItem: Next.js`, `connectionType: Framework snippet`, `source: studio` - [x] Still on Next.js, switch to the `.env.local` tab and copy it; expect the same event again (one per click) - [x] Switch the framework to Flutter and copy a file tab; expect `connectionTab: Mobile Frameworks`, `selectedItem: Flutter` - [x] Switch to ORM, pick Prisma and copy a file tab; expect `connectionTab: ORMs`, `selectedItem: Prisma` and no `connectionType` - [x] Switch to MCP, pick Claude Code and copy the add-server command; expect `connectionTab: MCP`, `selectedItem: Claude Code`, `connectionType: Command Line` - [x] Still on Claude Code, copy the authenticate command; expect the same properties. Pick Codex and copy add-server, authenticate and verify; expect `selectedItem: Codex` on each - [x] In Framework mode copy the install command and the skills install command; expect `connection_string_copied` with `connectionType: Install command` and `connectionTab: App Frameworks` for each. In ORM mode copy an install command; expect `connectionTab: ORMs`, `connectionType: Install command` - [ ] In Direct mode copy the skills install command; expect `connection_string_copied` with `connectionTab: Connection String`, `connectionType: Install command`, `lang: bash` - [ ] In MCP mode copy the skills install command; expect no `connection_string_copied` request - [x] Click Copy prompt; expect one `ai_prompt_copied` with `source: connect_sheet` and no `connection_string_copied` - [x] Switch to Server and copy the env block; expect no `connection_string_copied` request - [x] Switch to Direct and copy the connection string; expect exactly one `connection_string_copied` with `connectionTab: Connection String` (unchanged behavior, no duplicate) ## Linear - fixes GROWTH-1532
155 lines
4.1 KiB
TypeScript
155 lines
4.1 KiB
TypeScript
import type { ConnectionStringCopiedEvent } from 'common/telemetry-constants'
|
|
import { MCP_CLIENT_DATA } from 'ui-patterns/McpUrlBuilder/clients.data'
|
|
|
|
import { FRAMEWORKS, MOBILES, ORMS } from './Connect.constants'
|
|
import type { ConnectMode, ConnectState } from './Connect.types'
|
|
|
|
type FieldValue = ConnectState[string]
|
|
|
|
export type ConnectCopyType = 'Install command' | 'Command Line'
|
|
|
|
/**
|
|
* Properties for a `connection_string_copied` event fired from the Connect sheet.
|
|
* Without a `copyType` the copy is a framework or ORM file snippet.
|
|
*/
|
|
export function getConnectCopyProperties(
|
|
state: ConnectState,
|
|
copyType?: ConnectCopyType
|
|
): ConnectionStringCopiedEvent['properties'] | undefined {
|
|
if (state.mode === 'orm') {
|
|
const orm = ORMS.find((item) => item.key === state.orm)
|
|
return {
|
|
connectionTab: 'ORMs',
|
|
selectedItem: orm?.label,
|
|
...(copyType && { connectionType: copyType }),
|
|
source: 'studio',
|
|
}
|
|
}
|
|
|
|
if (state.mode === 'mcp') {
|
|
if (copyType !== 'Command Line') return undefined
|
|
const client = MCP_CLIENT_DATA.find((item) => item.key === state.mcpClient)
|
|
return {
|
|
connectionTab: 'MCP',
|
|
selectedItem: client?.label,
|
|
connectionType: copyType,
|
|
source: 'studio',
|
|
}
|
|
}
|
|
|
|
if (state.mode === 'direct') {
|
|
if (!copyType) return undefined
|
|
return {
|
|
connectionTab: 'Connection String',
|
|
connectionType: copyType,
|
|
lang: 'bash',
|
|
source: 'studio',
|
|
}
|
|
}
|
|
|
|
if (state.mode !== 'framework') return undefined
|
|
|
|
const mobile = MOBILES.find((item) => item.key === state.framework)
|
|
const framework = mobile ?? FRAMEWORKS.find((item) => item.key === state.framework)
|
|
return {
|
|
connectionTab: mobile ? 'Mobile Frameworks' : 'App Frameworks',
|
|
selectedItem: framework?.label,
|
|
connectionType: copyType ?? 'Framework snippet',
|
|
lang: String(state.library ?? 'unknown'),
|
|
source: 'studio',
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 })
|
|
}
|