From d571519a673ed409a873e0576ca7c2e52716ce46 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Tue, 22 Oct 2024 06:45:46 -0700 Subject: [PATCH] Use code editor in diagnostics tab (#1024) --- .../detail/{HTMLArtifact.tsx => Artifact.tsx} | 41 ++++++++++--- .../src/routes/tasks/detail/JSONArtifact.tsx | 60 ------------------- .../src/routes/tasks/detail/StepArtifacts.tsx | 17 +++--- .../src/routes/tasks/detail/TextArtifact.tsx | 56 ----------------- .../workflows/components/CodeEditor.tsx | 22 +++++-- 5 files changed, 59 insertions(+), 137 deletions(-) rename skyvern-frontend/src/routes/tasks/detail/{HTMLArtifact.tsx => Artifact.tsx} (65%) delete mode 100644 skyvern-frontend/src/routes/tasks/detail/JSONArtifact.tsx delete mode 100644 skyvern-frontend/src/routes/tasks/detail/TextArtifact.tsx diff --git a/skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx b/skyvern-frontend/src/routes/tasks/detail/Artifact.tsx similarity index 65% rename from skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx rename to skyvern-frontend/src/routes/tasks/detail/Artifact.tsx index a28a18e4..f90985f4 100644 --- a/skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx +++ b/skyvern-frontend/src/routes/tasks/detail/Artifact.tsx @@ -1,7 +1,7 @@ import { artifactApiClient } from "@/api/AxiosClient"; import { ArtifactApiResponse } from "@/api/types"; import { Skeleton } from "@/components/ui/skeleton"; -import { Textarea } from "@/components/ui/textarea"; +import { CodeEditor } from "@/routes/workflows/components/CodeEditor"; import { useQueries } from "@tanstack/react-query"; import axios from "axios"; @@ -26,15 +26,38 @@ function format(html: string) { return result.substring(1, result.length - 3); } +function getFormattedResult(type: "json" | "html" | "text", result: unknown) { + switch (type) { + case "json": + return JSON.stringify(result, null, 2); + case "html": + return format(result as string); + case "text": + return result; + } +} + +function getEndpoint(type: "json" | "html" | "text") { + switch (type) { + case "json": + return "/artifact/json"; + case "html": + case "text": + return "/artifact/text"; + } +} + type Props = { + type: "json" | "html" | "text"; artifacts: Array; }; -function HTMLArtifact({ artifacts }: Props) { +function Artifact({ type, artifacts }: Props) { function fetchArtifact(artifact: ArtifactApiResponse) { if (artifact.uri.startsWith("file://")) { + const endpoint = getEndpoint(type); return artifactApiClient - .get(`/artifact/text`, { + .get(endpoint, { params: { path: artifact.uri.slice(7), }, @@ -61,17 +84,21 @@ function HTMLArtifact({ artifacts }: Props) { } return ( -