Skip to content

Automate browser based workflows with AI

feat(SKY-12443): make studio run-view JSON blocks searchable (#7586)

Celal Zamanoğlue870b724c28a
diff --git a/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx b/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx
index 0edeb5901..86fc27e47 100644
--- a/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx
+++ b/skyvern-frontend/src/routes/workflows/components/CodeEditor.tsx
@@ -35,6 +35,9 @@ function getLanguageExtension(
type Props = {
value: string;
onChange?: (value: string) => void;
+ // Invoked once with the CodeMirror view when it is created (e.g. to drive
+ // the search panel from a toolbar button).
+ onEditorView?: (view: EditorView) => void;
language?: "python" | "json" | "html" | "yaml";
lineWrap?: boolean;
readOnly?: boolean;
@@ -69,6 +72,7 @@ const VIEWPORT_PREMOUNT_MARGIN = "200px";
function CodeEditorImpl({
value,
onChange,
+ onEditorView,
minHeight,
maxHeight,
language,
@@ -141,6 +145,11 @@ function CodeEditorImpl({
latestOnChangeRef.current = onChange;
}, [onChange]);
+ const latestOnEditorViewRef = useRef(onEditorView);
+ useEffect(() => {
+ latestOnEditorViewRef.current = onEditorView;
+ }, [onEditorView]);
+
const debouncedOnChange = useDebouncedCallback((newValue: string) => {
latestOnChangeRef.current?.(newValue);
}, 300);
@@ -161,6 +170,7 @@ function CodeEditorImpl({
const handleCreateEditor = useCallback((view: EditorView) => {
viewRef.current = view;
+ latestOnEditorViewRef.current?.(view);
}, []);
const handleEditorUpdate = useCallback((viewUpdate: ViewUpdate) => {
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/OverviewCodeBlock.test.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/OverviewCodeBlock.test.tsx
new file mode 100644
index 000000000..1ceea61cf
--- /dev/null
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/OverviewCodeBlock.test.tsx
@@ -0,0 +1,31 @@
+import { fireEvent, render, screen } from "@testing-library/react";
+import { expect, test, vi } from "vitest";
+
+const { openSearchPanelSpy } = vi.hoisted(() => ({
+ openSearchPanelSpy: vi.fn(),
+}));
+
+vi.mock("@codemirror/search", async () => {
+ const actual =
+ await vi.importActual<typeof import("@codemirror/search")>(
+ "@codemirror/search",
+ );
+ return { ...actual, openSearchPanel: openSearchPanelSpy };
+});
+
+import { OverviewCodeBlock } from "./OverviewCodeBlock";
+
+test("opens CodeMirror search from the toolbar", () => {
+ render(<OverviewCodeBlock value='{"a":1}' />);
+
+ const searchButton = screen.getByRole("button", { name: "Search" });
+ expect(searchButton).toBeTruthy();
+ expect(
+ screen.getByRole("button", { name: "Copy to clipboard" }),
+ ).toBeTruthy();
+
+ fireEvent.click(searchButton);
+
+ expect(openSearchPanelSpy).toHaveBeenCalledTimes(1);
+ expect(openSearchPanelSpy.mock.calls[0]?.[0]).toBeTruthy();
+});
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/OverviewCodeBlock.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/OverviewCodeBlock.tsx
index a32ace84d..0b4cf77c7 100644
--- a/skyvern-frontend/src/routes/workflows/studio/runview/OverviewCodeBlock.tsx
+++ b/skyvern-frontend/src/routes/workflows/studio/runview/OverviewCodeBlock.tsx
@@ -1,6 +1,14 @@
+import { useRef } from "react";
+import { MagnifyingGlassIcon } from "@radix-ui/react-icons";
+import { EditorView, keymap } from "@uiw/react-codemirror";
+import { openSearchPanel, search, searchKeymap } from "@codemirror/search";
+
import { CopyButton } from "@/components/CopyButton";
+import { Button } from "@/components/ui/button";
import { CodeEditor } from "@/routes/workflows/components/CodeEditor";
+const SEARCH_EXTENSIONS = [search(), keymap.of(searchKeymap)];
+
export function OverviewCodeBlock({
value,
maxHeight = "220px",
@@ -8,9 +16,25 @@ export function OverviewCodeBlock({
value: string;
maxHeight?: string;
}) {
+ const viewRef = useRef<EditorView | null>(null);
+
return (
<div className="relative">
- <div className="absolute right-2 top-2 z-10">
+ <div className="absolute right-2 top-2 z-10 flex gap-1">
+ <Button
+ size="icon"
+ variant="ghost"
+ aria-label="Search"
+ className="h-7 w-7 bg-slate-elevation3/80 text-muted-foreground backdrop-blur hover:bg-slate-elevation4 hover:text-foreground"
+ onClick={() => {
+ const view = viewRef.current;
+ if (view) {
+ openSearchPanel(view);
+ }
+ }}
+ >
+ <MagnifyingGlassIcon />
+ </Button>
<CopyButton
value={value}
className="h-7 w-7 bg-slate-elevation3/80 text-muted-foreground backdrop-blur hover:bg-slate-elevation4 hover:text-foreground"
@@ -21,6 +45,10 @@ export function OverviewCodeBlock({
value={value}
readOnly
maxHeight={maxHeight}
+ extraExtensions={SEARCH_EXTENSIONS}
+ onEditorView={(view) => {
+ viewRef.current = view;
+ }}
/>
</div>
);