1+ import { constructEditorSlug , ROOT_SLUG_ALIAS } from "@fern-docs/components/navigation" ;
12import { ArrowRight , Loader2 } from "lucide-react" ;
2- import { useState } from "react" ;
3-
3+ import Link from "next/link" ;
4+ import { useMemo , useState } from "react" ;
5+ import { useOrgName } from "@/app/[orgName]/context/OrgNameContext" ;
46import type { GithubSourceRepo } from "@/app/services/github/types" ;
5- import type { DocsUrl } from "@/utils/types" ;
6-
7+ import type { DocsUrl , EncodedDocsUrl } from "@/utils/types" ;
78import { Button } from "../ui/button" ;
89import { BranchPRInfo } from "./BranchPRInfo" ;
910import { DeleteBranchButton } from "./DeleteBranchButton" ;
@@ -13,17 +14,27 @@ export function BranchListItem({
1314 sourceRepo,
1415 docsUrl,
1516 showDivider = false ,
16- handleBranchDelete,
17- handleBranchClick
17+ handleBranchDelete
1818} : {
1919 branch : string ;
2020 docsUrl : DocsUrl ;
2121 sourceRepo ?: GithubSourceRepo ;
2222 showDivider ?: boolean ;
2323 handleBranchDelete : ( branch : string ) => void ;
24- handleBranchClick : ( branch : string ) => void ;
2524} ) {
2625 const [ loading , setLoading ] = useState ( false ) ;
26+ const orgName = useOrgName ( ) ;
27+
28+ const editorLink = useMemo (
29+ ( ) =>
30+ constructEditorSlug ( {
31+ orgName,
32+ docsUrl : encodeURIComponent ( docsUrl ) as EncodedDocsUrl ,
33+ branchName : branch ,
34+ slug : ROOT_SLUG_ALIAS
35+ } ) ,
36+ [ orgName , docsUrl , branch ]
37+ ) ;
2738 return (
2839 < >
2940 < div className = "flex items-center justify-between gap-x-4 gap-y-1" >
@@ -37,19 +48,21 @@ export function BranchListItem({
3748 variant = "outline"
3849 onClick = { ( ) => {
3950 setLoading ( true ) ;
40- handleBranchClick ( branch ) ;
4151 } }
4252 disabled = { loading }
4353 className = "text-green-1100 hover:text-green-1100 min-w-[84px]"
54+ asChild = { ! loading }
4455 >
45- { loading ? (
46- < Loader2 className = "size-4 animate-spin" />
47- ) : (
48- < >
49- Open
50- < ArrowRight className = "size-4" />
51- </ >
52- ) }
56+ < Link href = { editorLink } >
57+ { loading ? (
58+ < Loader2 className = "size-4 animate-spin" />
59+ ) : (
60+ < >
61+ Open
62+ < ArrowRight className = "size-4" />
63+ </ >
64+ ) }
65+ </ Link >
5366 </ Button >
5467 </ div >
5568 </ div >
0 commit comments