mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-14 21:35:25 +00:00
revamp repo page (#220)
* wip repo table * new repo page * add indicator for when feedback is applied in repo page * add repo button * fetch connection data in one query * fix styling
This commit is contained in:
parent
7685d9cf66
commit
bdab90ba41
11 changed files with 437 additions and 173 deletions
|
|
@ -147,7 +147,7 @@ export const completeOnboarding = async (domain: string): Promise<{ success: boo
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getSecrets = (domain: string): Promise<{ createdAt: Date; key: string; }[] | ServiceError> =>
|
export const getSecrets = (domain: string): Promise<{ createdAt: Date; key: string; }[] | ServiceError> =>
|
||||||
withAuth((session) =>
|
withAuth((session) =>
|
||||||
withOrgMembership(session, domain, async ({ orgId }) => {
|
withOrgMembership(session, domain, async ({ orgId }) => {
|
||||||
|
|
@ -321,7 +321,11 @@ export const getRepos = async (domain: string, filter: { status?: RepoIndexingSt
|
||||||
} : {}),
|
} : {}),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
connections: true,
|
connections: {
|
||||||
|
include: {
|
||||||
|
connection: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -330,7 +334,10 @@ export const getRepos = async (domain: string, filter: { status?: RepoIndexingSt
|
||||||
repoId: repo.id,
|
repoId: repo.id,
|
||||||
repoName: repo.name,
|
repoName: repo.name,
|
||||||
repoCloneUrl: repo.cloneUrl,
|
repoCloneUrl: repo.cloneUrl,
|
||||||
linkedConnections: repo.connections.map((connection) => connection.connectionId),
|
linkedConnections: repo.connections.map(({ connection }) => ({
|
||||||
|
id: connection.id,
|
||||||
|
name: connection.name,
|
||||||
|
})),
|
||||||
imageUrl: repo.imageUrl ?? undefined,
|
imageUrl: repo.imageUrl ?? undefined,
|
||||||
indexedAt: repo.indexedAt ?? undefined,
|
indexedAt: repo.indexedAt ?? undefined,
|
||||||
repoIndexingStatus: repo.repoIndexingStatus,
|
repoIndexingStatus: repo.repoIndexingStatus,
|
||||||
|
|
@ -883,7 +890,7 @@ export const createOnboardingSubscription = async (domain: string) =>
|
||||||
save_default_payment_method: 'on_subscription',
|
save_default_payment_method: 'on_subscription',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!subscription) {
|
if (!subscription) {
|
||||||
return {
|
return {
|
||||||
statusCode: StatusCodes.INTERNAL_SERVER_ERROR,
|
statusCode: StatusCodes.INTERNAL_SERVER_ERROR,
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ export default function SharedConnectionCreationForm<T>({
|
||||||
return checkIfSecretExists(secretKey, domain);
|
return checkIfSecretExists(secretKey, domain);
|
||||||
}, { message: "Secret not found" }),
|
}, { message: "Secret not found" }),
|
||||||
});
|
});
|
||||||
}, [schema, domain]);
|
}, [schema, domain, additionalConfigValidation]);
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof formSchema>>({
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ export const ErrorNavIndicator = () => {
|
||||||
.slice(0, 10)
|
.slice(0, 10)
|
||||||
.map(repo => (
|
.map(repo => (
|
||||||
// Link to the first connection for the repo
|
// Link to the first connection for the repo
|
||||||
<Link key={repo.repoId} href={`/${domain}/connections/${repo.linkedConnections[0]}`} onClick={() => captureEvent('wa_error_nav_job_pressed', {})}>
|
<Link key={repo.repoId} href={`/${domain}/connections/${repo.linkedConnections[0].id}`} onClick={() => captureEvent('wa_error_nav_job_pressed', {})}>
|
||||||
<div className="flex items-center justify-between px-3 py-2
|
<div className="flex items-center justify-between px-3 py-2
|
||||||
bg-red-50 dark:bg-red-900/20 rounded-md
|
bg-red-50 dark:bg-red-900/20 rounded-md
|
||||||
border border-red-200/50 dark:border-red-800/50
|
border border-red-200/50 dark:border-red-800/50
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ export const ProgressNavIndicator = () => {
|
||||||
<div className="flex flex-col gap-2 pl-4">
|
<div className="flex flex-col gap-2 pl-4">
|
||||||
{inProgressRepos.slice(0, 10).map(item => (
|
{inProgressRepos.slice(0, 10).map(item => (
|
||||||
// Link to the first connection for the repo
|
// Link to the first connection for the repo
|
||||||
<Link key={item.repoId} href={`/${domain}/connections/${item.linkedConnections[0]}`} onClick={() => captureEvent('wa_progress_nav_job_pressed', {})}>
|
<Link key={item.repoId} href={`/${domain}/connections/${item.linkedConnections[0].id}`} onClick={() => captureEvent('wa_progress_nav_job_pressed', {})}>
|
||||||
<div className="flex items-center gap-2 px-3 py-2 bg-green-50 dark:bg-green-900/20
|
<div className="flex items-center gap-2 px-3 py-2 bg-green-50 dark:bg-green-900/20
|
||||||
rounded-md text-sm text-green-700 dark:text-green-300
|
rounded-md text-sm text-green-700 dark:text-green-300
|
||||||
border border-green-200/50 dark:border-green-800/50
|
border border-green-200/50 dark:border-green-800/50
|
||||||
|
|
|
||||||
|
|
@ -49,13 +49,19 @@ export const RepoListItem = ({
|
||||||
className="flex flex-row items-center p-4 border rounded-lg bg-background justify-between"
|
className="flex flex-row items-center p-4 border rounded-lg bg-background justify-between"
|
||||||
>
|
>
|
||||||
<div className="flex flex-row items-center gap-2">
|
<div className="flex flex-row items-center gap-2">
|
||||||
<Image
|
{imageUrl ? (
|
||||||
src={imageUrl ?? ""}
|
<Image
|
||||||
alt={name}
|
src={imageUrl}
|
||||||
width={40}
|
alt={name}
|
||||||
height={40}
|
width={32}
|
||||||
className="rounded-full"
|
height={32}
|
||||||
/>
|
className="object-cover"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="h-8 w-8 flex items-center justify-center bg-muted text-xs font-medium uppercase text-muted-foreground rounded-md">
|
||||||
|
{name.charAt(0)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<p className="font-medium">{name}</p>
|
<p className="font-medium">{name}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row items-center gap-4">
|
<div className="flex flex-row items-center gap-4">
|
||||||
|
|
|
||||||
57
packages/web/src/app/[domain]/repos/addRepoButton.tsx
Normal file
57
packages/web/src/app/[domain]/repos/addRepoButton.tsx
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { PlusCircle } from "lucide-react"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogDescription,
|
||||||
|
DialogClose,
|
||||||
|
DialogFooter,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { useState } from "react"
|
||||||
|
import { ConnectionList } from "../connections/components/connectionList"
|
||||||
|
import { useDomain } from "@/hooks/useDomain"
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
export function AddRepoButton() {
|
||||||
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
const domain = useDomain()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 ml-2 text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
<PlusCircle className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||||
|
<DialogContent className="sm:max-w-[800px] max-h-[90vh] flex flex-col p-0 gap-0 overflow-hidden">
|
||||||
|
<DialogHeader className="px-6 py-4 border-b">
|
||||||
|
<DialogTitle className="text-xl font-semibold">Add a New Repository</DialogTitle>
|
||||||
|
<DialogDescription className="text-sm text-muted-foreground mt-1">
|
||||||
|
Repositories are added to Sourcebot using <span className="text-primary">connections</span>. To add a new repo, add it to an existing connection or create a new one.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="flex-1 overflow-y-auto p-6">
|
||||||
|
<ConnectionList className="w-full" />
|
||||||
|
</div>
|
||||||
|
<DialogFooter className="flex justify-between items-center border-t p-4 px-6">
|
||||||
|
<Button asChild variant="default" className="bg-primary hover:bg-primary/90">
|
||||||
|
<Link href={`/${domain}/connections`}>Add new connection</Link>
|
||||||
|
</Button>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="outline">Close</Button>
|
||||||
|
</DialogClose>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -1,141 +1,265 @@
|
||||||
'use client';
|
"use client"
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button"
|
||||||
import { Column, ColumnDef } from "@tanstack/react-table"
|
import type { ColumnDef } from "@tanstack/react-table"
|
||||||
import { ArrowUpDown } from "lucide-react"
|
import { ArrowUpDown, ExternalLink, Clock, Loader2, CheckCircle2, XCircle, Trash2, Check, ListFilter } from "lucide-react"
|
||||||
import prettyBytes from "pretty-bytes";
|
import Image from "next/image"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { RepoIndexingStatus } from "@sourcebot/db";
|
||||||
|
import { useDomain } from "@/hooks/useDomain"
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
|
||||||
|
import { AddRepoButton } from "./addRepoButton"
|
||||||
|
|
||||||
export type RepositoryColumnInfo = {
|
export type RepositoryColumnInfo = {
|
||||||
name: string;
|
name: string
|
||||||
branches: {
|
imageUrl?: string
|
||||||
name: string,
|
connections: {
|
||||||
version: string,
|
id: number
|
||||||
}[];
|
name: string
|
||||||
repoSizeBytes: number;
|
}[]
|
||||||
indexedFiles: number;
|
repoIndexingStatus: RepoIndexingStatus
|
||||||
indexSizeBytes: number;
|
lastIndexed: string
|
||||||
shardCount: number;
|
url: string
|
||||||
lastIndexed: string;
|
|
||||||
latestCommit: string;
|
|
||||||
commitUrlTemplate: string;
|
|
||||||
url: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const columns: ColumnDef<RepositoryColumnInfo>[] = [
|
const statusLabels = {
|
||||||
|
[RepoIndexingStatus.NEW]: "Queued",
|
||||||
|
[RepoIndexingStatus.IN_INDEX_QUEUE]: "Queued",
|
||||||
|
[RepoIndexingStatus.INDEXING]: "Indexing",
|
||||||
|
[RepoIndexingStatus.INDEXED]: "Indexed",
|
||||||
|
[RepoIndexingStatus.FAILED]: "Failed",
|
||||||
|
[RepoIndexingStatus.IN_GC_QUEUE]: "Deleting",
|
||||||
|
[RepoIndexingStatus.GARBAGE_COLLECTING]: "Deleting",
|
||||||
|
[RepoIndexingStatus.GARBAGE_COLLECTION_FAILED]: "Deletion Failed"
|
||||||
|
};
|
||||||
|
|
||||||
|
const StatusIndicator = ({ status }: { status: RepoIndexingStatus }) => {
|
||||||
|
let icon = null
|
||||||
|
let description = ""
|
||||||
|
let className = ""
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
case RepoIndexingStatus.NEW:
|
||||||
|
case RepoIndexingStatus.IN_INDEX_QUEUE:
|
||||||
|
icon = <Clock className="h-3.5 w-3.5" />
|
||||||
|
description = "Repository is queued for indexing"
|
||||||
|
className = "text-yellow-600 bg-yellow-50 dark:bg-yellow-900/20 dark:text-yellow-400"
|
||||||
|
break
|
||||||
|
case RepoIndexingStatus.INDEXING:
|
||||||
|
icon = <Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||||
|
description = "Repository is being indexed"
|
||||||
|
className = "text-blue-600 bg-blue-50 dark:bg-blue-900/20 dark:text-blue-400"
|
||||||
|
break
|
||||||
|
case RepoIndexingStatus.INDEXED:
|
||||||
|
icon = <CheckCircle2 className="h-3.5 w-3.5" />
|
||||||
|
description = "Repository has been successfully indexed"
|
||||||
|
className = "text-green-600 bg-green-50 dark:bg-green-900/20 dark:text-green-400"
|
||||||
|
break
|
||||||
|
case RepoIndexingStatus.FAILED:
|
||||||
|
icon = <XCircle className="h-3.5 w-3.5" />
|
||||||
|
description = "Repository indexing failed"
|
||||||
|
className = "text-red-600 bg-red-50 dark:bg-red-900/20 dark:text-red-400"
|
||||||
|
break
|
||||||
|
case RepoIndexingStatus.IN_GC_QUEUE:
|
||||||
|
case RepoIndexingStatus.GARBAGE_COLLECTING:
|
||||||
|
icon = <Trash2 className="h-3.5 w-3.5" />
|
||||||
|
description = "Repository is being deleted"
|
||||||
|
className = "text-gray-600 bg-gray-50 dark:bg-gray-900/20 dark:text-gray-400"
|
||||||
|
break
|
||||||
|
case RepoIndexingStatus.GARBAGE_COLLECTION_FAILED:
|
||||||
|
icon = <XCircle className="h-3.5 w-3.5" />
|
||||||
|
description = "Repository deletion failed"
|
||||||
|
className = "text-red-600 bg-red-50 dark:bg-red-900/20 dark:text-red-400"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<div
|
||||||
|
className={cn("flex items-center gap-1.5 text-xs font-medium px-2.5 py-0.5 rounded-full w-fit", className)}
|
||||||
|
>
|
||||||
|
{icon}
|
||||||
|
{statusLabels[status]}
|
||||||
|
</div>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p className="text-sm">{description}</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const columns = (domain: string): ColumnDef<RepositoryColumnInfo>[] => [
|
||||||
{
|
{
|
||||||
accessorKey: "name",
|
accessorKey: "name",
|
||||||
header: "Name",
|
header: () => (
|
||||||
|
<div className="flex items-center w-[400px]">
|
||||||
|
<span>Repository</span>
|
||||||
|
<AddRepoButton />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const repo = row.original;
|
const repo = row.original
|
||||||
const url = repo.url;
|
const url = repo.url
|
||||||
// local repositories will have a url of 0 length
|
const isRemoteRepo = url.length > 0
|
||||||
const isRemoteRepo = url.length === 0;
|
|
||||||
return (
|
|
||||||
<div className="flex flex-row items-center gap-2">
|
|
||||||
<span
|
|
||||||
className={!isRemoteRepo ? "cursor-pointer text-blue-500 hover:underline": ""}
|
|
||||||
onClick={() => {
|
|
||||||
if (!isRemoteRepo) {
|
|
||||||
window.open(url, "_blank");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{repo.name}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "branches",
|
|
||||||
header: "Branches",
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const branches = row.original.branches;
|
|
||||||
|
|
||||||
if (branches.length === 0) {
|
|
||||||
return <div>N/A</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-2 max-h-32 overflow-scroll scrollbar-hide">
|
<div className="flex flex-row items-center gap-3 py-2">
|
||||||
{branches.map(({ name, version }, index) => {
|
<div className="relative h-8 w-8 overflow-hidden rounded-md border bg-muted">
|
||||||
const shortVersion = version.substring(0, 8);
|
{repo.imageUrl ? (
|
||||||
return (
|
<Image
|
||||||
<span key={index}>
|
src={repo.imageUrl || "/placeholder.svg"}
|
||||||
{name}
|
alt={`${repo.name} logo`}
|
||||||
@
|
width={32}
|
||||||
<span
|
height={32}
|
||||||
className="cursor-pointer text-blue-500 hover:underline"
|
className="object-cover"
|
||||||
onClick={() => {
|
/>
|
||||||
const url = row.original.commitUrlTemplate.replace("{{.Version}}", version);
|
) : (
|
||||||
window.open(url, "_blank");
|
<div className="flex h-full w-full items-center justify-center bg-muted text-xs font-medium uppercase text-muted-foreground">
|
||||||
}}
|
{repo.name.charAt(0)}
|
||||||
>
|
</div>
|
||||||
{shortVersion}
|
)}
|
||||||
</span>
|
</div>
|
||||||
</span>
|
<div className="flex items-center gap-2">
|
||||||
)
|
<span
|
||||||
})}
|
className={isRemoteRepo ? "font-medium text-primary hover:underline cursor-pointer" : "font-medium"}
|
||||||
|
onClick={() => {
|
||||||
|
if (isRemoteRepo) {
|
||||||
|
window.open(url, "_blank")
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{repo.name}
|
||||||
|
</span>
|
||||||
|
{isRemoteRepo && <ExternalLink className="h-3.5 w-3.5 text-muted-foreground" />}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "shardCount",
|
accessorKey: "connections",
|
||||||
header: ({ column }) => createSortHeader("Shard Count", column),
|
header: () => <div className="w-[200px]">Connections</div>,
|
||||||
cell: ({ row }) => (
|
|
||||||
<div className="text-right">{row.original.shardCount}</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "indexedFiles",
|
|
||||||
header: ({ column }) => createSortHeader("Indexed Files", column),
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<div className="text-right">{row.original.indexedFiles}</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "indexSizeBytes",
|
|
||||||
header: ({ column }) => createSortHeader("Index Size", column),
|
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const size = prettyBytes(row.original.indexSizeBytes);
|
const connections = row.original.connections
|
||||||
return <div className="text-right">{size}</div>;
|
|
||||||
}
|
if (!connections || connections.length === 0) {
|
||||||
|
return <div className="text-muted-foreground text-sm">—</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
{connections.map((connection) => (
|
||||||
|
<Badge
|
||||||
|
key={connection.id}
|
||||||
|
variant="outline"
|
||||||
|
className="text-xs px-2 py-0.5 hover:bg-muted cursor-pointer group flex items-center gap-1"
|
||||||
|
onClick={() => {
|
||||||
|
window.location.href = `/${domain}/connections/${connection.id}`
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{connection.name}
|
||||||
|
<ExternalLink className="h-3 w-3 text-muted-foreground opacity-50 group-hover:opacity-100 transition-opacity" />
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "repoSizeBytes",
|
accessorKey: "repoIndexingStatus",
|
||||||
header: ({ column }) => createSortHeader("Repository Size", column),
|
header: ({ column }) => {
|
||||||
|
const uniqueLabels = Array.from(new Set(Object.values(statusLabels)));
|
||||||
|
const currentFilter = column.getFilterValue() as string | undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-[150px]">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant={currentFilter ? "secondary" : "ghost"}
|
||||||
|
className="font-medium"
|
||||||
|
>
|
||||||
|
Status
|
||||||
|
<ListFilter className={cn(
|
||||||
|
"ml-2 h-3.5 w-3.5",
|
||||||
|
currentFilter ? "text-primary" : "text-muted-foreground"
|
||||||
|
)} />
|
||||||
|
{currentFilter && (
|
||||||
|
<div className="absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full bg-primary animate-pulse" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="start">
|
||||||
|
<DropdownMenuItem onClick={() => column.setFilterValue(undefined)}>
|
||||||
|
<Check className={cn("mr-2 h-4 w-4", !column.getFilterValue() ? "opacity-100" : "opacity-0")} />
|
||||||
|
All
|
||||||
|
</DropdownMenuItem>
|
||||||
|
{uniqueLabels.map((label) => (
|
||||||
|
<DropdownMenuItem key={label} onClick={() => column.setFilterValue(label)}>
|
||||||
|
<Check className={cn("mr-2 h-4 w-4", column.getFilterValue() === label ? "opacity-100" : "opacity-0")} />
|
||||||
|
{label}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const size = prettyBytes(row.original.repoSizeBytes);
|
return <StatusIndicator status={row.original.repoIndexingStatus} />
|
||||||
return <div className="text-right">{size}</div>;
|
},
|
||||||
}
|
filterFn: (row, id, value) => {
|
||||||
|
if (value === undefined) return true;
|
||||||
|
|
||||||
|
const status = row.getValue(id) as RepoIndexingStatus;
|
||||||
|
return statusLabels[status] === value;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "lastIndexed",
|
accessorKey: "lastIndexed",
|
||||||
header: ({ column }) => createSortHeader("Last Indexed", column),
|
header: ({ column }) => (
|
||||||
|
<div className="w-[150px]">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
className="font-medium"
|
||||||
|
>
|
||||||
|
Last Indexed
|
||||||
|
<ArrowUpDown className="ml-2 h-3.5 w-3.5 text-muted-foreground" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const date = new Date(row.original.lastIndexed);
|
if (!row.original.lastIndexed) {
|
||||||
return date.toISOString();
|
return <div>-</div>;
|
||||||
}
|
}
|
||||||
|
const date = new Date(row.original.lastIndexed)
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="font-medium">
|
||||||
|
{date.toLocaleDateString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-muted-foreground">
|
||||||
|
{date
|
||||||
|
.toLocaleTimeString("en-US", {
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: false,
|
||||||
|
})
|
||||||
|
.toLowerCase()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: "latestCommit",
|
|
||||||
header: ({ column }) => createSortHeader("Latest Commit", column),
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const date = new Date(row.original.latestCommit);
|
|
||||||
return date.toISOString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
const createSortHeader = (name: string, column: Column<RepositoryColumnInfo, unknown>) => {
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
|
||||||
>
|
|
||||||
{name}
|
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
19
packages/web/src/app/[domain]/repos/layout.tsx
Normal file
19
packages/web/src/app/[domain]/repos/layout.tsx
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { NavigationMenu } from "../components/navigationMenu";
|
||||||
|
|
||||||
|
export default function Layout({
|
||||||
|
children,
|
||||||
|
params: { domain },
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
params: { domain: string };
|
||||||
|
}>) {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex flex-col">
|
||||||
|
<NavigationMenu domain={domain} />
|
||||||
|
<main className="flex-grow flex justify-center p-4 bg-backgroundSecondary relative">
|
||||||
|
<div className="w-full max-w-6xl rounded-lg p-6">{children}</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -1,23 +1,24 @@
|
||||||
import { Suspense } from "react";
|
|
||||||
import { NavigationMenu } from "../components/navigationMenu";
|
import { NavigationMenu } from "../components/navigationMenu";
|
||||||
import { RepositoryTable } from "./repositoryTable";
|
import { RepositoryTable } from "./repositoryTable";
|
||||||
import { getOrgFromDomain } from "@/data/org";
|
import { getOrgFromDomain } from "@/data/org";
|
||||||
import { PageNotFound } from "../components/pageNotFound";
|
import { PageNotFound } from "../components/pageNotFound";
|
||||||
|
import { Header } from "../components/header";
|
||||||
export default async function ReposPage({ params: { domain } }: { params: { domain: string } }) {
|
export default async function ReposPage({ params: { domain } }: { params: { domain: string } }) {
|
||||||
const org = await getOrgFromDomain(domain);
|
const org = await getOrgFromDomain(domain);
|
||||||
if (!org) {
|
if (!org) {
|
||||||
return <PageNotFound />
|
return <PageNotFound />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-screen flex flex-col items-center">
|
<div>
|
||||||
<NavigationMenu domain={domain} />
|
<Header>
|
||||||
<Suspense fallback={<div>Loading...</div>}>
|
<h1 className="text-3xl">Repositories</h1>
|
||||||
<div className="max-w-[90%]">
|
</Header>
|
||||||
<RepositoryTable orgId={ org.id }/>
|
<div className="h-screen flex flex-col items-center">
|
||||||
|
<div className="w-full">
|
||||||
|
<RepositoryTable />
|
||||||
</div>
|
</div>
|
||||||
</Suspense>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,88 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
import { DataTable } from "@/components/ui/data-table";
|
import { DataTable } from "@/components/ui/data-table";
|
||||||
import { columns, RepositoryColumnInfo } from "./columns";
|
import { columns, RepositoryColumnInfo } from "./columns";
|
||||||
import { listRepositories } from "@/lib/server/searchService";
|
import { unwrapServiceError } from "@/lib/utils";
|
||||||
import { isServiceError } from "@/lib/utils";
|
import { getRepos } from "@/actions";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { NEXT_PUBLIC_POLLING_INTERVAL_MS } from "@/lib/environment.client";
|
||||||
|
import { useDomain } from "@/hooks/useDomain";
|
||||||
|
import { RepoIndexingStatus } from "@sourcebot/db";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
|
||||||
export const RepositoryTable = async ({ orgId }: { orgId: number }) => {
|
export const RepositoryTable = () => {
|
||||||
const _repos = await listRepositories(orgId);
|
const domain = useDomain();
|
||||||
|
const { data: repos, isLoading: reposLoading, error: reposError } = useQuery({
|
||||||
if (isServiceError(_repos)) {
|
queryKey: ['repos', domain],
|
||||||
return <div>Error fetching repositories</div>;
|
queryFn: async () => {
|
||||||
}
|
return await unwrapServiceError(getRepos(domain));
|
||||||
|
},
|
||||||
const repos = _repos.List.Repos.map((repo): RepositoryColumnInfo => {
|
refetchInterval: NEXT_PUBLIC_POLLING_INTERVAL_MS,
|
||||||
return {
|
refetchIntervalInBackground: true,
|
||||||
name: repo.Repository.Name,
|
|
||||||
branches: (repo.Repository.Branches ?? []).map((branch) => {
|
|
||||||
return {
|
|
||||||
name: branch.Name,
|
|
||||||
version: branch.Version,
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
repoSizeBytes: repo.Stats.ContentBytes,
|
|
||||||
indexSizeBytes: repo.Stats.IndexBytes,
|
|
||||||
shardCount: repo.Stats.Shards,
|
|
||||||
lastIndexed: repo.IndexMetadata.IndexTime,
|
|
||||||
latestCommit: repo.Repository.LatestCommitDate,
|
|
||||||
indexedFiles: repo.Stats.Documents,
|
|
||||||
commitUrlTemplate: repo.Repository.CommitURLTemplate,
|
|
||||||
url: repo.Repository.URL,
|
|
||||||
}
|
|
||||||
}).sort((a, b) => {
|
|
||||||
return new Date(b.lastIndexed).getTime() - new Date(a.lastIndexed).getTime();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const tableRepos = useMemo(() => {
|
||||||
|
if (reposLoading) return Array(4).fill(null).map(() => ({
|
||||||
|
name: "",
|
||||||
|
connections: [],
|
||||||
|
repoIndexingStatus: RepoIndexingStatus.NEW,
|
||||||
|
lastIndexed: "",
|
||||||
|
url: "",
|
||||||
|
imageUrl: "",
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (!repos) return [];
|
||||||
|
return repos.map((repo): RepositoryColumnInfo => ({
|
||||||
|
name: repo.repoName.split('/').length > 2 ? repo.repoName.split('/').slice(-2).join('/') : repo.repoName,
|
||||||
|
imageUrl: repo.imageUrl,
|
||||||
|
connections: repo.linkedConnections,
|
||||||
|
repoIndexingStatus: repo.repoIndexingStatus as RepoIndexingStatus,
|
||||||
|
lastIndexed: repo.indexedAt?.toISOString() ?? "",
|
||||||
|
url: repo.repoCloneUrl,
|
||||||
|
})).sort((a, b) => {
|
||||||
|
return new Date(b.lastIndexed).getTime() - new Date(a.lastIndexed).getTime();
|
||||||
|
});
|
||||||
|
}, [repos, reposLoading]);
|
||||||
|
|
||||||
|
const tableColumns = useMemo(() => {
|
||||||
|
if (reposLoading) {
|
||||||
|
return columns(domain).map((column) => {
|
||||||
|
if ('accessorKey' in column && column.accessorKey === "name") {
|
||||||
|
return {
|
||||||
|
...column,
|
||||||
|
cell: () => (
|
||||||
|
<div className="flex flex-row items-center gap-3 py-2">
|
||||||
|
<Skeleton className="h-8 w-8 rounded-md" /> {/* Avatar skeleton */}
|
||||||
|
<Skeleton className="h-4 w-48" /> {/* Repository name skeleton */}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...column,
|
||||||
|
cell: () => (
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
<Skeleton className="h-5 w-24 rounded-full" />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return columns(domain);
|
||||||
|
}, [reposLoading, domain]);
|
||||||
|
|
||||||
|
|
||||||
|
if (reposError) {
|
||||||
|
return <div>Error loading repositories</div>;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={tableColumns}
|
||||||
data={repos}
|
data={tableRepos}
|
||||||
searchKey="name"
|
searchKey="name"
|
||||||
searchPlaceholder="Search repositories..."
|
searchPlaceholder="Search repositories..."
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,10 @@ export const repositoryQuerySchema = z.object({
|
||||||
repoId: z.number(),
|
repoId: z.number(),
|
||||||
repoName: z.string(),
|
repoName: z.string(),
|
||||||
repoCloneUrl: z.string(),
|
repoCloneUrl: z.string(),
|
||||||
linkedConnections: z.array(z.number()),
|
linkedConnections: z.array(z.object({
|
||||||
|
id: z.number(),
|
||||||
|
name: z.string(),
|
||||||
|
})),
|
||||||
imageUrl: z.string().optional(),
|
imageUrl: z.string().optional(),
|
||||||
indexedAt: z.date().optional(),
|
indexedAt: z.date().optional(),
|
||||||
repoIndexingStatus: z.nativeEnum(RepoIndexingStatus),
|
repoIndexingStatus: z.nativeEnum(RepoIndexingStatus),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue