Files
supabase/apps/studio/components/layouts/Navigation/LayoutHeader/LocalVersionPopover.tsx
Mert YEREKAPAN da81b2f14d feat(studio): add click tracking for top bar buttons (#45414)
## 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 -->
2026-05-05 16:12:51 +00:00

203 lines
8.1 KiB
TypeScript

import dayjs from 'dayjs'
import {
Badge,
Button,
Dialog,
DialogContent,
DialogHeader,
DialogSection,
DialogTitle,
DialogTrigger,
Popover_Shadcn_,
PopoverContent_Shadcn_,
PopoverSeparator_Shadcn_,
PopoverTrigger_Shadcn_,
Tabs_Shadcn_,
TabsContent_Shadcn_,
TabsList_Shadcn_,
TabsTrigger_Shadcn_,
} from 'ui'
import { Admonition } from 'ui-patterns/admonition'
import { SimpleCodeBlock } from 'ui-patterns/SimpleCodeBlock'
import { getSemver, semverGte, semverLte } from './LocalVersionPopover.utils'
import { DocsButton } from '@/components/ui/DocsButton'
import { InlineLink } from '@/components/ui/InlineLink'
import { useCLIReleaseVersionQuery } from '@/data/misc/cli-release-version-query'
import { DOCS_URL } from '@/lib/constants'
import { useTrack } from '@/lib/telemetry/track'
export const LocalVersionPopover = () => {
const { data, isSuccess } = useCLIReleaseVersionQuery()
const track = useTrack()
const currentCliVersion = data?.current
const latestCliVersion = data?.latest
const hasLatestCLIVersion = isSuccess && !!latestCliVersion
const current = getSemver(currentCliVersion)
const latest = getSemver(latestCliVersion)
const hasUpdate =
!!current && !!latest
? currentCliVersion !== latestCliVersion && semverLte(current, latest)
: false
const isBeta =
!!current && !!latest && currentCliVersion !== latestCliVersion && semverGte(current, latest)
const approximateNextRelease = !!data?.published_at
? dayjs(data?.published_at).utc().add(14, 'day').format('DD MMM YYYY')
: undefined
if (!isSuccess || !currentCliVersion) return null
return (
<Popover_Shadcn_
onOpenChange={(open) => {
if (open) track('header_local_version_popover_opened')
}}
>
<PopoverTrigger_Shadcn_ className="flex items-center">
<Badge variant={isBeta ? 'warning' : hasUpdate ? 'success' : 'default'}>
{isBeta ? 'Beta' : hasUpdate ? 'Update available' : 'Latest'}
</Badge>
</PopoverTrigger_Shadcn_>
<PopoverContent_Shadcn_ align="end" className="w-80 px-0">
{hasLatestCLIVersion ? (
!isBeta && hasUpdate ? (
<div className="px-4 mb-3">
<p className="text-sm mb-2">A new version of Supabase CLI is available:</p>
<Tabs_Shadcn_ defaultValue="macos">
<TabsList_Shadcn_ className="mt-2">
<TabsTrigger_Shadcn_ className="px-2 text-xs" value="macos">
macOS
</TabsTrigger_Shadcn_>
<TabsTrigger_Shadcn_ className="px-2 text-xs" value="windows">
Windows
</TabsTrigger_Shadcn_>
<TabsTrigger_Shadcn_ className="px-2 text-xs" value="linux">
Linux
</TabsTrigger_Shadcn_>
<TabsTrigger_Shadcn_ className="px-2 text-xs" value="npm">
npm / Bun
</TabsTrigger_Shadcn_>
</TabsList_Shadcn_>
<TabsContent_Shadcn_ className="mt-2 text-xs" value="macos">
<SimpleCodeBlock parentClassName="bg-selection rounded-sm px-2!">
brew upgrade supabase
</SimpleCodeBlock>
</TabsContent_Shadcn_>
<TabsContent_Shadcn_ className="mt-2 text-xs" value="windows">
<SimpleCodeBlock parentClassName="bg-selection rounded-sm px-2!">
scoop update supabase
</SimpleCodeBlock>
</TabsContent_Shadcn_>
<TabsContent_Shadcn_ className="mt-2 text-xs" value="linux">
<SimpleCodeBlock parentClassName="bg-selection rounded-sm px-2!">
brew upgrade supabase
</SimpleCodeBlock>
</TabsContent_Shadcn_>
<TabsContent_Shadcn_ className="mt-2 text-xs" value="npm">
<SimpleCodeBlock parentClassName="bg-selection rounded-sm px-2!">
npm update supabase --save-dev
</SimpleCodeBlock>
</TabsContent_Shadcn_>
</Tabs_Shadcn_>
</div>
) : (
<div className="px-4 mb-3">
{isBeta ? (
<p className="text-sm">You're on the Beta version of Supabase CLI</p>
) : (
<p className="text-sm">You're on the latest version of Supabase CLI</p>
)}
</div>
)
) : null}
<div className="flex flex-col gap-y-2 px-4">
<p className="text-xs text-foreground-lighter">
All available release versions of the CLI can be found on our{' '}
<InlineLink href="https://github.com/supabase/cli/releases">
GitHub repository
</InlineLink>
.
</p>
</div>
<div className="flex items-center gap-x-2 mt-3 px-4">
<Dialog>
<DialogTrigger asChild>
<Button type="default">Release schedule</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader className="border-b">
<DialogTitle>Stable release schedule</DialogTitle>
</DialogHeader>
<DialogSection className="flex flex-col gap-y-3">
<div className="flex flex-col gap-y-2">
<p className="text-foreground-lighter text-xs font-mono uppercase">
Approximate next release: {approximateNextRelease}
</p>
<p className="text-sm">
Supabase CLI releases follows a two-week schedule, with stable updates available
through the{' '}
<InlineLink
href={`${DOCS_URL}/guides/local-development/cli/getting-started?queryGroups=platform&platform=linux#updating-the-supabase-cli`}
>
CLI
</InlineLink>
.
</p>
</div>
<Admonition
type="default"
title="Beta Releases"
description="Beta releases are also available between stable releases through the Beta version of the CLI, which might be helpful if you are waiting for a specific fix."
>
<p className="mt-2!">If you'd like to try, we recommend doing so via npm:</p>
<div className="flex items-center bg-surface-200 py-1 px-2 rounded-sm mt-2 mb-1">
<SimpleCodeBlock parentClassName="bg-surface-200">
npm i supabase@beta --save-dev
</SimpleCodeBlock>
</div>
{
<p className="text-sm text-foreground-lighter">
Latest Beta version: <span>{data.beta}</span>
</p>
}
<DocsButton
href={`${DOCS_URL}/guides/local-development/cli/getting-started?queryGroups=platform&platform=linux#using-beta-version`}
className="no-underline! mt-2"
/>
</Admonition>
</DialogSection>
</DialogContent>
</Dialog>
<Button type="default" asChild>
<a
target="_blank"
rel="noreferrer noopener"
href={`${DOCS_URL}/guides/local-development/cli/getting-started?queryGroups=platform&platform=linux`}
>
CLI Docs
</a>
</Button>
</div>
<PopoverSeparator_Shadcn_ className="my-4" />
<div className="flex items-center gap-x-4 px-4">
<div className="flex flex-col gap-y-1">
<p className="text-xs">Current version:</p>
<p className="text-sm font-mono">{currentCliVersion}</p>
</div>
{hasLatestCLIVersion && hasUpdate && !isBeta && (
<div className="flex flex-col gap-y-1">
<p className="text-xs">Available version:</p>
<p className="text-sm font-mono">{latestCliVersion}</p>
</div>
)}
</div>
</PopoverContent_Shadcn_>
</Popover_Shadcn_>
)
}