Skip to content

Commit c56433d

Browse files
repository table
1 parent cfb3593 commit c56433d

10 files changed

Lines changed: 144 additions & 174 deletions

File tree

packages/web/src/app/[domain]/components/navigationMenu/navigationItems.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { NavigationMenuItem, NavigationMenuLink, NavigationMenuList, navigationMenuTriggerStyle } from "@/components/ui/navigation-menu";
44
import { Badge } from "@/components/ui/badge";
5-
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
65
import { cn, getShortenedNumberDisplayString } from "@/lib/utils";
76
import { SearchIcon, MessageCircleIcon, BookMarkedIcon, SettingsIcon, CircleIcon } from "lucide-react";
87
import { usePathname } from "next/navigation";

packages/web/src/app/[domain]/components/navigationMenu/progressIndicator.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { useToast } from "@/components/hooks/use-toast";
34
import { Badge } from "@/components/ui/badge";
45
import { Button } from "@/components/ui/button";
56
import { Separator } from "@/components/ui/separator";
@@ -25,6 +26,7 @@ export const ProgressIndicator = ({
2526
}: ProgressIndicatorProps) => {
2627
const domain = useDomain();
2728
const router = useRouter();
29+
const { toast } = useToast();
2830

2931
if (numRepos === 0) {
3032
return null;
@@ -51,6 +53,9 @@ export const ProgressIndicator = ({
5153
className="h-6 w-6 text-muted-foreground"
5254
onClick={() => {
5355
router.refresh();
56+
toast({
57+
description: "Page refreshed",
58+
});
5459
}}
5560
>
5661
<RefreshCwIcon className="w-3 h-3" />
@@ -105,14 +110,13 @@ const RepoItem = ({ repo }: { repo: RepositoryQuery }) => {
105110

106111

107112
return (
108-
<Link
109-
href={'/'}
113+
<div
110114
className={clsx("flex flex-row items-center gap-2 border rounded-md p-2 text-clip")}
111115
>
112116
{repoIcon}
113117
<span className="text-sm truncate">
114118
{displayName}
115119
</span>
116-
</Link>
120+
</div>
117121
)
118122
}

packages/web/src/app/[domain]/repos/columns.tsx

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,51 @@
22

33
import { Button } from "@/components/ui/button"
44
import type { ColumnDef } from "@tanstack/react-table"
5-
import { ArrowUpDown, Clock, Loader2, CheckCircle2, XCircle, Trash2, Check, ListFilter } from "lucide-react"
5+
import { ArrowUpDown, Clock, Loader2, CheckCircle2, Check, ListFilter } from "lucide-react"
66
import Image from "next/image"
77
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
88
import { cn, getRepoImageSrc } from "@/lib/utils"
9-
import { RepoIndexingStatus } from "@sourcebot/db";
109
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
1110
import Link from "next/link"
1211
import { getBrowsePath } from "../browse/hooks/utils"
1312

13+
export type RepoStatus = 'syncing' | 'indexed' | 'not-indexed';
14+
1415
export type RepositoryColumnInfo = {
1516
repoId: number
1617
repoName: string;
1718
repoDisplayName: string
1819
imageUrl?: string
19-
repoIndexingStatus: RepoIndexingStatus
20+
status: RepoStatus
2021
lastIndexed: string
2122
}
2223

23-
const statusLabels = {
24-
[RepoIndexingStatus.NEW]: "Queued",
25-
[RepoIndexingStatus.IN_INDEX_QUEUE]: "Queued",
26-
[RepoIndexingStatus.INDEXING]: "Indexing",
27-
[RepoIndexingStatus.INDEXED]: "Indexed",
28-
[RepoIndexingStatus.FAILED]: "Failed",
29-
[RepoIndexingStatus.IN_GC_QUEUE]: "Deleting",
30-
[RepoIndexingStatus.GARBAGE_COLLECTING]: "Deleting",
31-
[RepoIndexingStatus.GARBAGE_COLLECTION_FAILED]: "Deletion Failed"
24+
const statusLabels: Record<RepoStatus, string> = {
25+
'syncing': "Syncing",
26+
'indexed': "Indexed",
27+
'not-indexed': "Pending",
3228
};
3329

34-
const StatusIndicator = ({ status }: { status: RepoIndexingStatus }) => {
30+
const StatusIndicator = ({ status }: { status: RepoStatus }) => {
3531
let icon = null
3632
let description = ""
3733
let className = ""
3834

3935
switch (status) {
40-
case RepoIndexingStatus.NEW:
41-
case RepoIndexingStatus.IN_INDEX_QUEUE:
42-
icon = <Clock className="h-3.5 w-3.5" />
43-
description = "Repository is queued for indexing"
44-
className = "text-yellow-600 bg-yellow-50 dark:bg-yellow-900/20 dark:text-yellow-400"
45-
break
46-
case RepoIndexingStatus.INDEXING:
36+
case 'syncing':
4737
icon = <Loader2 className="h-3.5 w-3.5 animate-spin" />
48-
description = "Repository is being indexed"
38+
description = "Repository is currently syncing"
4939
className = "text-blue-600 bg-blue-50 dark:bg-blue-900/20 dark:text-blue-400"
5040
break
51-
case RepoIndexingStatus.INDEXED:
41+
case 'indexed':
5242
icon = <CheckCircle2 className="h-3.5 w-3.5" />
53-
description = "Repository has been successfully indexed"
43+
description = "Repository has been successfully indexed and is up to date"
5444
className = "text-green-600 bg-green-50 dark:bg-green-900/20 dark:text-green-400"
5545
break
56-
case RepoIndexingStatus.FAILED:
57-
icon = <XCircle className="h-3.5 w-3.5" />
58-
description = "Repository indexing failed"
59-
className = "text-red-600 bg-red-50 dark:bg-red-900/20 dark:text-red-400"
60-
break
61-
case RepoIndexingStatus.IN_GC_QUEUE:
62-
case RepoIndexingStatus.GARBAGE_COLLECTING:
63-
icon = <Trash2 className="h-3.5 w-3.5" />
64-
description = "Repository is being deleted"
65-
className = "text-gray-600 bg-gray-50 dark:bg-gray-900/20 dark:text-gray-400"
66-
break
67-
case RepoIndexingStatus.GARBAGE_COLLECTION_FAILED:
68-
icon = <XCircle className="h-3.5 w-3.5" />
69-
description = "Repository deletion failed"
70-
className = "text-red-600 bg-red-50 dark:bg-red-900/20 dark:text-red-400"
46+
case 'not-indexed':
47+
icon = <Clock className="h-3.5 w-3.5" />
48+
description = "Repository is pending initial sync"
49+
className = "text-yellow-600 bg-yellow-50 dark:bg-yellow-900/20 dark:text-yellow-400"
7150
break
7251
}
7352

@@ -130,9 +109,9 @@ export const columns = (domain: string): ColumnDef<RepositoryColumnInfo>[] => [
130109
},
131110
},
132111
{
133-
accessorKey: "repoIndexingStatus",
112+
accessorKey: "status",
134113
header: ({ column }) => {
135-
const uniqueLabels = Array.from(new Set(Object.values(statusLabels)));
114+
const uniqueLabels = Object.values(statusLabels);
136115
const currentFilter = column.getFilterValue() as string | undefined;
137116

138117
return (
@@ -173,12 +152,12 @@ export const columns = (domain: string): ColumnDef<RepositoryColumnInfo>[] => [
173152
)
174153
},
175154
cell: ({ row }) => {
176-
return <StatusIndicator status={row.original.repoIndexingStatus} />
155+
return <StatusIndicator status={row.original.status} />
177156
},
178157
filterFn: (row, id, value) => {
179158
if (value === undefined) return true;
180159

181-
const status = row.getValue(id) as RepoIndexingStatus;
160+
const status = row.getValue(id) as RepoStatus;
182161
return statusLabels[status] === value;
183162
},
184163
},
@@ -191,14 +170,14 @@ export const columns = (domain: string): ColumnDef<RepositoryColumnInfo>[] => [
191170
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
192171
className="px-0 font-medium hover:bg-transparent focus:bg-transparent active:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0"
193172
>
194-
Last Indexed
173+
Last Synced
195174
<ArrowUpDown className="ml-2 h-3.5 w-3.5" />
196175
</Button>
197176
</div>
198177
),
199178
cell: ({ row }) => {
200179
if (!row.original.lastIndexed) {
201-
return <div>-</div>;
180+
return <div className="text-muted-foreground">Never</div>;
202181
}
203182
const date = new Date(row.original.lastIndexed)
204183
return (

packages/web/src/app/[domain]/repos/page.tsx

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
import { RepositoryTable } from "./repositoryTable";
2-
import { getOrgFromDomain } from "@/data/org";
3-
import { PageNotFound } from "../components/pageNotFound";
4-
import { Header } from "../components/header";
1+
import { auth } from "@/auth";
52
import { env } from "@/env.mjs";
3+
import { getPrismaClient } from "@/prisma";
4+
import { RepoJob } from "@sourcebot/db";
5+
import { Header } from "../components/header";
6+
import { RepoStatus } from "./columns";
7+
import { RepositoryTable } from "./repositoryTable";
8+
9+
function getRepoStatus(repo: { indexedAt: Date | null, jobs: RepoJob[] }): RepoStatus {
10+
const latestJob = repo.jobs[0];
11+
12+
if (latestJob?.status === 'PENDING' || latestJob?.status === 'IN_PROGRESS') {
13+
return 'syncing';
14+
}
15+
16+
return repo.indexedAt ? 'indexed' : 'not-indexed';
17+
}
618

719
export default async function ReposPage(props: { params: Promise<{ domain: string }> }) {
820
const params = await props.params;
@@ -11,22 +23,33 @@ export default async function ReposPage(props: { params: Promise<{ domain: strin
1123
domain
1224
} = params;
1325

14-
const org = await getOrgFromDomain(domain);
15-
if (!org) {
16-
return <PageNotFound />
17-
}
26+
const session = await auth();
27+
const prisma = getPrismaClient(session?.user?.id);
28+
29+
const repos = await prisma.repo.findMany({
30+
include: {
31+
jobs: true,
32+
}
33+
});
1834

1935
return (
2036
<div>
2137
<Header>
2238
<h1 className="text-3xl">Repositories</h1>
2339
</Header>
24-
<div className="flex flex-col items-center">
25-
<div className="w-full">
26-
<RepositoryTable
27-
isAddReposButtonVisible={env.EXPERIMENT_SELF_SERVE_REPO_INDEXING_ENABLED === 'true'}
28-
/>
29-
</div>
40+
<div className="px-6 py-6">
41+
<RepositoryTable
42+
repos={repos.map((repo) => ({
43+
repoId: repo.id,
44+
repoName: repo.name,
45+
repoDisplayName: repo.displayName ?? repo.name,
46+
imageUrl: repo.imageUrl ?? undefined,
47+
indexedAt: repo.indexedAt ?? undefined,
48+
status: getRepoStatus(repo),
49+
}))}
50+
domain={domain}
51+
isAddReposButtonVisible={env.EXPERIMENT_SELF_SERVE_REPO_INDEXING_ENABLED === 'true'}
52+
/>
3053
</div>
3154
</div>
3255
)

0 commit comments

Comments
 (0)