Skip to content

Commit 2ccdebc

Browse files
wip
1 parent 1631ed3 commit 2ccdebc

File tree

5 files changed

+188
-59
lines changed

5 files changed

+188
-59
lines changed

packages/backend/src/repoIndexManager.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ export class RepoIndexManager {
258258
},
259259
data: {
260260
status: RepoIndexingJobStatus.IN_PROGRESS,
261+
repo: {
262+
update: {
263+
latestIndexingJobStatus: RepoIndexingJobStatus.IN_PROGRESS,
264+
}
265+
}
261266
},
262267
select: {
263268
type: true,
@@ -462,6 +467,11 @@ export class RepoIndexManager {
462467
data: {
463468
status: RepoIndexingJobStatus.COMPLETED,
464469
completedAt: new Date(),
470+
repo: {
471+
update: {
472+
latestIndexingJobStatus: RepoIndexingJobStatus.COMPLETED,
473+
}
474+
}
465475
},
466476
include: {
467477
repo: true,
@@ -522,6 +532,11 @@ export class RepoIndexManager {
522532
status: RepoIndexingJobStatus.FAILED,
523533
completedAt: new Date(),
524534
errorMessage: job.failedReason,
535+
repo: {
536+
update: {
537+
latestIndexingJobStatus: RepoIndexingJobStatus.FAILED,
538+
}
539+
}
525540
},
526541
select: { repo: true }
527542
});
@@ -550,6 +565,11 @@ export class RepoIndexManager {
550565
status: RepoIndexingJobStatus.FAILED,
551566
completedAt: new Date(),
552567
errorMessage: 'Job stalled',
568+
repo: {
569+
update: {
570+
latestIndexingJobStatus: RepoIndexingJobStatus.FAILED,
571+
}
572+
}
553573
},
554574
select: { repo: true, type: true }
555575
});
@@ -572,6 +592,11 @@ export class RepoIndexManager {
572592
status: RepoIndexingJobStatus.FAILED,
573593
completedAt: new Date(),
574594
errorMessage: 'Job timed out',
595+
repo: {
596+
update: {
597+
latestIndexingJobStatus: RepoIndexingJobStatus.FAILED,
598+
}
599+
}
575600
},
576601
select: { repo: true }
577602
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Repo" ADD COLUMN "latestIndexingJobStatus" "RepoIndexingJobStatus";

