Skip to content

Automate browser based workflows with AI

Copy icon on hover for every JSON tree viewer node (SKY-13286) (#7900)

Suchintana2fcc2eff2c9
diff --git a/skyvern-frontend/src/components/CopyButton.tsx b/skyvern-frontend/src/components/CopyButton.tsx
index ff5c0f401..6be2c6c7a 100644
--- a/skyvern-frontend/src/components/CopyButton.tsx
+++ b/skyvern-frontend/src/components/CopyButton.tsx
@@ -3,14 +3,17 @@ import { CheckIcon, CopyIcon } from "@radix-ui/react-icons";
import { Button } from "@/components/ui/button";
import { copyText } from "@/util/copyText";
-import { cn } from "@/util/utils";
function CopyButton({
value,
className,
+ ariaLabel,
}: {
- value: string;
+ // A getter defers building the copied text until click, so callers rendering
+ // many buttons (e.g. per JSON-tree row) don't serialize on every render.
+ value: string | (() => string);
className?: string;
+ ariaLabel?: string;
}) {
const [copied, setCopied] = useState(false);
@@ -18,7 +21,7 @@ function CopyButton({
if (copied) {
return;
}
- await copyText(value);
+ await copyText(typeof value === "function" ? value() : value);
setCopied(true);
setTimeout(() => setCopied(false), 1500);
};
@@ -28,8 +31,8 @@ function CopyButton({
size="icon"
variant="ghost"
onClick={handleCopy}
- className={cn(className)}
- aria-label="Copy to clipboard"
+ className={className}
+ aria-label={ariaLabel ?? "Copy to clipboard"}
>
{copied ? <CheckIcon /> : <CopyIcon />}
</Button>
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.test.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.test.tsx
index 9c5914885..3386825e2 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.test.tsx
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.test.tsx
@@ -1,14 +1,19 @@
// @vitest-environment jsdom
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
-import { afterEach, describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { ActionTypes, Status, type ActionsApiResponse } from "@/api/types";
import type { WorkflowRunBlock } from "../../types/workflowRunTypes";
import { BlockInspector, JsonExplorer } from "./BlockInspector";
+const { copyTextMock } = vi.hoisted(() => ({ copyTextMock: vi.fn() }));
+
+vi.mock("@/util/copyText", () => ({ copyText: copyTextMock }));
+
afterEach(() => {
cleanup();
+ vi.clearAllMocks();
});
function buildBlock(
@@ -116,6 +121,32 @@ describe("JsonExplorer", () => {
expect(row.textContent).not.toContain('loop_value: "/runs"');
expect(screen.getByText("loop_value")).toBeDefined();
});
+
+ it("offers a copy button per node: raw text for leaves, the full subtree for nested nodes", () => {
+ render(
+ <JsonExplorer
+ rootLabel="output"
+ value={{ task: { id: "tsk_1" }, status: "completed" }}
+ />,
+ );
+
+ expect(screen.getAllByRole("button", { name: /^Copy / })).toHaveLength(3);
+
+ fireEvent.click(screen.getByRole("button", { name: "Copy status" }));
+ expect(copyTextMock).toHaveBeenLastCalledWith("completed");
+
+ fireEvent.click(screen.getByRole("button", { name: "Copy task" }));
+ expect(copyTextMock).toHaveBeenLastCalledWith(
+ JSON.stringify({ id: "tsk_1" }, null, 2),
+ );
+ // Copying a collapsed node must not expand it.
+ expect(screen.queryByText("id")).toBeNull();
+
+ fireEvent.click(screen.getByRole("button", { name: "Copy output" }));
+ expect(copyTextMock).toHaveBeenLastCalledWith(
+ JSON.stringify({ task: { id: "tsk_1" }, status: "completed" }, null, 2),
+ );
+ });
});
describe("BlockInspector Inputs tab", () => {
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.tsx b/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.tsx
index 2f99cc38f..049cee617 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.tsx
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/BlockInspector.tsx
@@ -11,6 +11,7 @@ import {
getReadableActionType,
type ActionsApiResponse,
} from "@/api/types";
+import { CopyButton } from "@/components/CopyButton";
import { Input } from "@/components/ui/input";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { cn } from "@/util/utils";
@@ -19,6 +20,7 @@ import {
shouldShowExtractedInformation,
type WorkflowRunBlock,
} from "../../types/workflowRunTypes";
+import { jsonClipboardText } from "./formatValue";
import { BlockDetailFailure } from "./shared";
type InspectorField = {
@@ -233,10 +235,19 @@ function JsonNode({
const isOpen = hasSearch || expanded.has(path);
const childCount = children.length;
+ const copyButton = (
+ // The path keeps accessible names unique when the same key repeats at
+ // different depths (e.g. two "id" fields).
+ <CopyButton
+ value={() => jsonClipboardText(value)}
+ ariaLabel={`Copy ${path === "$" ? label : path.slice(2)}`}
+ className="h-4 w-4 shrink-0 text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 group-hover/jsonnode:opacity-100 [&_svg]:size-3"
+ />
+ );
if (!isExpandable) {
return (
- <div className="flex min-w-0 items-start gap-1 py-0.5 text-xs">
+ <div className="group/jsonnode flex min-w-0 items-start gap-1 py-0.5 text-xs">
<span className="size-3.5 shrink-0" aria-hidden="true" />
<span className="shrink-0 text-muted-foreground dark:text-slate-500">
<HighlightedText text={label} search={search} />
@@ -244,31 +255,35 @@ function JsonNode({
<span className="min-w-0 break-words font-mono text-tertiary-foreground">
<HighlightedText text={primitivePreview(value)} search={search} />
</span>
+ {copyButton}
</div>
);
}
return (
<div className="min-w-0 text-xs">
- <button
- type="button"
- onClick={() => onToggle(path)}
- className="flex w-full min-w-0 cursor-pointer items-center gap-1 rounded py-0.5 text-left outline-none hover:bg-muted/60 focus-visible:ring-1 focus-visible:ring-foreground/40"
- >
- {isOpen ? (
- <ChevronDownIcon className="size-3.5 shrink-0 text-muted-foreground dark:text-slate-500" />
- ) : (
- <ChevronRightIcon className="size-3.5 shrink-0 text-muted-foreground dark:text-slate-500" />
- )}
- <span className="shrink-0 text-muted-foreground">
- <HighlightedText text={label} search={search} />
- </span>
- {!isOpen && (
- <span className="min-w-0 truncate font-mono text-tertiary-foreground">
- {expandablePreview(value, childCount)}
+ <div className="group/jsonnode flex min-w-0 items-center gap-1">
+ <button
+ type="button"
+ onClick={() => onToggle(path)}
+ className="flex min-w-0 flex-1 cursor-pointer items-center gap-1 rounded py-0.5 text-left outline-none hover:bg-muted/60 focus-visible:ring-1 focus-visible:ring-foreground/40"
+ >
+ {isOpen ? (
+ <ChevronDownIcon className="size-3.5 shrink-0 text-muted-foreground dark:text-slate-500" />
+ ) : (
+ <ChevronRightIcon className="size-3.5 shrink-0 text-muted-foreground dark:text-slate-500" />
+ )}
+ <span className="shrink-0 text-muted-foreground">
+ <HighlightedText text={label} search={search} />
</span>
- )}
- </button>
+ {!isOpen && (
+ <span className="min-w-0 truncate font-mono text-tertiary-foreground">
+ {expandablePreview(value, childCount)}
+ </span>
+ )}
+ </button>
+ {copyButton}
+ </div>
{isOpen && (
<div className="ml-4 border-l border-border pl-3">
{children.map(([childKey, childValue]) => (
diff --git a/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/formatValue.ts b/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/formatValue.ts
index b8719c98c..e96a5bc2d 100644
--- a/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/formatValue.ts
+++ b/skyvern-frontend/src/routes/workflows/workflowRun/blockDetail/formatValue.ts
@@ -15,4 +15,17 @@ function stringifyTimelineValue(value: unknown): string {
}
}
+// Strings copy raw (unquoted) so identifiers paste cleanly; objects/arrays copy
+// their full subtree as pretty-printed JSON.
+export function jsonClipboardText(value: unknown): string {
+ if (typeof value === "string") {
+ return value;
+ }
+ try {
+ return JSON.stringify(value, null, 2);
+ } catch {
+ return String(value);
+ }
+}
+
export { stringifyTimelineValue };