mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Context
Just some housekeeping here while going through the repo, realised that
there's dead code in `ProjectBranchSwitcher`
## Changes involved:
- `ProjectBranchSelector` is only rendered by `MobileNavigationBar`,
which `DefaultLayout` only mounts when `useBreakpoint('md')` is true.
The selector's own `isMobile` check used the same breakpoint, so its
desktop `Popover` branch could never run.
- The name `ProjectBranchSelector` is also misleading since the sheet
switches more than just the project's branch + it's mobile-only, so
opting to rename it to `MobileProjectSwitcher` instead
- Also fix org rows in the sheet being tighter than project rows.
`compactPadding` was inverted, so the embedded list got `p-0.5` on the
item and lost the default `px-2 py-1.5`
- Align buttons in `ProjectBranchSelector` across all tabs + use outline
variant for secondary action
| Previous | Updated |
|---|---|
| <img width="352" height="174" alt="image"
src="https://github.com/user-attachments/assets/24cb2985-b568-4bc1-8f53-ab3914ef0804"
/> | <img width="351" height="161" alt="image"
src="https://github.com/user-attachments/assets/e6e9b0e9-c075-4235-93ca-80c5d070c287"
/> |
| <img width="336" height="248" alt="image"
src="https://github.com/user-attachments/assets/4071b73f-f741-4598-ba01-8dc7bb6ba57a"
/> | <img width="335" height="313" alt="image"
src="https://github.com/user-attachments/assets/2bea398d-ebe9-4641-9bfe-c4a7b6b10c51"
/> |
If you meant a different table, tell me what the two columns should be.
For example, file and change, or before and after behaviour.
134 lines
4.6 KiB
TypeScript
134 lines
4.6 KiB
TypeScript
import { BoxesIcon, BoxIcon, GitBranchIcon } from 'lucide-react'
|
|
import { cn, SheetHeader, SheetTitle, Tabs, TabsContent, TabsList } from 'ui'
|
|
import MobileSheetNav from 'ui-patterns/MobileSheetNav/MobileSheetNav'
|
|
|
|
import { MobileProjectSwitcherSheetTabTrigger } from './MobileProjectSwitcherSheetTabTrigger'
|
|
import { BranchDropdown } from '@/components/layouts/AppLayout/BranchDropdown'
|
|
import { OrganizationDropdown } from '@/components/layouts/AppLayout/OrganizationDropdown'
|
|
import { ProjectDropdown } from '@/components/layouts/AppLayout/ProjectDropdown'
|
|
import type { Branch } from '@/data/branches/branches-query'
|
|
import type { ProjectDetail } from '@/data/projects/project-detail-query'
|
|
import type { Organization } from '@/types'
|
|
|
|
const EMBEDDED_CLASSNAME =
|
|
'bg-transparent border-0 shadow-none min-h-0 flex-1 flex flex-col overflow-hidden rounded-none'
|
|
|
|
export interface MobileProjectSwitcherSheetProps {
|
|
open: boolean
|
|
onOpenChange: (open: boolean) => void
|
|
selectedRef: string | undefined
|
|
onClose: () => void
|
|
selectedOrganization?: Organization | null
|
|
displayProject?: ProjectDetail | null
|
|
selectedBranch?: Branch | null
|
|
selectedOrganizationName?: string | null
|
|
selectedProjectName?: string | null
|
|
selectedBranchName?: string | null
|
|
isMainBranch?: boolean
|
|
}
|
|
|
|
export function MobileProjectSwitcherSheet({
|
|
open,
|
|
onOpenChange,
|
|
selectedRef,
|
|
onClose,
|
|
selectedOrganization,
|
|
displayProject,
|
|
selectedBranch,
|
|
selectedOrganizationName,
|
|
selectedProjectName,
|
|
selectedBranchName,
|
|
isMainBranch,
|
|
}: MobileProjectSwitcherSheetProps) {
|
|
const orgLabel = selectedOrganizationName ?? selectedOrganization?.name
|
|
const projectLabel = selectedProjectName ?? displayProject?.name
|
|
const branchLabel = selectedBranchName ?? selectedBranch?.name ?? 'main'
|
|
|
|
const tabs = [
|
|
orgLabel && {
|
|
value: 'organization' as const,
|
|
label: orgLabel,
|
|
icon: BoxesIcon,
|
|
},
|
|
projectLabel && {
|
|
value: 'project' as const,
|
|
label: projectLabel,
|
|
icon: BoxIcon,
|
|
},
|
|
branchLabel && {
|
|
value: 'branch' as const,
|
|
label: branchLabel,
|
|
icon: GitBranchIcon,
|
|
},
|
|
].filter(Boolean) as Array<{
|
|
value: 'organization' | 'project' | 'branch'
|
|
label: string
|
|
icon: typeof BoxesIcon
|
|
}>
|
|
|
|
const defaultTab =
|
|
(selectedRef && tabs.some((t) => t.value === 'project') ? 'project' : tabs[0]?.value) ??
|
|
'organization'
|
|
|
|
if (tabs.length === 0) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<MobileSheetNav
|
|
open={open}
|
|
onOpenChange={onOpenChange}
|
|
className="flex flex-col overflow-hidden h-[85dvh] md:max-h-[500px]"
|
|
>
|
|
<Tabs defaultValue={defaultTab} className="flex flex-col flex-1 min-h-0 overflow-hidden p-0">
|
|
<SheetHeader className="border-0 border-default p-0 shrink-0">
|
|
<SheetTitle className="sr-only">Switch organization, project or branch</SheetTitle>
|
|
<TabsList
|
|
className={cn(
|
|
'w-full grid gap-0 shrink-0',
|
|
tabs.length === 1 && 'grid-cols-1',
|
|
tabs.length === 2 && 'grid-cols-2',
|
|
tabs.length === 3 && 'grid-cols-3'
|
|
)}
|
|
>
|
|
{tabs.map(({ value, label, icon }, index) => (
|
|
<MobileProjectSwitcherSheetTabTrigger
|
|
key={value}
|
|
value={value}
|
|
label={label}
|
|
icon={icon}
|
|
isMainBranch={value === 'branch' ? isMainBranch : undefined}
|
|
isLast={index === tabs.length - 1}
|
|
/>
|
|
))}
|
|
</TabsList>
|
|
</SheetHeader>
|
|
{tabs.some((t) => t.value === 'organization') && (
|
|
<TabsContent
|
|
value="organization"
|
|
className="flex-1 min-h-0 overflow-hidden flex flex-col mt-0 p-0 data-[state=inactive]:hidden"
|
|
>
|
|
<OrganizationDropdown embedded className={EMBEDDED_CLASSNAME} onClose={onClose} />
|
|
</TabsContent>
|
|
)}
|
|
{tabs.some((t) => t.value === 'project') && (
|
|
<TabsContent
|
|
value="project"
|
|
className="flex-1 min-h-0 overflow-hidden flex flex-col mt-0 py-0 data-[state=inactive]:hidden"
|
|
>
|
|
<ProjectDropdown embedded className={EMBEDDED_CLASSNAME} onClose={onClose} />
|
|
</TabsContent>
|
|
)}
|
|
{tabs.some((t) => t.value === 'branch') && (
|
|
<TabsContent
|
|
value="branch"
|
|
className="flex-1 min-h-0 overflow-hidden flex flex-col mt-0 p-0 data-[state=inactive]:hidden"
|
|
>
|
|
<BranchDropdown embedded className={EMBEDDED_CLASSNAME} onClose={onClose} />
|
|
</TabsContent>
|
|
)}
|
|
</Tabs>
|
|
</MobileSheetNav>
|
|
)
|
|
}
|