packages/db/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ model Repo {
6666
jobs RepoIndexingJob[]
6767
indexedAt DateTime? /// When the repo was last indexed successfully.
6868
indexedCommitHash String? /// The commit hash of the last indexed commit (on HEAD).
69+
latestIndexingJobStatus RepoIndexingJobStatus? /// The status of the latest indexing job.
6970
7071
external_id String /// The id of the repo in the external service
7172
external_codeHostType CodeHostType /// The type of the external service (e.g., github, gitlab, etc.)

packages/web/src/app/[domain]/repos/components/reposTable.tsx

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants"
1717
import { cn, getCodeHostCommitUrl, getCodeHostIcon, getCodeHostInfoForRepo, getRepoImageSrc } from "@/lib/utils"
1818
import {
1919
type ColumnDef,
20-
type SortingState,
2120
type VisibilityState,
2221
flexRender,
2322
getCoreRowModel,
24-
getSortedRowModel,
2523
useReactTable,
2624
} from "@tanstack/react-table"
2725
import { cva } from "class-variance-authority"
28-
import { ArrowUpDown, ExternalLink, Loader2, MoreHorizontal, RefreshCwIcon } from "lucide-react"
26+
import { ArrowDown, ArrowUp, ArrowUpDown, ExternalLink, Loader2, MoreHorizontal, RefreshCwIcon } from "lucide-react"
2927
import Image from "next/image"
3028
import Link from "next/link"
3129
import { useEffect, useRef, useState } from "react"
@@ -82,15 +80,29 @@ const getStatusBadge = (status: Repo["latestJobStatus"]) => {
8280
return <Badge className={statusBadgeVariants({ status })}>{labels[status]}</Badge>
8381
}
8482

85-
export const columns: ColumnDef<Repo>[] = [
83+
interface ColumnsContext {
84+
onSortChange: (sortBy: string) => void;
85+
currentSortBy?: string;
86+
currentSortOrder: string;
87+
}
88+
89+
export const getColumns = (context: ColumnsContext): ColumnDef<Repo>[] => [
8690
{
8791
accessorKey: "displayName",
8892
size: 400,
89-
header: ({ column }) => {
93+
header: () => {
94+
const isActive = context.currentSortBy === 'displayName';
95+
const Icon = isActive
96+
? (context.currentSortOrder === 'asc' ? ArrowUp : ArrowDown)
97+
: ArrowUpDown;
98+
9099
return (
91-
<Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}>
100+
<Button
101+
variant="ghost"
102+
onClick={() => context.onSortChange('displayName')}
103+
>
92104
Repository
93-
<ArrowUpDown className="ml-2 h-4 w-4" />
105+
<Icon className="ml-2 h-4 w-4" />
94106
</Button>
95107
)
96108
},
@@ -157,14 +169,19 @@ export const columns: ColumnDef<Repo>[] = [
157169
{
158170
accessorKey: "indexedAt",
159171
size: 200,
160-
header: ({ column }) => {
172+
header: () => {
173+
const isActive = context.currentSortBy === 'indexedAt';
174+
const Icon = isActive
175+
? (context.currentSortOrder === 'asc' ? ArrowUp : ArrowDown)
176+
: ArrowUpDown;
177+
161178
return (
162179
<Button
163180
variant="ghost"
164-
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
181+
onClick={() => context.onSortChange('indexedAt')}
165182
>
166183
Last synced
167-
<ArrowUpDown className="ml-2 h-4 w-4" />
184+
<Icon className="ml-2 h-4 w-4" />
168185
</Button>
169186
)
170187
},
@@ -276,6 +293,15 @@ interface ReposTableProps {
276293
totalCount: number;
277294
initialSearch: string;
278295
initialStatus: string;
296+
initialSortBy?: string;
297+
initialSortOrder: string;
298+
stats: {
299+
numCompleted: number
300+
numFailed: number
301+
numPending: number
302+
numInProgress: number
303+
numNoJobs: number
304+
}
279305
}
280306

281307
export const ReposTable = ({
@@ -285,8 +311,10 @@ export const ReposTable = ({
285311
totalCount,
286312
initialSearch,
287313
initialStatus,
314+
initialSortBy,
315+
initialSortOrder,
316+
stats,
288317
}: ReposTableProps) => {
289-
const [sorting, setSorting] = useState<SortingState>([])
290318
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
291319
const [rowSelection, setRowSelection] = useState({})
292320
const [searchValue, setSearchValue] = useState(initialSearch)
@@ -336,20 +364,40 @@ export const ReposTable = ({
336364
router.replace(`${pathname}?${params.toString()}`);
337365
};
338366

367+
const handleSortChange = (sortBy: string) => {
368+
const params = new URLSearchParams(searchParams.toString());
369+
370+
// Toggle sort order if clicking the same column
371+
if (initialSortBy === sortBy) {
372+
const newOrder = initialSortOrder === 'asc' ? 'desc' : 'asc';
373+
params.set('sortOrder', newOrder);
374+
} else {
375+
// Default to ascending when changing columns
376+
params.set('sortBy', sortBy);
377+
params.set('sortOrder', 'asc');
378+
}
379+
380+
params.set('page', '1'); // Reset to page 1 on sort change
381+
router.replace(`${pathname}?${params.toString()}`);
382+
};
383+
339384
const totalPages = Math.ceil(totalCount / pageSize);
340385

386+
const columns = getColumns({
387+
onSortChange: handleSortChange,
388+
currentSortBy: initialSortBy,
389+
currentSortOrder: initialSortOrder,
390+
});
391+
341392
const table = useReactTable({
342393
data,
343394
columns,
344-
onSortingChange: setSorting,
345395
getCoreRowModel: getCoreRowModel(),
346-
getSortedRowModel: getSortedRowModel(),
347396
onColumnVisibilityChange: setColumnVisibility,
348397
onRowSelectionChange: setRowSelection,
349398
columnResizeMode: 'onChange',
350399
enableColumnResizing: false,
351400
state: {
352-
sorting,
353401
columnVisibility,
354402
rowSelection,
355403
},
@@ -381,11 +429,11 @@ export const ReposTable = ({
381429
</SelectTrigger>
382430
<SelectContent>
383431
<SelectItem value="all">Filter by status</SelectItem>
384-
<SelectItem value="COMPLETED">Completed</SelectItem>
385-
<SelectItem value="IN_PROGRESS">In progress</SelectItem>
386-
<SelectItem value="PENDING">Pending</SelectItem>
387-
<SelectItem value="FAILED">Failed</SelectItem>
388-
<SelectItem value="null">No status</SelectItem>
432+
<SelectItem value="COMPLETED">Completed ({stats.numCompleted})</SelectItem>
433+
<SelectItem value="IN_PROGRESS">In progress ({stats.numInProgress})</SelectItem>
434+
<SelectItem value="PENDING">Pending ({stats.numPending})</SelectItem>
435+
<SelectItem value="FAILED">Failed ({stats.numFailed})</SelectItem>
436+
<SelectItem value="none">No status ({stats.numNoJobs})</SelectItem>
389437
</SelectContent>
390438
</Select>
391439
<Button

0 commit comments

Comments
 (0)