Skip to content

Commit 82bb29a

Browse files
authored
fix: branch dropdown sort & default branch shield (supabase#32650)
sort and add shield
1 parent 9eb3c22 commit 82bb29a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

apps/studio/components/layouts/AppLayout/BranchDropdown.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AlertCircle, Check, ChevronsUpDown, ListTree, MessageCircle } from 'lucide-react'
1+
import { AlertCircle, Check, ChevronsUpDown, ListTree, MessageCircle, Shield } from 'lucide-react'
22
import Link from 'next/link'
33
import { useRouter } from 'next/router'
44
import { useState } from 'react'
@@ -51,10 +51,11 @@ const BranchLink = ({
5151
setOpen(false)
5252
}}
5353
>
54-
<p className="truncate w-60" title={branch.name}>
54+
<p className="truncate w-60 flex items-center gap-1" title={branch.name}>
55+
{branch.is_default && <Shield size={14} className="text-amber-900" />}
5556
{branch.name}
5657
</p>
57-
{isSelected && <Check />}
58+
{isSelected && <Check size={14} strokeWidth={1.5} />}
5859
</CommandItem_Shadcn_>
5960
</Link>
6061
)
@@ -77,6 +78,15 @@ const BranchDropdown = ({ isNewNav = false }: BranchDropdownProps) => {
7778
const [open, setOpen] = useState(false)
7879
const selectedBranch = branches?.find((branch) => branch.project_ref === ref)
7980

81+
const mainBranch = branches?.find((branch) => branch.is_default)
82+
const restOfBranches = branches
83+
?.filter((branch) => !branch.is_default)
84+
.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())
85+
86+
const sortedBranches = mainBranch
87+
? [mainBranch].concat(restOfBranches ?? [])
88+
: restOfBranches ?? []
89+
8090
const BRANCHING_GITHUB_DISCUSSION_LINK = 'https://github.com/orgs/supabase/discussions/18937'
8191

8292
return (
@@ -112,7 +122,7 @@ const BranchDropdown = ({ isNewNav = false }: BranchDropdownProps) => {
112122
<CommandEmpty_Shadcn_>No branches found</CommandEmpty_Shadcn_>
113123
<CommandGroup_Shadcn_>
114124
<ScrollArea className="max-h-[210px] overflow-y-auto">
115-
{branches?.map((branch) => (
125+
{sortedBranches?.map((branch) => (
116126
<BranchLink
117127
key={branch.id}
118128
branch={branch}

0 commit comments

Comments
 (0)