Spaces:
Running

mcp-webcam / src /components /clients /PollerRow.tsx
evalstate's picture
evalstate HF Staff
Deploy mcp-webcam v0.3.0 (stateless MCP 2026-07-28 + SEP-3415 Events + Studio UI)
6f5f15e verified
Raw History Blame Contribute Delete
3.77 kB
import { Copy, ShieldBan } from 'lucide-react';
import { toast } from 'sonner';
import type { PollerView } from '../../../shared/api-types';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
import { formatMs, prettyCursor, relativeTime } from '@/lib/format';
import { ClientBadge } from './ClientBadge';
import { EraBadge } from './EraBadge';
import { cn } from '@/lib/utils';
export function PollerRow({
poller,
nowMs,
onRevoke,
}: {
poller: PollerView;
nowMs: number;
onRevoke: (pollerId: string) => Promise<void>;
}) {
const dotClass =
poller.status === 'active'
? 'bg-emerald-400'
: poller.status === 'idle'
? 'bg-event'
: 'bg-zinc-500';
const copyCursor = async () => {
if (!poller.cursor) return;
try {
await navigator.clipboard.writeText(poller.cursor);
toast.success('Copied poller cursor');
} catch {
toast.error('Clipboard copy failed');
}
};
return (
<div className="rounded-lg border border-poll/25 bg-panel-2/45 p-2.5 space-y-2">
<div className="flex items-start justify-between gap-2">
<div className="min-w-0 space-y-1">
<div className="flex flex-wrap items-center gap-1.5">
<span className={cn('h-2 w-2 rounded-full shrink-0', dotClass)} title={poller.status} />
<ClientBadge client={poller.client} />
<EraBadge era={poller.client.era} protocolVersion={poller.client.protocolVersion} />
{poller.revokePending && (
<Badge variant="danger" className="striped-revoke text-[10px]">
revoke pending
</Badge>
)}
</div>
<div className="flex flex-wrap items-center gap-1.5">
<Badge variant="poll" className="font-mono text-[10px]">
{poller.eventName}
</Badge>
<button
type="button"
onClick={() => void copyCursor()}
className="inline-flex items-center gap-1 font-mono text-[10.5px] text-muted hover:text-fg cursor-pointer"
title={poller.cursor ? `Copy cursor ${poller.cursor}` : 'No cursor'}
>
<span>cur:{prettyCursor(poller.cursor)}</span>
{poller.cursor && <Copy className="h-2.5 w-2.5 opacity-60" />}
</button>
</div>
</div>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="danger"
size="sm"
className="h-6.5 px-2 text-[11px] shrink-0"
disabled={poller.revokePending}
onClick={() =>
void onRevoke(poller.pollerId)
.then(() => toast.warning('Next poll will return -32024 Forbidden'))
.catch((e) => toast.error(e instanceof Error ? e.message : 'Revoke failed'))
}
>
<ShieldBan className="h-3 w-3" />
Revoke
</Button>
</TooltipTrigger>
<TooltipContent>Return -32024 Forbidden on this poller's next events/poll</TooltipContent>
</Tooltip>
</div>
<div className="flex flex-wrap items-center gap-3 text-[11px] text-muted tabular-nums">
<span>
polls <strong className="font-medium text-fg">{poller.polls}</strong>
</span>
<span>
delivered <strong className="font-medium text-fg">{poller.delivered}</strong>
</span>
<span>last {relativeTime(poller.lastPollAt, nowMs)}</span>
<span className="font-mono text-muted-2">next ≤ {formatMs(poller.nextPollMs)}</span>
</div>
</div>
);
}