Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
feat(SKY-11479): center screenshots on zoom-click in Run tab (#6846)
Celal Zamanoğlu2c49a74a95ac
diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.tsx b/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.tsxindex 1690c7f72..3de1424a9 100644--- a/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.tsx+++ b/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.tsx@@ -1,3 +1,4 @@+import { useEffect, useLayoutEffect, useRef, useState } from "react";import { ReloadIcon } from "@radix-ui/react-icons";import { useQuery } from "@tanstack/react-query";@@ -6,12 +7,31 @@ import { ArtifactApiResponse } from "@/api/types";import { useCredentialGetter } from "@/hooks/useCredentialGetter";import { getImageURL } from "@/routes/tasks/detail/artifactUtils";+import { screenshotZoomClasses } from "./HeroScreenshot.utils";+/**- * The pinned/active action screenshot, letterboxed to fit the run hero. Shares the- * ["artifact", id] cache with the filmstrip thumbnails so each is fetched once.+ * The pinned/active action screenshot, fit to the run-hero width and scrollable+ * for long captures. Shares the ["artifact", id] cache with the filmstrip+ * thumbnails so each is fetched once.*/export function HeroScreenshot({ artifactId }: { artifactId: string | null }) {const credentialGetter = useCredentialGetter();+ const [zoomed, setZoomed] = useState(false);+ const containerRef = useRef<HTMLDivElement>(null);+ useEffect(() => {+ setZoomed(false);+ }, [artifactId]);++ // Start each view at the top; when zoomed, center horizontally too (margin-auto+ // resolves to 0 once the image overflows, so the scroll would default to left).+ useLayoutEffect(() => {+ const el = containerRef.current;+ if (!el) {+ return;+ }+ el.scrollTop = 0;+ el.scrollLeft = zoomed ? (el.scrollWidth - el.clientWidth) / 2 : 0;+ }, [zoomed, artifactId]);const { data, isLoading } = useQuery<ArtifactApiResponse>({queryKey: ["artifact", artifactId],queryFn: async () => {@@ -48,11 +68,28 @@ export function HeroScreenshot({ artifactId }: { artifactId: string | null }) {</div>);}+ const toggleZoom = () => setZoomed((z) => !z);+ const zoom = screenshotZoomClasses(zoomed);return (- <img- src={getImageURL(data)}- alt="action screenshot"- className="absolute inset-0 h-full w-full object-contain"- />+ <div+ ref={containerRef}+ className={zoom.container}+ role="button"+ tabIndex={0}+ aria-label={zoomed ? "Zoom screenshot out" : "Zoom screenshot in"}+ onClick={toggleZoom}+ onKeyDown={(e) => {+ if (e.key === "Enter" || e.key === " ") {+ e.preventDefault();+ toggleZoom();+ }+ }}+ >+ <img+ src={getImageURL(data)}+ alt="action screenshot"+ className={zoom.image}+ />+ </div>);}diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.utils.test.ts b/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.utils.test.tsnew file mode 100644index 000000000..c7e365581--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.utils.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from "vitest";++import { screenshotZoomClasses } from "./HeroScreenshot.utils";++describe("screenshotZoomClasses", () => {+ it("fits to width and scrolls vertically when not zoomed", () => {+ const { container, image } = screenshotZoomClasses(false);+ expect(container).toContain("cursor-zoom-in");+ expect(container).toContain("overflow-y-auto");+ expect(image).toContain("w-full");+ expect(image).not.toContain("max-w-none");+ });++ it("shows the screenshot at natural size, top-center, when zoomed", () => {+ const { container, image } = screenshotZoomClasses(true);+ expect(container).toContain("cursor-zoom-out");+ expect(container).toContain("overflow-auto");+ expect(image).toContain("mx-auto");+ expect(image).toContain("max-w-none");+ });+});diff --git a/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.utils.ts b/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.utils.tsnew file mode 100644index 000000000..f85ad9bcd--- /dev/null+++ b/skyvern-frontend/src/routes/workflows/studio/runview/HeroScreenshot.utils.ts@@ -0,0 +1,23 @@+import { cn } from "@/util/utils";++/**+ * Classes for the run-hero screenshot. The default view fits the screenshot to+ * the panel width and scrolls vertically, so long full-page captures aren't+ * cropped (object-contain shrank tall captures to an unreadable sliver and the+ * overflow was clipped). Click toggles to natural size (`zoomed`), scrollable on+ * both axes; the caller sets the initial scroll to top-center.+ */+export function screenshotZoomClasses(zoomed: boolean): {+ container: string;+ image: string;+} {+ return {+ container: cn(+ "absolute inset-0",+ zoomed+ ? "overflow-auto cursor-zoom-out bg-slate-950"+ : "overflow-y-auto overflow-x-hidden cursor-zoom-in",+ ),+ image: zoomed ? "mx-auto block max-w-none" : "block w-full",+ };+}