mirror of
https://github.com/supabase/supabase.git
synced 2026-07-02 18:34:44 +08:00
## Problem We need a local-only UI to inspect client and server telemetry events and override flags during development without touching non-local env behavior. This work is intended to be shared across Studio, Docs, and WWW. ## Changes - Introduced a shared `dev-tools` package with the Dev Telemetry Toolbar UI, trigger, and provider. - Wired the toolbar into Studio, Docs, and WWW app shells (local-only gating). - Added a local-only `devTelemetry()` opt-in with storage gating and SSE subscription. - Wired client PostHog events into a local listener and re-exported types. - Added local flag override cookie support in the UI and CODEOWNERS for the new package. - Added unit tests covering local/non-local behavior and flag utilities. ## Testing Manual (local only): - Start each app locally: `pnpm dev:studio`, `pnpm dev:docs`, `pnpm dev:www` - Open the app, run `devTelemetry()` in the browser console - Click around and confirm both client and server events appear (client will be page views only) - Verify feature flag overrides (PostHog + ConfigCat) persist and restore correctly - Confirm dismissing the toolbar clears local storage and hides the trigger Unblocked by https://github.com/supabase/platform/pull/29172 Resolves GROWTH-591 Demo: [github.com/user-attachments/assets/60b376db-7440-4ada-82f5-d1bd4af4db3b](https://github.com/user-attachments/assets/60b376db-7440-4ada-82f5-d1bd4af4db3b) Screenshots: <img width="1368" height="972" alt="1" src="https://github.com/user-attachments/assets/d2f20a0c-191f-4118-bb5e-15b25f5a54a9" /> <img width="1423" height="790" alt="2" src="https://github.com/user-attachments/assets/115598e2-7287-49bf-9ed7-71ecc679dee3" /> <img width="1433" height="882" alt="3" src="https://github.com/user-attachments/assets/51f666f2-9efc-410f-baec-378bdee9dbfe" /> <img width="608" height="483" alt="4" src="https://github.com/user-attachments/assets/584d6cf5-1b2f-4cee-9e6a-d55ce2e3bae5" /> <img width="628" height="305" alt="5" src="https://github.com/user-attachments/assets/991a9b39-578a-4565-b110-537a02040a53" /> <img width="659" height="447" alt="6" src="https://github.com/user-attachments/assets/95ef405c-fffa-44af-bf6a-f974b780e3fc" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Developer Toolbar (local only): view client/server telemetry, inspect events, and manage/override feature flags with persistent overrides, filtering, and clear/reload. * Client-side telemetry hooks: surface structured events to dev tooling for realtime inspection. * **Bug Fixes** * Fixed end-of-file newline in shared code. * **Chores** * Added dev-tools package, integrated provider and trigger across Studio, Docs, and marketing sites, and added CODEOWNERS entry. * **Tests** * Added comprehensive tests and test setup for the DevToolbar. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
133 lines
4.6 KiB
TypeScript
133 lines
4.6 KiB
TypeScript
import { Command, Menu, Search } from 'lucide-react'
|
|
import dynamic from 'next/dynamic'
|
|
import Image from 'next/image'
|
|
import Link from 'next/link'
|
|
import type { FC } from 'react'
|
|
import { memo, useState } from 'react'
|
|
// End of third-party imports
|
|
|
|
import { useIsLoggedIn, useIsUserLoading, useUser } from 'common'
|
|
import { isFeatureEnabled } from 'common/enabled-features'
|
|
import { DevToolbarTrigger } from 'dev-tools'
|
|
import { Button, buttonVariants, cn } from 'ui'
|
|
import { AuthenticatedDropdownMenu, CommandMenuTriggerInput } from 'ui-patterns'
|
|
import { getCustomContent } from '../../../lib/custom-content/getCustomContent'
|
|
import GlobalNavigationMenu from './GlobalNavigationMenu'
|
|
import useDropdownMenu from './useDropdownMenu'
|
|
|
|
const GlobalMobileMenu = dynamic(() => import('./GlobalMobileMenu'))
|
|
const TopNavDropdown = dynamic(() => import('./TopNavDropdown'))
|
|
|
|
const largeLogo = isFeatureEnabled('branding:large_logo')
|
|
|
|
const TopNavBar: FC = () => {
|
|
const isLoggedIn = useIsLoggedIn()
|
|
const isUserLoading = useIsUserLoading()
|
|
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
|
const user = useUser()
|
|
const menu = useDropdownMenu(user)
|
|
|
|
return (
|
|
<>
|
|
<nav
|
|
aria-label="top bar"
|
|
className="w-full z-40 flex flex-col border-b backdrop-blur backdrop-filter bg bg-opacity-75"
|
|
>
|
|
<div className="w-full px-5 lg:pl-10 flex justify-between h-[var(--header-height)] gap-3">
|
|
<div className="hidden lg:flex h-full items-center justify-center gap-2">
|
|
<HeaderLogo />
|
|
<GlobalNavigationMenu />
|
|
</div>
|
|
<div className="w-full grow lg:w-auto flex gap-3 justify-between lg:justify-end items-center h-full">
|
|
<div className="lg:hidden">
|
|
<HeaderLogo />
|
|
</div>
|
|
|
|
<div className="flex gap-2 items-center">
|
|
<DevToolbarTrigger />
|
|
<CommandMenuTriggerInput
|
|
placeholder={
|
|
<>
|
|
Search
|
|
<span className="hidden xl:inline ml-1"> docs...</span>
|
|
</>
|
|
}
|
|
/>
|
|
<button
|
|
title="Menu dropdown button"
|
|
className={cn(
|
|
buttonVariants({ type: 'default' }),
|
|
'flex lg:hidden border-default bg-surface-100/75 text-foreground-light rounded-md min-w-[30px] w-[30px] h-[30px] data-[state=open]:bg-overlay-hover/30'
|
|
)}
|
|
onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
|
|
>
|
|
<Menu size={18} strokeWidth={1} />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div className="hidden lg:flex items-center justify-end gap-3">
|
|
{!isUserLoading && (
|
|
<Button asChild>
|
|
<a href="/dashboard" className="h-[30px]" target="_blank" rel="noreferrer noopener">
|
|
{isLoggedIn ? 'Dashboard' : 'Sign up'}
|
|
</a>
|
|
</Button>
|
|
)}
|
|
{process.env.NEXT_PUBLIC_DEV_AUTH_PAGE === 'true' && (
|
|
<Button asChild>
|
|
<Link href="/dev-secret-auth">Dev-only secret sign-in</Link>
|
|
</Button>
|
|
)}
|
|
{isLoggedIn ? (
|
|
<AuthenticatedDropdownMenu menu={menu} user={user} site="docs" />
|
|
) : (
|
|
<TopNavDropdown />
|
|
)}
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
<GlobalMobileMenu open={mobileMenuOpen} setOpen={setMobileMenuOpen} />
|
|
</>
|
|
)
|
|
}
|
|
|
|
const HeaderLogo = memo(() => {
|
|
const { navigationLogo } = getCustomContent(['navigation:logo'])
|
|
|
|
return (
|
|
<Link
|
|
href="/"
|
|
className={cn(
|
|
buttonVariants({ type: 'default' }),
|
|
'flex shrink-0 items-center w-fit !bg-transparent !border-none !shadow-none'
|
|
)}
|
|
>
|
|
<Image
|
|
className={cn('hidden dark:block !m-0', largeLogo && 'h-[36px]')}
|
|
src={navigationLogo?.dark ?? '/docs/supabase-dark.svg'}
|
|
priority={true}
|
|
loading="eager"
|
|
width={navigationLogo?.width ?? 96}
|
|
height={navigationLogo?.height ?? 18}
|
|
alt="Supabase wordmark"
|
|
/>
|
|
<Image
|
|
className={cn('block dark:hidden !m-0', largeLogo && 'h-[36px]')}
|
|
src={navigationLogo?.light ?? '/docs/supabase-light.svg'}
|
|
priority={true}
|
|
loading="eager"
|
|
width={navigationLogo?.width ?? 96}
|
|
height={navigationLogo?.height ?? 18}
|
|
alt="Supabase wordmark"
|
|
/>
|
|
<span className="font-mono text-sm font-medium text-brand-link mb-px">DOCS</span>
|
|
</Link>
|
|
)
|
|
})
|
|
|
|
HeaderLogo.displayName = 'HeaderLogo'
|
|
|
|
TopNavBar.displayName = 'TopNavBar'
|
|
|
|
export default TopNavBar
|