Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-12794): keep studio Code a run-view tab; editor Visual/YAML as shared toggles (#7662)
Celal Zamanoğlue90e8fb3bb2c
diff --git a/skyvern-frontend/src/routes/workflows/studio/EditorPaneHeader.test.tsx b/skyvern-frontend/src/routes/workflows/studio/EditorPaneHeader.test.tsxindex 49b1be52c..468fe78ae 100644--- a/skyvern-frontend/src/routes/workflows/studio/EditorPaneHeader.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/EditorPaneHeader.test.tsx@@ -10,14 +10,23 @@ import {test,vi,} from "vitest";-import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import {+ cleanup,+ fireEvent,+ render,+ screen,+ waitFor,+} from "@testing-library/react";import { TooltipProvider } from "@/components/ui/tooltip";import { useWorkflowBlockSearchStore } from "@/store/WorkflowBlockSearchStore";import { useWorkflowYamlEditorStore } from "@/store/WorkflowYamlEditorStore";import { type BlockSearchTarget } from "./blockSearch";-import { EditorPaneBlockSearch } from "./EditorPaneHeader";+import {+ EditorPaneBlockSearch,+ EditorPaneModeToggle,+} from "./EditorPaneHeader";// cmdk and Radix Popover need ResizeObserver and scrollIntoView, which jsdom// lacks. Install them for this suite only and restore afterward.@@ -81,6 +90,8 @@ beforeEach(() => {focusBlock.mockReset();useWorkflowBlockSearchStore.getState().registerHandle(null);useWorkflowYamlEditorStore.getState().close();+ useWorkflowYamlEditorStore.getState().registerEnterYamlMode(null);+ useWorkflowYamlEditorStore.getState().registerCommit(null);});describe("EditorPaneBlockSearch", () => {@@ -175,3 +186,93 @@ describe("EditorPaneBlockSearch", () => {expect(screen.getAllByRole("option")).toHaveLength(3);});});++describe("EditorPaneModeToggle", () => {+ function renderToggle() {+ return render(+ <TooltipProvider delayDuration={0}>+ <EditorPaneModeToggle />+ </TooltipProvider>,+ );+ }++ test("renders nothing until a canvas registers the YAML entry point", () => {+ renderToggle();+ expect(screen.queryByRole("button", { name: "Visual" })).toBeNull();+ expect(screen.queryByRole("button", { name: "YAML" })).toBeNull();+ });++ test("shows the Visual/YAML pair once registered, defaulting to Visual", () => {+ const store = useWorkflowYamlEditorStore.getState();+ store.registerEnterYamlMode(() => store.open("blocks: []"));+ renderToggle();++ const visual = screen.getByRole("button", { name: "Visual" });+ const yaml = screen.getByRole("button", { name: "YAML" });+ expect(visual.getAttribute("aria-pressed")).toBe("true");+ expect(yaml.getAttribute("aria-pressed")).toBe("false");+ });++ test("YAML enters yaml mode; Visual commits back out", async () => {+ const store = useWorkflowYamlEditorStore.getState();+ store.registerEnterYamlMode(() => store.open("blocks: []"));+ store.registerCommit(async () => {+ useWorkflowYamlEditorStore.getState().close();+ return true;+ });+ renderToggle();++ fireEvent.click(screen.getByRole("button", { name: "YAML" }));+ expect(useWorkflowYamlEditorStore.getState().active).toBe(true);+ expect(+ screen.getByRole("button", { name: "YAML", pressed: true }),+ ).not.toBeNull();++ fireEvent.click(screen.getByRole("button", { name: "Visual" }));+ await waitFor(() =>+ expect(useWorkflowYamlEditorStore.getState().active).toBe(false),+ );+ expect(+ screen.getByRole("button", { name: "Visual", pressed: true }),+ ).not.toBeNull();+ });++ test("clicking the already-active segment does not re-fire its action", () => {+ const store = useWorkflowYamlEditorStore.getState();+ const enterYaml = vi.fn(() => store.open("blocks: []"));+ const commit = vi.fn(async () => {+ useWorkflowYamlEditorStore.getState().close();+ return true;+ });+ store.registerEnterYamlMode(enterYaml);+ store.registerCommit(commit);+ renderToggle();++ // Visual mode: clicking the active Visual segment must not commit.+ fireEvent.click(screen.getByRole("button", { name: "Visual" }));+ expect(commit).not.toHaveBeenCalled();++ // Clicking the now-active YAML segment must not re-enter — reserializing+ // the canvas would discard the in-progress YAML draft.+ fireEvent.click(screen.getByRole("button", { name: "YAML" }));+ expect(enterYaml).toHaveBeenCalledTimes(1);+ fireEvent.click(screen.getByRole("button", { name: "YAML" }));+ expect(enterYaml).toHaveBeenCalledTimes(1);+ });++ test("both toggles are disabled while a commit is in flight", () => {+ const store = useWorkflowYamlEditorStore.getState();+ store.registerEnterYamlMode(() => store.open("blocks: []"));+ store.setCommitting(true);+ renderToggle();++ expect(+ (screen.getByRole("button", { name: "Visual" }) as HTMLButtonElement)+ .disabled,+ ).toBe(true);+ expect(+ (screen.getByRole("button", { name: "YAML" }) as HTMLButtonElement)+ .disabled,+ ).toBe(true);+ });+});diff --git a/skyvern-frontend/src/routes/workflows/studio/EditorPaneHeader.tsx b/skyvern-frontend/src/routes/workflows/studio/EditorPaneHeader.tsxindex 2a215e183..896aba69f 100644--- a/skyvern-frontend/src/routes/workflows/studio/EditorPaneHeader.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/EditorPaneHeader.tsx@@ -1,4 +1,8 @@-import { MagnifyingGlassIcon } from "@radix-ui/react-icons";+import {+ CodeIcon,+ EyeOpenIcon,+ MagnifyingGlassIcon,+} from "@radix-ui/react-icons";import { useMemo, useState } from "react";import {@@ -21,19 +25,19 @@ import {} from "@/store/WorkflowYamlEditorStore";import { useWorkflowBlockSearchStore } from "@/store/WorkflowBlockSearchStore";-import { YamlModeToggle } from "../editor/YamlModeToggle";import { filterBlockSearchTargets } from "./blockSearch";import { PANE_HEADER_ICON_BUTTON_CLASS, studioPanelId } from "./constants";import { ControlTooltip } from "./ControlTooltip";import { PaneHeaderDivider } from "./PaneHeaderDivider";import { useStudioPaneCompact } from "./StudioShellContext";+import { ViewToggle } from "./ViewToggle";/**- * Editor pane header chrome: the Visual/Code mode toggle, relocated from the- * canvas's floating overlay. Entry is registered by the embedded Workspace- * (it owns the canvas→YAML serialization); exit is the store's shared- * commit-on-switch flow. Hidden for read-only (global) workflows, which never- * register an entry point.+ * Editor pane header chrome: the Visual/YAML mode toggle, the same segmented+ * ViewToggle pair the other pane strips use. Entry is registered by the+ * embedded Workspace (it owns the canvas→YAML serialization); exit is the+ * store's shared commit-on-switch flow. Hidden for read-only (global)+ * workflows, which never register an entry point.*/export function EditorPaneModeToggle() {const compact = useStudioPaneCompact();@@ -46,13 +50,40 @@ export function EditorPaneModeToggle() {return (<><PaneHeaderDivider />- <YamlModeToggle- mode={active ? "code" : "visual"}- compact={compact}- disabled={committing}- onCode={enterYamlMode}- onVisual={() => void commitYamlDraft(false)}- />+ <div+ role="group"+ aria-label="Editor view"+ className="flex shrink-0 items-center gap-1"+ >+ <ViewToggle+ active={!active}+ // Only the inactive segment acts: re-committing from Visual or+ // re-entering from YAML would reserialize the canvas and discard the+ // in-progress YAML draft (the old YamlModeToggle omitted the handler+ // on the active segment for the same reason).+ onClick={() => {+ if (active) {+ void commitYamlDraft(false);+ }+ }}+ disabled={committing}+ compact={compact}+ label="Visual"+ icon={<EyeOpenIcon className="h-3 w-3" />}+ />+ <ViewToggle+ active={active}+ onClick={() => {+ if (!active) {+ enterYamlMode();+ }+ }}+ disabled={committing}+ compact={compact}+ label="YAML"+ icon={<CodeIcon className="h-3 w-3" />}+ />+ </div></>);}diff --git a/skyvern-frontend/src/routes/workflows/studio/ViewToggle.tsx b/skyvern-frontend/src/routes/workflows/studio/ViewToggle.tsxindex 1ed0f06c9..dfededb3e 100644--- a/skyvern-frontend/src/routes/workflows/studio/ViewToggle.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/ViewToggle.tsx@@ -19,6 +19,7 @@ export function ViewToggle({compact,title,ariaLabel,+ disabled,}: {active: boolean;onClick: () => void;@@ -29,17 +30,20 @@ export function ViewToggle({// Overrides the accessible name without changing the visible label, e.g. to// append a badge's state ("Outputs, new output") to a screen reader only.ariaLabel?: string;+ disabled?: boolean;}) {const tip = title ?? (compact ? (ariaLabel ?? label) : undefined);const button = (<buttontype="button"onClick={onClick}+ disabled={disabled}aria-label={ariaLabel ?? label}aria-pressed={active}className={cn("inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-[11px] font-medium","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",+ "disabled:pointer-events-none disabled:opacity-40",active? "bg-accent text-foreground": "text-muted-foreground hover:bg-accent/50 hover:text-foreground",diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsxindex 8f3508cef..fb77f9cc4 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/RunView.test.tsx@@ -346,6 +346,11 @@ describe("RunView view toggles", () => {expect(scope.queryByTestId("workflow-run-code")).toBeNull();fireEvent.click(scope.getByRole("button", { name: "Code" }));expect(scope.queryByTestId("workflow-run-code")).not.toBeNull();+ // The Code toggle exposes aria-pressed once it's the active view, matching+ // the sibling view toggles (defends the shared ViewToggle disabled-prop add).+ expect(+ scope.getByRole("button", { name: "Code", pressed: true }),+ ).not.toBeNull();});test("the Code toggle shows a spinner while cached code is generating", () => {