"use client"; import { IconPlayerPause, IconPlayerPlay, IconEdit, IconRefresh, IconRestore, IconTrash, } from "@tabler/icons-react"; import { Badge } from "@kandev/ui/badge"; import { Button } from "@kandev/ui/button"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@kandev/ui/table"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import type { IssueWatch, ReviewWatch } from "@/lib/types/gitlab"; type Watch = ReviewWatch | IssueWatch; export type WatchTableProps = { watches: TWatch[]; dirtyIds: ReadonlySet; authoritativeEnabledById: ReadonlyMap; onEdit: (watch: TWatch) => void; onDelete: (id: string) => void; onTrigger: (id: string) => void; onReset: (id: string) => void; onToggleEnabled: (watch: TWatch) => void; }; type ActionProps = Omit, "watches"> & { watch: TWatch; mobile?: boolean; }; function checkUnavailableReason(dirty: boolean, enabled: boolean): string | undefined { if (dirty) return "Save changes before checking now"; if (!enabled) return "Enable this watch before checking now"; return undefined; } function CheckNowButton({ size, disabledReason, onClick, }: { size: string; disabledReason?: string; onClick: (event: React.MouseEvent) => void; }) { const button = ( ); if (!disabledReason) return button; return ( {button} {disabledReason} ); } function WatchActions({ watch, dirtyIds, authoritativeEnabledById, onEdit, onDelete, onTrigger, onReset, onToggleEnabled, mobile, }: ActionProps) { const size = mobile ? "h-11 w-11" : "h-8 w-8"; const dirty = dirtyIds.has(watch.id); const authoritativeEnabled = authoritativeEnabledById.get(watch.id) ?? watch.enabled; const checkReason = checkUnavailableReason(dirty, authoritativeEnabled); const stop = (action: () => void) => (event: React.MouseEvent) => { event.stopPropagation(); action(); }; return (
onTrigger(watch.id))} />
); } function projectSummary(watch: Watch): string { return watch.projects.length > 0 ? watch.projects.map((project) => project.path).join(", ") : "All projects"; } function lastPolled(value?: string): string { if (!value) return "Never"; return new Date(value).toLocaleString(); } function WatchError({ watch }: { watch: Watch }) { if (!watch.last_error) return null; return (

{watch.last_error}

); } function MobileWatchCard(props: ActionProps) { const { watch, onEdit } = props; return (
); } export function GitLabWatchTable(props: WatchTableProps) { if (props.watches.length === 0) { return

No watches configured.

; } return ( <>
{props.watches.map((watch) => ( ))}
Projects Interval Last checked Status Actions {props.watches.map((watch) => ( props.onEdit(watch)} >

{projectSummary(watch)}

{Math.round(watch.poll_interval_seconds / 60)}m {lastPolled(watch.last_polled_at)} {watch.enabled ? "Active" : "Paused"}
))}
); }