Files
supabase/apps/studio/components/layouts/AppLayout/BranchDropdown.tsx
Drew McLellan 663f077b47 chore(studio): remove header dropdown opened events (#54533)
## 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.
2026-12-03 14:18:55 +00:00

128 lines
4.1 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { useParams } from 'common'
import { useState } from 'react'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import {
AppLayoutDropdownError,
AppLayoutDropdownTriggerButton,
AppLayoutDropdownWithPopover,
} from './AppLayoutDropdown'
import { BranchBadge } from './BranchBadge'
import { BranchDropdownCommandContent } from './BranchDropdownCommandContent'
import { useEmbeddedCloseHandler } from './useEmbeddedCloseHandler'
import { branchesQueryOptions } from '@/data/branches/branches-query'
import type { Branch } from '@/data/branches/branches-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { useGrant } from '@/lib/grants'
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 projectRef = projectDetails?.parent_project_ref || ref
const branchesGrant = useGrant('GET /v1/projects/{ref}/branches', { projectRef })
const {
data: branches,
isPending: isPendingBranches,
isError: isBranchesError,
isSuccess: isBranchesSuccess,
} = useQuery(
branchesQueryOptions(
{ projectRef, grant: branchesGrant.grant },
{ enabled: Boolean(projectDetails) }
)
)
const isDenied = branchesGrant.status === 'denied' && Boolean(projectDetails)
const isLoading =
branchesGrant.status === 'loading' ||
(branchesGrant.status === 'granted' && isPendingBranches) ||
(branchesGrant.status === 'denied' && !projectDetails)
const isError = isBranchesError || branchesGrant.status === 'error'
const isSuccess = isBranchesSuccess || isDenied
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={setOpen}
triggerButton={<AppLayoutDropdownTriggerButton aria-label="Show project branches" />}
/>
)
}