feat: add copy button to events tab to copy all events as JSON

This commit is contained in:
Nathan Flurry 2026-01-27 20:31:38 -08:00
parent 6782836030
commit f2c060903f
8 changed files with 156 additions and 102 deletions

View file

@ -1,4 +1,4 @@
import { ChevronDown, ChevronRight } from "lucide-react";
import { ChevronDown, ChevronRight, Copy, Check } from "lucide-react";
import { useEffect, useState } from "react";
import type { UniversalEvent } from "sandbox-agent";
import { formatJson, formatTime } from "../../utils/format";
@ -20,6 +20,17 @@ const EventsTab = ({
error: string | null;
}) => {
const [collapsedEvents, setCollapsedEvents] = useState<Record<string, boolean>>({});
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(JSON.stringify(events, null, 2));
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error("Failed to copy events:", err);
}
};
useEffect(() => {
if (events.length === 0) {
@ -35,6 +46,15 @@ const EventsTab = ({
<button className="button ghost small" onClick={onFetch} disabled={loading}>
{loading ? "Loading..." : "Fetch"}
</button>
<button
className="button ghost small"
onClick={handleCopy}
disabled={events.length === 0}
title="Copy all events as JSON"
>
{copied ? <Check size={14} /> : <Copy size={14} />}
{copied ? "Copied" : "Copy"}
</button>
<button className="button ghost small" onClick={onClear}>
Clear
</button>