mirror of
https://github.com/supabase/supabase.git
synced 2026-09-09 03:19:36 +08:00
## What kind of change does this PR introduce? Feature ## What is the current behavior? The dev toolbar is only discoverable via `window.devToolbar()` in the browser console, or by having your email on the `devToolbarDefaultOn` ConfigCat flag. Once enabled, Studio shows a floating trigger button. ## What is the new behavior? In local and staging Studio, the account/settings dropdown (avatar menu) includes a **Local tools** section above **Theme** with a **Dev toolbar** checkbox toggle. - **On**: shows the floating orb (persists via localStorage, same as `window.devToolbar()`) - **Off**: hides the orb and dismisses the toolbar Open the panel itself via the orb once it is visible. Production builds are unchanged (`isAvailable` is false and the menu item is hidden). | After | | --- | | <img width="226" height="204" alt="CleanShot 2026-08-20 at 12 46 38@2x" src="https://github.com/user-attachments/assets/c846b119-626d-48f5-9a02-aef4d006326c" /> | | <img width="558" height="1024" alt="CleanShot 2026-08-20 at 12 47 04@2x" src="https://github.com/user-attachments/assets/4b3dd22b-537b-4874-821d-c202033c4ad7" /> | ## Manual testing Run `pnpm dev:studio` and open http://localhost:8082. 1. **Find the entry point:** top-right avatar/settings menu → **Local tools** → **Dev toolbar** (above **Theme**). Should not appear in production builds. 2. **Turn it on:** check **Dev toolbar**. A green floating orb should appear (default bottom-right). 3. **Open the panel:** click the orb. The **Dev Toolbar** sheet should open with Events and Flags tabs. 4. **Event count:** navigate around Studio (e.g. open a project, switch pages). The orb badge should increment and stay readable in light and dark mode. 5. **Turn it off:** reopen the avatar menu and uncheck **Dev toolbar**. The orb and panel should disappear. 6. **Close vs hide:** with the toolbar on, open the sheet and use **Close** (X). The orb should remain; only the sheet closes. Optional: confirm `window.devToolbar()` in the browser console still enables the orb. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a Local tools option to enable the development toolbar when available. * Toolbar activation and dismissal preferences now persist between sessions. * Added clearer event-count badges with responsive sizing for larger counts. * **Improvements** * Simplified toolbar controls by removing the separate hide option. * Improved toolbar availability handling across local and production environments. * **Tests** * Expanded coverage for activation, persistence, visibility, and event-count badges. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Danny White <dnywh@users.noreply.github.com> Co-authored-by: Sean Oliver <882952+seanoliver@users.noreply.github.com>
212 lines
7.3 KiB
TypeScript
212 lines
7.3 KiB
TypeScript
import { useDevToolbar } from 'dev-tools'
|
|
import { FlaskConical, Loader2, ScrollText, User2 } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import Link from 'next/link'
|
|
import { useRouter } from 'next/router'
|
|
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 router = useRouter()
|
|
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 =
|
|
router.pathname.startsWith('/project/') || router.pathname.startsWith('/org/')
|
|
const { showUpgradeCta } = useShowUpgradeCta({ enabled: isOrgScopedRoute })
|
|
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
return (
|
|
<DropdownMenu
|
|
open={isOpen}
|
|
onOpenChange={(open) => {
|
|
setIsOpen(open)
|
|
if (open) track('header_user_dropdown_opened')
|
|
}}
|
|
>
|
|
<DropdownMenuTrigger asChild className={cn('border shrink-0 px-3', triggerClassName)}>
|
|
<ButtonTooltip
|
|
variant="default"
|
|
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">
|
|
<Loader2 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
|
|
href="/account/me"
|
|
onClick={() => {
|
|
if (router.pathname !== '/account/me') {
|
|
appStateSnapshot.setLastRouteBeforeVisitingAccountPage(router.asPath)
|
|
}
|
|
}}
|
|
>
|
|
<User2 size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Account
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
className="flex gap-2 cursor-pointer"
|
|
onClick={() => toggleFeaturePreviewModal(true)}
|
|
>
|
|
<FlaskConical size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Feature previews
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
|
|
<Link
|
|
href="https://supabase.com/changelog"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
<ScrollText size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Changelog
|
|
</Link>
|
|
</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={() => {
|
|
router.push('/logout')
|
|
}}
|
|
>
|
|
Log out
|
|
</DropdownMenuItem>
|
|
</DropdownMenuGroup>
|
|
</>
|
|
)}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|