From 37559fc38f434db3ff15a8fdc7125508ff0c5c7f Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Tue, 15 Oct 2024 08:00:25 -0700 Subject: [PATCH] Render all multi artifacts correctly (#976) --- .../src/routes/tasks/detail/HTMLArtifact.tsx | 53 +++++++++++-------- .../src/routes/tasks/detail/StepArtifacts.tsx | 20 +++---- .../src/routes/tasks/detail/TextArtifact.tsx | 53 +++++++++++-------- 3 files changed, 75 insertions(+), 51 deletions(-) diff --git a/skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx b/skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx index ce7d281d..a28a18e4 100644 --- a/skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx +++ b/skyvern-frontend/src/routes/tasks/detail/HTMLArtifact.tsx @@ -2,7 +2,7 @@ import { artifactApiClient } from "@/api/AxiosClient"; import { ArtifactApiResponse } from "@/api/types"; import { Skeleton } from "@/components/ui/skeleton"; import { Textarea } from "@/components/ui/textarea"; -import { useQuery } from "@tanstack/react-query"; +import { useQueries } from "@tanstack/react-query"; import axios from "axios"; // https://stackoverflow.com/a/60338028 @@ -27,29 +27,36 @@ function format(html: string) { } type Props = { - artifact: ArtifactApiResponse; + artifacts: Array; }; -function HTMLArtifact({ artifact }: Props) { - const { data, isFetching, isError, error } = useQuery({ - queryKey: ["artifact", artifact.artifact_id], - queryFn: async () => { - if (artifact.uri.startsWith("file://")) { - return artifactApiClient - .get(`/artifact/text`, { - params: { - path: artifact.uri.slice(7), - }, - }) - .then((response) => response.data); - } - if (artifact.uri.startsWith("s3://") && artifact.signed_url) { - return axios.get(artifact.signed_url).then((response) => response.data); - } - }, +function HTMLArtifact({ artifacts }: Props) { + function fetchArtifact(artifact: ArtifactApiResponse) { + if (artifact.uri.startsWith("file://")) { + return artifactApiClient + .get(`/artifact/text`, { + params: { + path: artifact.uri.slice(7), + }, + }) + .then((response) => response.data); + } + if (artifact.uri.startsWith("s3://") && artifact.signed_url) { + return axios.get(artifact.signed_url).then((response) => response.data); + } + } + + const results = useQueries({ + queries: + artifacts?.map((artifact) => { + return { + queryKey: ["artifact", artifact.artifact_id], + queryFn: () => fetchArtifact(artifact), + }; + }) ?? [], }); - if (isFetching) { + if (results.some((result) => result.isLoading)) { return ; } @@ -57,7 +64,11 @@ function HTMLArtifact({ artifact }: Props) {