22
33import { Badge } from "@/components/ui/badge"
44import { Button } from "@/components/ui/button"
5- import {
6- DropdownMenu ,
7- DropdownMenuContent ,
8- DropdownMenuItem ,
9- DropdownMenuLabel ,
10- DropdownMenuSeparator ,
11- DropdownMenuTrigger ,
12- } from "@/components/ui/dropdown-menu"
135import { InputGroup , InputGroupAddon , InputGroupInput } from "@/components/ui/input-group"
146import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from "@/components/ui/select"
157import { Table , TableBody , TableCell , TableHead , TableHeader , TableRow } from "@/components/ui/table"
168import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants"
17- import { cn , getCodeHostCommitUrl , getCodeHostIcon , getCodeHostInfoForRepo , getRepoImageSrc } from "@/lib/utils"
9+ import { cn , getCodeHostCommitUrl , getCodeHostIcon , getRepoImageSrc , isServiceError } from "@/lib/utils"
1810import {
1911 type ColumnDef ,
2012 type VisibilityState ,
@@ -23,7 +15,7 @@ import {
2315 useReactTable ,
2416} from "@tanstack/react-table"
2517import { cva } from "class-variance-authority"
26- import { ArrowDown , ArrowUp , ArrowUpDown , ExternalLink , Loader2 , MoreHorizontal , RefreshCwIcon } from "lucide-react"
18+ import { ArrowDown , ArrowUp , ArrowUpDown , Loader2 , RefreshCwIcon } from "lucide-react"
2719import Image from "next/image"
2820import Link from "next/link"
2921import { useEffect , useRef , useState } from "react"
@@ -35,6 +27,8 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
3527import { NotificationDot } from "../../components/notificationDot"
3628import { CodeHostType } from "@sourcebot/db"
3729import { useHotkeys } from "react-hotkeys-hook"
30+ import { indexRepo } from "@/features/workerApi/actions"
31+ import { RepoActionsDropdown } from "./repoActionsDropdown"
3832
3933// @see : https://v0.app/chat/repo-indexing-status-uhjdDim8OUS
4034
@@ -84,6 +78,7 @@ interface ColumnsContext {
8478 onSortChange : ( sortBy : string ) => void ;
8579 currentSortBy ?: string ;
8680 currentSortOrder : string ;
81+ onTriggerSync : ( repoId : number ) => void ;
8782}
8883
8984export const getColumns = ( context : ColumnsContext ) : ColumnDef < Repo > [ ] => [
@@ -253,40 +248,7 @@ export const getColumns = (context: ColumnsContext): ColumnDef<Repo>[] => [
253248 enableHiding : false ,
254249 cell : ( { row } ) => {
255250 const repo = row . original
256- const codeHostInfo = getCodeHostInfoForRepo ( {
257- codeHostType : repo . codeHostType ,
258- name : repo . name ,
259- displayName : repo . displayName ?? undefined ,
260- webUrl : repo . webUrl ?? undefined ,
261- } ) ;
262-
263- return (
264- < DropdownMenu >
265- < DropdownMenuTrigger asChild >
266- < Button variant = "ghost" className = "h-8 w-8 p-0" >
267- < span className = "sr-only" > Open menu</ span >
268- < MoreHorizontal className = "h-4 w-4" />
269- </ Button >
270- </ DropdownMenuTrigger >
271- < DropdownMenuContent align = "end" >
272- < DropdownMenuLabel > Actions</ DropdownMenuLabel >
273- < DropdownMenuItem asChild >
274- < Link href = { `/${ SINGLE_TENANT_ORG_DOMAIN } /repos/${ repo . id } ` } > View details</ Link >
275- </ DropdownMenuItem >
276- { repo . webUrl && (
277- < >
278- < DropdownMenuSeparator />
279- < DropdownMenuItem asChild >
280- < a href = { repo . webUrl } target = "_blank" rel = "noopener noreferrer" className = "flex items-center" >
281- Open in { codeHostInfo . codeHostName }
282- < ExternalLink className = "ml-2 h-3 w-3" />
283- </ a >
284- </ DropdownMenuItem >
285- </ >
286- ) }
287- </ DropdownMenuContent >
288- </ DropdownMenu >
289- )
251+ return < RepoActionsDropdown repo = { repo } />
290252 } ,
291253 } ,
292254]
@@ -386,12 +348,29 @@ export const ReposTable = ({
386348 router . replace ( `${ pathname } ?${ params . toString ( ) } ` ) ;
387349 } ;
388350
351+ const handleTriggerSync = async ( repoId : number ) => {
352+ const response = await indexRepo ( repoId ) ;
353+
354+ if ( ! isServiceError ( response ) ) {
355+ const { jobId } = response ;
356+ toast ( {
357+ description : `✅ Repository sync triggered successfully. Job ID: ${ jobId } ` ,
358+ } ) ;
359+ router . refresh ( ) ;
360+ } else {
361+ toast ( {
362+ description : `❌ Failed to sync repository. ${ response . message } ` ,
363+ } ) ;
364+ }
365+ } ;
366+
389367 const totalPages = Math . ceil ( totalCount / pageSize ) ;
390368
391369 const columns = getColumns ( {
392370 onSortChange : handleSortChange ,
393371 currentSortBy : initialSortBy ,
394372 currentSortOrder : initialSortOrder ,
373+ onTriggerSync : handleTriggerSync
395374 } ) ;
396375
397376 const table = useReactTable ( {
0 commit comments