mirror of
https://github.com/supabase/supabase.git
synced 2026-06-15 08:05:21 +08:00
## Problem We have multiple Popover components ## Solution - [x] migrate Popover usages to Shadcn components - Migrated JSON and text editor in the `TableEditor` (inline row edition) - Migrated the template popover in the logs explorer templates page - [x] remove `_Shadcn_` suffix from Popover components (renaming + prettier) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Unified popover implementation across the app and design system; dropdowns, calendars, menus and tooltips now use a consistent popover API with no visual or interaction changes. * **Chores** * Minor prop typing update for the logs date-picker to align with the consolidated popover content type. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45980) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
118 lines
3.8 KiB
TypeScript
118 lines
3.8 KiB
TypeScript
import { useBreakpoint, useParams } from 'common'
|
|
import { useRouter } from 'next/router'
|
|
import { useState } from 'react'
|
|
import {
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
} from 'ui'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { getProjectBranchSelectorState } from './ProjectBranchSelector.utils'
|
|
import { ProjectBranchSelectorPopover } from './ProjectBranchSelectorPopover'
|
|
import { ProjectBranchSelectorSheet } from './ProjectBranchSelectorSheet'
|
|
import { ProjectBranchSelectorTrigger } from './ProjectBranchSelectorTrigger'
|
|
import { useBranchesQuery } from '@/data/branches/branches-query'
|
|
import { useProjectDetailQuery } from '@/data/projects/project-detail-query'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
|
|
export function ProjectBranchSelector() {
|
|
const router = useRouter()
|
|
const { ref } = useParams()
|
|
const { data: selectedOrganization } = useSelectedOrganizationQuery()
|
|
const { data: project, isPending: isLoadingProject } = useSelectedProjectQuery()
|
|
|
|
const isBranch = project?.parentRef !== project?.ref
|
|
const isProductionBranch = !isBranch
|
|
const { data: parentProject } = useProjectDetailQuery(
|
|
{ ref: project?.parent_project_ref },
|
|
{ enabled: isBranch }
|
|
)
|
|
const displayProject = parentProject ?? project
|
|
|
|
const [open, setOpen] = useState(false)
|
|
|
|
const isBranchingEnabled = project?.is_branch_enabled === true
|
|
const { data: branches } = useBranchesQuery(
|
|
{ projectRef: project?.parent_project_ref || ref },
|
|
{ enabled: open && Boolean(project) }
|
|
)
|
|
|
|
const selectedBranch = branches?.find((b) => b.project_ref === ref)
|
|
const { isMainBranch, branchDisplayName, selectedOrgInitial, organizationHref } =
|
|
getProjectBranchSelectorState({
|
|
selectedBranch,
|
|
isBranchingEnabled,
|
|
selectedOrganization: selectedOrganization ?? undefined,
|
|
})
|
|
|
|
const goToOrganization = () => {
|
|
setOpen(false)
|
|
router.push(organizationHref)
|
|
}
|
|
|
|
const isMobile = useBreakpoint('md')
|
|
|
|
if (isLoadingProject || !displayProject)
|
|
return <ShimmeringLoader className="w-[120px] ml-1 md:py-3" />
|
|
|
|
if (!IS_PLATFORM) {
|
|
return (
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton className="grid flex-1 text-left text-sm leading-tight text-foreground">
|
|
<span className="truncate">{displayProject.name}</span>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
)
|
|
}
|
|
|
|
const triggerProps = {
|
|
displayProjectName: displayProject.name,
|
|
selectedOrgInitial,
|
|
isBranch,
|
|
isProductionBranch,
|
|
branchDisplayName,
|
|
onGoToOrganization: goToOrganization,
|
|
}
|
|
|
|
if (isMobile) {
|
|
return (
|
|
<>
|
|
<ProjectBranchSelectorTrigger {...triggerProps} onClick={() => setOpen(true)} />
|
|
<ProjectBranchSelectorSheet
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
selectedRef={ref}
|
|
onClose={() => setOpen(false)}
|
|
selectedOrganization={selectedOrganization ?? null}
|
|
displayProject={displayProject ?? null}
|
|
selectedBranch={selectedBranch ?? null}
|
|
isMainBranch={isMainBranch}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<Popover open={open} onOpenChange={setOpen} modal={false}>
|
|
<PopoverTrigger asChild>
|
|
<ProjectBranchSelectorTrigger {...triggerProps} />
|
|
</PopoverTrigger>
|
|
<PopoverContent className="p-0 w-[780px]" side="bottom" align="start">
|
|
<ProjectBranchSelectorPopover onClose={() => setOpen(false)} />
|
|
</PopoverContent>
|
|
</Popover>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
)
|
|
}
|