mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem
Part of FE-5266 (remove or sample noisy Studio events). The
`header_{organization,project,branch,user}_dropdown_opened` events are
among the highest-volume events and don't answer a product question: the
next pageview already shows what was selected. Their owner signed off on
removing them.
## Solution
- Remove the `track()` calls from the organization, project, branch and
user dropdowns. Each now passes its state setter straight to
`onOpenChange`.
- Drop the `useTrack` import from `BranchDropdown` and
`ProjectDropdown`, which no longer track anything.
- Remove the four event types and their `TelemetryEvent` union entries.
`header_feedback_dropdown_opened` is kept. `upgrade_cta_clicked` in the
user and organization dropdowns is untouched. This is a standalone PR so
it can be reverted on its own.
201 lines
7.2 KiB
TypeScript
201 lines
7.2 KiB
TypeScript
import { Link, useLocation, useNavigate } from '@tanstack/react-router'
|
|
import { useDevToolbar } from 'dev-tools'
|
|
import { FlaskConicalIcon, Loader2Icon, ScrollTextIcon, User2Icon } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import { useState } from 'react'
|
|
import {
|
|
cn,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuRadioGroup,
|
|
DropdownMenuRadioItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
singleThemes,
|
|
} from 'ui'
|
|
|
|
import { ButtonTooltip } from '../ui/ButtonTooltip'
|
|
import { useFeaturePreviewModal } from './App/FeaturePreview/FeaturePreviewContext'
|
|
import { DevToolbarMenuGroup } from './DevToolbarMenuGroup'
|
|
import { TimezoneDropdown } from './UserDropdown/TimezoneDropdown'
|
|
import { ProfileImage } from '@/components/ui/ProfileImage'
|
|
import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { useShowUpgradeCta } from '@/hooks/misc/useShowUpgradeCta'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import { useProfileNameAndPicture } from '@/lib/profile'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
export function UserDropdown({
|
|
triggerClassName,
|
|
contentClassName,
|
|
}: {
|
|
triggerClassName?: string
|
|
contentClassName?: string
|
|
}) {
|
|
const navigate = useNavigate()
|
|
const pathname = useLocation({ select: (location) => location.pathname })
|
|
const currentRoute = useLocation({ select: (location) => location.href })
|
|
const { theme, setTheme } = useTheme()
|
|
const appStateSnapshot = useAppStateSnapshot()
|
|
const profileShowEmailEnabled = useIsFeatureEnabled('profile:show_email')
|
|
const { username, avatarUrl, primaryEmail, isLoading } = useProfileNameAndPicture()
|
|
|
|
const { toggleFeaturePreviewModal } = useFeaturePreviewModal()
|
|
const track = useTrack()
|
|
const { isAvailable: isDevToolbarAvailable } = useDevToolbar()
|
|
const shouldShowSectionSeparator = IS_PLATFORM || isDevToolbarAvailable
|
|
|
|
// The upgrade CTA is org-scoped, so only enable it on routes where an org is in scope.
|
|
// Excludes /account/*, /organizations, /new, marketing routes, etc. Gating the hook here
|
|
// also skips fetching organization data on routes where the CTA can't render.
|
|
const isOrgScopedRoute = pathname.startsWith('/project/') || pathname.startsWith('/org/')
|
|
const { showUpgradeCta } = useShowUpgradeCta({ enabled: isOrgScopedRoute })
|
|
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
return (
|
|
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
|
|
<DropdownMenuTrigger asChild className={cn('border shrink-0 px-3', triggerClassName)}>
|
|
<ButtonTooltip
|
|
className="[&>span]:flex px-0 py-0 rounded-full overflow-hidden h-8 w-8"
|
|
tooltip={{ content: { text: 'Account settings' } }}
|
|
>
|
|
{isLoading ? (
|
|
<div className="w-full h-full flex items-center justify-center">
|
|
<Loader2Icon className="animate-spin text-foreground-lighter" size={16} />
|
|
</div>
|
|
) : (
|
|
<ProfileImage alt={username} src={avatarUrl} className="w-8 h-8 rounded-md" />
|
|
)}
|
|
</ButtonTooltip>
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent side="bottom" align="end" className={contentClassName}>
|
|
{IS_PLATFORM && (
|
|
<>
|
|
<div className="px-2 py-1 flex flex-col gap-0 text-sm">
|
|
{!!username ? (
|
|
<>
|
|
<span title={username} className="w-full text-left text-foreground truncate">
|
|
{username}
|
|
</span>
|
|
{primaryEmail !== username && profileShowEmailEnabled && (
|
|
<span
|
|
title={primaryEmail}
|
|
className="w-full text-left text-foreground-light text-xs truncate"
|
|
>
|
|
{primaryEmail}
|
|
</span>
|
|
)}
|
|
</>
|
|
) : (
|
|
<span title={primaryEmail} className="w-full text-left text-foreground truncate">
|
|
{primaryEmail}
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
|
|
<Link
|
|
to="/account/me"
|
|
onClick={() => {
|
|
if (pathname !== '/account/me') {
|
|
appStateSnapshot.setLastRouteBeforeVisitingAccountPage(currentRoute)
|
|
}
|
|
}}
|
|
>
|
|
<User2Icon size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Account
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
className="flex gap-2 cursor-pointer"
|
|
onClick={() => toggleFeaturePreviewModal(true)}
|
|
>
|
|
<FlaskConicalIcon size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Feature previews
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
|
|
<a href="https://supabase.com/changelog" target="_blank" rel="noopener noreferrer">
|
|
<ScrollTextIcon size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Changelog
|
|
</a>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuGroup>
|
|
</>
|
|
)}
|
|
|
|
{shouldShowSectionSeparator && <DropdownMenuSeparator />}
|
|
|
|
<DevToolbarMenuGroup />
|
|
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuLabel>Theme</DropdownMenuLabel>
|
|
<DropdownMenuRadioGroup
|
|
value={theme}
|
|
onValueChange={(value) => {
|
|
setTheme(value)
|
|
}}
|
|
>
|
|
{singleThemes.map((theme) => (
|
|
<DropdownMenuRadioItem
|
|
key={theme.value}
|
|
value={theme.value}
|
|
className="cursor-pointer"
|
|
>
|
|
{theme.name}
|
|
</DropdownMenuRadioItem>
|
|
))}
|
|
</DropdownMenuRadioGroup>
|
|
</DropdownMenuGroup>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuGroup>
|
|
<TimezoneDropdown />
|
|
</DropdownMenuGroup>
|
|
|
|
{showUpgradeCta && (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
<div className="p-1">
|
|
<UpgradePlanButton
|
|
source="user_dropdown"
|
|
plan="Pro"
|
|
className="w-full justify-center"
|
|
onClick={() => {
|
|
track('upgrade_cta_clicked', { placement: 'user_dropdown' })
|
|
setIsOpen(false)
|
|
}}
|
|
/>
|
|
</div>
|
|
</>
|
|
)}
|
|
{IS_PLATFORM && (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuItem
|
|
className="cursor-pointer"
|
|
onSelect={() => {
|
|
navigate({ to: '/logout' })
|
|
}}
|
|
>
|
|
Sign out
|
|
</DropdownMenuItem>
|
|
</DropdownMenuGroup>
|
|
</>
|
|
)}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|