mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
## Summary Adds PostHog click/open tracking for every interactive element in the Studio top bar. Previously only 5 of ~16 surfaces were tracked. ### New events (16) | Event | Surface | |---|---| | `home_logo_clicked` | Supabase logo | | `header_back_to_dashboard_clicked` | Mobile back chevron | | `header_exceeding_usage_badge_clicked` | "Exceeding usage limits" badge | | `organization_dropdown_opened` | Org dropdown trigger | | `project_dropdown_opened` | Project dropdown trigger | | `branch_dropdown_opened` | Branch dropdown trigger | | `merge_request_button_clicked` | MR trigger (separate from existing success event) | | `connect_button_clicked` | Connect CTA | | `feedback_dropdown_opened` | Feedback dropdown trigger | | `advisor_button_clicked` | Advisor toggle | | `inline_editor_button_clicked` | SQL editor toggle | | `assistant_button_clicked` | AI Assistant toggle | | `user_dropdown_opened` | Account dropdown | | `local_dropdown_opened` | Local-dev settings dropdown | | `local_version_popover_opened` | CLI version popover | ### Notes - Uses `useTrack` (per `telemetry-standards`), all event names use approved `_clicked` / `_opened` verbs. - Dropdown `onOpenChange` handlers guard against Radix's double-fire by only tracking when `open === true`. - `merge_request_button_clicked` fires on the trigger click; the existing `branch_create_merge_request_button_clicked` continues to fire on successful MR creation. - Pre-existing tracked surfaces (`command_menu_opened`, `help_button_clicked`, `header_upgrade_cta_clicked`, `send_feedback_button_clicked`) are unchanged. ## Test plan - [x] Spot-check each event fires once per interaction in PostHog Live Events - [x] Verify no double-fire on dropdown close <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Added telemetry tracking for many header/navigation interactions (logo, back-to-dashboard, usage badge, connect/merge/advisor/assistant/inline-editor buttons, and multiple dropdowns/popovers). * **Tests** * Updated tests to stub telemetry calls so UI tests remain stable and deterministic. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
114 lines
3.5 KiB
TypeScript
114 lines
3.5 KiB
TypeScript
import { useParams } from 'common'
|
|
import { useState } from 'react'
|
|
import { ShimmeringLoader } from 'ui-patterns'
|
|
|
|
import { AppLayoutDropdownError, AppLayoutDropdownWithPopover } from './AppLayoutDropdown'
|
|
import { BranchBadge } from './BranchBadge'
|
|
import { BranchDropdownCommandContent } from './BranchDropdownCommandContent'
|
|
import { useEmbeddedCloseHandler } from './useEmbeddedCloseHandler'
|
|
import { useBranchesQuery } from '@/data/branches/branches-query'
|
|
import type { Branch } from '@/data/branches/branches-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
interface BranchDropdownProps {
|
|
embedded?: boolean
|
|
className?: string
|
|
onClose?: () => void
|
|
}
|
|
|
|
export const BranchDropdown = ({
|
|
embedded = false,
|
|
className,
|
|
onClose,
|
|
}: BranchDropdownProps = {}) => {
|
|
const { ref } = useParams()
|
|
const snap = useAppStateSnapshot()
|
|
const { data: projectDetails } = useSelectedProjectQuery()
|
|
|
|
const [open, setOpen] = useState(false)
|
|
const close = useEmbeddedCloseHandler(embedded, onClose, setOpen)
|
|
const track = useTrack()
|
|
|
|
const handleOpenChange = (next: boolean) => {
|
|
if (next) track('header_branch_dropdown_opened')
|
|
setOpen(next)
|
|
}
|
|
|
|
const projectRef = projectDetails?.parent_project_ref || ref
|
|
|
|
const {
|
|
data: branches,
|
|
isPending: isLoading,
|
|
isError,
|
|
isSuccess,
|
|
} = useBranchesQuery({ projectRef }, { enabled: Boolean(projectDetails) })
|
|
|
|
const isBranchingEnabled = projectDetails?.is_branch_enabled === true
|
|
const selectedBranch = branches?.find((branch) => branch.project_ref === ref)
|
|
|
|
const defaultMainBranch = {
|
|
id: 'main',
|
|
name: 'main',
|
|
project_ref: projectRef ?? ref ?? '',
|
|
is_default: true,
|
|
} as unknown as Branch
|
|
|
|
const mainBranch = branches?.find((branch) => branch.is_default)
|
|
const restOfBranches = branches
|
|
?.filter((branch) => !branch.is_default)
|
|
?.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())
|
|
|
|
const sortedBranches =
|
|
branches && branches.length > 0
|
|
? mainBranch
|
|
? [mainBranch].concat(restOfBranches ?? [])
|
|
: (restOfBranches ?? [])
|
|
: [defaultMainBranch]
|
|
const branchList = isBranchingEnabled ? (sortedBranches ?? []) : [defaultMainBranch]
|
|
|
|
const commandContent = (
|
|
<BranchDropdownCommandContent
|
|
embedded={embedded}
|
|
className={className}
|
|
branchList={branchList}
|
|
selectedBranch={selectedBranch}
|
|
branchesCount={branches?.length ?? 0}
|
|
isBranchingEnabled={isBranchingEnabled}
|
|
projectRef={ref}
|
|
onClose={close}
|
|
onCreateBranch={() => snap.setShowCreateBranchModal(true)}
|
|
/>
|
|
)
|
|
|
|
if (isLoading) return <ShimmeringLoader className="p-2 md:w-[90px]" />
|
|
|
|
if (isError) return <AppLayoutDropdownError message="Failed to load branches" />
|
|
|
|
if (!isSuccess) return null
|
|
|
|
if (embedded) return commandContent
|
|
|
|
return (
|
|
<AppLayoutDropdownWithPopover
|
|
linkHref={`/project/${ref}`}
|
|
linkContent={
|
|
<>
|
|
<span
|
|
title={isBranchingEnabled ? selectedBranch?.name : 'main'}
|
|
className="text-sm text-foreground max-w-32 lg:max-w-64 truncate"
|
|
>
|
|
{isBranchingEnabled ? selectedBranch?.name : 'main'}
|
|
</span>
|
|
<BranchBadge branch={selectedBranch} isBranchingEnabled={isBranchingEnabled} />
|
|
</>
|
|
}
|
|
linkClassName="flex items-center gap-2 shrink-0"
|
|
commandContent={commandContent}
|
|
open={open}
|
|
onOpenChange={handleOpenChange}
|
|
/>
|
|
)
|
|
}
|